469,140 Members | 1,204 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,140 developers. It's quick & easy.

partial template specialization

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
2 1958

"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

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

Similar topics

17 posts views Thread by Paul MG | last post: by
9 posts views Thread by Philip Lawatsch | last post: by
8 posts views Thread by Agent Mulder | last post: by
6 posts views Thread by wkaras | last post: by
9 posts views Thread by Greg | last post: by
10 posts views Thread by jason.cipriani | last post: by
1 post views Thread by Ioannis Gyftos | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.