 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
daniel.w.gelder@gmail.com Guest
|
Posted: Wed Apr 27, 2005 11:45 pm Post subject: Recursive partial specialization |
|
|
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
|
Posted: Mon May 30, 2005 1:44 am Post subject: Re: Recursive partial specialization |
|
|
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 |
|
 |
|
|
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
|
|