C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Recursive partial specialization

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
daniel.w.gelder@gmail.com
Guest





PostPosted: Wed Apr 27, 2005 11:45 pm    Post subject: Recursive partial specialization Reply with quote



Hi. I have a template with 3 params:

template <typename BASE, typename SUPER=void, typename SUPER2=void>
Coolness
{
};

typedef Coolness<long> LongCoolness;
typedef Coolness<long, bool> LongAndBoolCoolness;

OK, this is the trick here. When the template is typedefed in this
form:

typedef Coolness<BASE, Coolness Thing;

IE with a Coolness as a second parameter, I then want T1 and T2 to be
the parameters instead:

typedef Coolness<BASE, T1, T2> Thing;

Can I accomplish with partial specialization?

Thanks very much
Dan

Back to top
Kanenas
Guest





PostPosted: Mon May 30, 2005 1:44 am    Post subject: Re: Recursive partial specialization Reply with quote



On 27 Apr 2005 16:45:58 -0700, [email]daniel.w.gelder (AT) gmail (DOT) com[/email] wrote:

Quote:
Hi. I have a template with 3 params:

template <typename BASE, typename SUPER=void, typename SUPER2=void

Don't forget a 'struct' or 'class' keyword.

Quote:
Coolness
{
};

typedef Coolness typedef Coolness<long, bool> LongAndBoolCoolness;

OK, this is the trick here. When the template is typedefed in this
form:

typedef Coolness<BASE, Coolness Thing;

IE with a Coolness as a second parameter, I then want T1 and T2 to be
the parameters instead:

typedef Coolness<BASE, T1, T2> Thing;

Can I accomplish with partial specialization?

You can't get type equivalence, but you can close if you also use

inheritance.

template <BASE, typename T1, typename T2>
class Coolness<BASE, Coolness
: public Coolness<BASE, T1, T2>
{
typedef Coolness<T1, T2> Super1;
typedef Coolness<BASE, T1, T2> Base;

/* These constructors may or may not make any sense
for Coolness.
*/
Coolness(const BASE& b, const T1& t1, const T2& t2)
: Base(b, t1, t2) {}
Coolness(const BASE& b, const Super1& s)
};

Any template instantiations which have a 1 or 2 arg Coolness as the
second parameter, e.g. 'Coolness<string, Coolness string> >', will use the specialization. Note that the inner
Coolness-es in the example ('Coolness<string>' and
'Coolness<Coolness') do not use the specialization.
However, 'Coolness<string, Coolness >' has
2 Coolness-es which do use the specialization.

Kanenas

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.