T
TimeHorse
Re: Cross-posted from the moderated group (but this version has
spelling fixes).
Hello,
I am trying to create a mixin class hierarchy as follows:
template <class E, class Y>
struct Z { };
template <template <class, class> class X, class Y>
struct A
{
typedef typename X G; // Problem
typedef typename X<A *, Y> F;
A(void) { }
virtual ~A(void) { }
};
template <class Y>
struct B : public virtual A<Z, Y>
{
B(void) { }
virtual ~B(void) { }
};
template <class Y, template <class> class P = B>
struct C :
public virtual A<P<Y>::G, Y>, // Problem
private P<Y>
{
C(void) { }
virtual ~C(void) { }
};
int main(/* int argc, char ** argv */void)
{
C<int> c;
return 0;
}
In this, struct Z is a utility template; there may be many definitions
for struct Z. struct A is a virtual base class used to set up
polymorphism for the derived mixin classes. B is an implementation of
a Policy Class. Among other things, B is meant to decide which
template to use for the X parameter in A's template (in this case it
chooses template struct Z). C puts all the mixin policies together.
Here, only one policy is demonstrated, denoted P, which defaults to
B. In each example, Y is a value decided at compile time at the point
of instantiation. In this case, it is instantiated with int. The
problem I am obviously having is that: when B sets X in A through its
base class definition, C has no way of retrieving that binding from P
in order to set the same value for its virtual base A allowing the two
virtual bases to match and act virtually.
In A, the typedef of G is invalid because X is not a type but a
templated type and there is no typedef equivalent to bind a template
parameter (X) to a name (G) so that derived classes can access it.
Secondly, there is no way in C's base classes to specify "A with
template parameters G from P<Y> and Y", where G is assumed to be a
name bound to A that refers to its template parameter X. Again, G
should be defined in B's base class A, which B sets to the value Z.
Does this make sense? Is it possible to do this? Any alternative
suggestions?? Thank!
Jeffrey.
spelling fixes).
Hello,
I am trying to create a mixin class hierarchy as follows:
template <class E, class Y>
struct Z { };
template <template <class, class> class X, class Y>
struct A
{
typedef typename X G; // Problem
typedef typename X<A *, Y> F;
A(void) { }
virtual ~A(void) { }
};
template <class Y>
struct B : public virtual A<Z, Y>
{
B(void) { }
virtual ~B(void) { }
};
template <class Y, template <class> class P = B>
struct C :
public virtual A<P<Y>::G, Y>, // Problem
private P<Y>
{
C(void) { }
virtual ~C(void) { }
};
int main(/* int argc, char ** argv */void)
{
C<int> c;
return 0;
}
In this, struct Z is a utility template; there may be many definitions
for struct Z. struct A is a virtual base class used to set up
polymorphism for the derived mixin classes. B is an implementation of
a Policy Class. Among other things, B is meant to decide which
template to use for the X parameter in A's template (in this case it
chooses template struct Z). C puts all the mixin policies together.
Here, only one policy is demonstrated, denoted P, which defaults to
B. In each example, Y is a value decided at compile time at the point
of instantiation. In this case, it is instantiated with int. The
problem I am obviously having is that: when B sets X in A through its
base class definition, C has no way of retrieving that binding from P
in order to set the same value for its virtual base A allowing the two
virtual bases to match and act virtually.
In A, the typedef of G is invalid because X is not a type but a
templated type and there is no typedef equivalent to bind a template
parameter (X) to a name (G) so that derived classes can access it.
Secondly, there is no way in C's base classes to specify "A with
template parameters G from P<Y> and Y", where G is assumed to be a
name bound to A that refers to its template parameter X. Again, G
should be defined in B's base class A, which B sets to the value Z.
Does this make sense? Is it possible to do this? Any alternative
suggestions?? Thank!
Jeffrey.