On 27 Apr 2005 16:45:58 -0700,
da*************@gmail.com wrote:
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.
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<T1, T2>, void> 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<T1, T2>, void>
: 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<Coolness<string>,
string> >', will use the specialization. Note that the inner
Coolness-es in the example ('Coolness<string>' and
'Coolness<Coolness<string>, long>') do not use the specialization.
However, 'Coolness<string, Coolness<string, Coolness<string> > >' has
2 Coolness-es which do use the specialization.
Kanenas