D
daniel.w.gelder
Hello, I have a template with two typenames.
template <typename BASE, typename SUPER> struct Morphic
{
Morphic<BASE,SUPER>( ) { .. }
~Morphic<BASE,SUPER>( ) { .. }
};
Morphic takes a Base and a Super. Sometimes Super is itself a Morphic.
In that situation i allow a Morphic<BASE,SUPER> to be constructed from
any Morphic which uses Morphic<BASE,SUPER> as its own SUPER. I do it
like this:
template <typename S1>
Morphic<BASE,SUPER>(const Morphic<S1, Morphic<BASE,SUPER> >& copy)
{ .. }
In other words:
typedef Morphic<long, void> LongMorphic;
typedef Morphic<long, LongMorphic> LongerMorphic;
LongerMorphic hello();
LongMorphic hola(hello); // can be constructed.
I also allow construction from Morphics that are 2 or more levels
removed:
template <typename S1, typename S2>
Morphic <BASE,SUPER>(const Morphic <S2, Morphic <S1, Morphic
<BASE,SUPER> > >& copy) { .. }
Etc...so you can construct a Morphic<A,B> from a Morphic<Q, Morphic<Z,
Morphic<A,B> > >.
What I am attempting now is the reverse: construction of Morphic<Q,
Morphic<Z, Morphic<A,B> > > from Morphic<A,B>. If the compiler
understood what I meant, I would try this syntax:
template <typename S1>
Morphic<S1, Morphic<BASE,SUPER> >(const Morphic<BASE,SUPER>& copy)
Now of *course* I have two solutions already but neither is good. First
I can simply accept SUPER as a parameter:
Morphic<BASE,SUPER>(const SUPER& copy)
Works but doesn't scale to more than one level -- I can construct
Morphic<Z, Morphic<A,B> > from Morphic<A, B>, but I can't construct
Morphic<Q, Morphic<Z, Morphic<A,B> > > from Morphic<A,B>.
Another solution is to make a different implementation of the template
for each situation:
template <typename BASE, typename SUPER> Morphic;
template <typename BASE>
Morphic<BASE, void> { .. }
template <typename BASE, typename BASE2>
Morphic<BASE, Morphic<BASE2, void> > { .. }
template <typename BASE, typename BASE2, typename BASE3>
Morphic<BASE, Morphic<BASE2, Morphic<BASE3, void> > > { .. };
And have every implementation support the extent that it is. But that
seems wasteful to solve a syntax issue.
Anyone have any ideas? I'm still pretty new to metaprogramming so...
Thanks in advance.
Dan
template <typename BASE, typename SUPER> struct Morphic
{
Morphic<BASE,SUPER>( ) { .. }
~Morphic<BASE,SUPER>( ) { .. }
};
Morphic takes a Base and a Super. Sometimes Super is itself a Morphic.
In that situation i allow a Morphic<BASE,SUPER> to be constructed from
any Morphic which uses Morphic<BASE,SUPER> as its own SUPER. I do it
like this:
template <typename S1>
Morphic<BASE,SUPER>(const Morphic<S1, Morphic<BASE,SUPER> >& copy)
{ .. }
In other words:
typedef Morphic<long, void> LongMorphic;
typedef Morphic<long, LongMorphic> LongerMorphic;
LongerMorphic hello();
LongMorphic hola(hello); // can be constructed.
I also allow construction from Morphics that are 2 or more levels
removed:
template <typename S1, typename S2>
Morphic <BASE,SUPER>(const Morphic <S2, Morphic <S1, Morphic
<BASE,SUPER> > >& copy) { .. }
Etc...so you can construct a Morphic<A,B> from a Morphic<Q, Morphic<Z,
Morphic<A,B> > >.
What I am attempting now is the reverse: construction of Morphic<Q,
Morphic<Z, Morphic<A,B> > > from Morphic<A,B>. If the compiler
understood what I meant, I would try this syntax:
template <typename S1>
Morphic<S1, Morphic<BASE,SUPER> >(const Morphic<BASE,SUPER>& copy)
Now of *course* I have two solutions already but neither is good. First
I can simply accept SUPER as a parameter:
Morphic<BASE,SUPER>(const SUPER& copy)
Works but doesn't scale to more than one level -- I can construct
Morphic<Z, Morphic<A,B> > from Morphic<A, B>, but I can't construct
Morphic<Q, Morphic<Z, Morphic<A,B> > > from Morphic<A,B>.
Another solution is to make a different implementation of the template
for each situation:
template <typename BASE, typename SUPER> Morphic;
template <typename BASE>
Morphic<BASE, void> { .. }
template <typename BASE, typename BASE2>
Morphic<BASE, Morphic<BASE2, void> > { .. }
template <typename BASE, typename BASE2, typename BASE3>
Morphic<BASE, Morphic<BASE2, Morphic<BASE3, void> > > { .. };
And have every implementation support the extent that it is. But that
seems wasteful to solve a syntax issue.
Anyone have any ideas? I'm still pretty new to metaprogramming so...
Thanks in advance.
Dan