By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,709 Members | 1,586 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,709 IT Pros & Developers. It's quick & easy.

partial template specialization

P: n/a
Here is the code that I currently have:

template <typename type, typename ret>
struct XdrFunctionType
{
typedef type Type;
typedef ret (*Policy)(XDR*, Type*);
};

template <typename type, typename ret, typename XdrFunctionType<type,
ret>::Policy>
struct XdrPolicy
{
typedef type Type;
typedef XdrFunctionType<type, ret>::Policy Policy;
};

=====================

I want to specialize XdrPolicy template for ret type of bool and ret type of
bool_t.
In other words, I don't want the clients of XdrPolicy to have to enter 3
template parameters but rather only two: the "type" and the "Policy"
function. I want the "ret" type to be implicitly known somehow - is that
possible with what I have or with slight variation from it.

Thanks.
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"skscpp" <sk*****@hotmail.com> wrote in message
news:bl**********@news.lsil.com...
Here is the code that I currently have:

template <typename type, typename ret>
struct XdrFunctionType
{
typedef type Type;
typedef ret (*Policy)(XDR*, Type*);
};

template <typename type, typename ret, typename XdrFunctionType<type,
ret>::Policy>
struct XdrPolicy
{
typedef type Type;
typedef XdrFunctionType<type, ret>::Policy Policy;
};

=====================

I want to specialize XdrPolicy template for ret type of bool and ret type of bool_t.
In other words, I don't want the clients of XdrPolicy to have to enter 3
template parameters but rather only two: the "type" and the "Policy"
function. I want the "ret" type to be implicitly known somehow - is that
possible with what I have or with slight variation from it.


Perhaps I'm misunderstanding, but note that template
arguments can be defaulted. If you want to default
only one of three, it needs to be last.

template<typename A, typename B, typename C = T>

-Mike
Jul 19 '05 #2

P: n/a

"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:7q******************@newsread3.news.pas.earth link.net...

"skscpp" <sk*****@hotmail.com> wrote in message
news:bl**********@news.lsil.com...
Here is the code that I currently have:

template <typename type, typename ret>
struct XdrFunctionType
{
typedef type Type;
typedef ret (*Policy)(XDR*, Type*);
};

template <typename type, typename ret, typename XdrFunctionType<type,
ret>::Policy>
struct XdrPolicy
{
typedef type Type;
typedef XdrFunctionType<type, ret>::Policy Policy;
};

=====================

I want to specialize XdrPolicy template for ret type of bool and ret type
of
bool_t.
In other words, I don't want the clients of XdrPolicy to have to enter 3
template parameters but rather only two: the "type" and the "Policy"
function. I want the "ret" type to be implicitly known somehow - is

that possible with what I have or with slight variation from it.


Perhaps I'm misunderstanding, but note that template
arguments can be defaulted. If you want to default
only one of three, it needs to be last.

template<typename A, typename B, typename C = T>

-Mike


You are correct. However, my third parameter depends on my 2nd paramater.
I guess there isn't a way to overcome this. Well, I don't necessarily have
to use "default argument" scheme.

Thanks.
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.