partial template specialization

S

skscpp

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.
 
M

Mike Wahler

skscpp said:
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
 
S

skscpp

Mike Wahler said:
type

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top