Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Help with Template-Template and Mixin Polymorphism

Thread Tools

Help with Template-Template and Mixin Polymorphism

Posts: n/a
Re: Cross-posted from the moderated group (but this version has
spelling fixes).


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!


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
difference between inheritance and mixin Vellingiri Arul Ruby 6 09-26-2007 09:19 PM
Dynamic polymorphism vs. Static polymorphism Krivenok Dmitry C++ 13 06-01-2006 09:49 AM
Question regarding <=> operator and Comparable Mixin Manuel Kasten Ruby 5 11-10-2005 06:15 PM
Class and Mixin with same method name problem Ruby 13 11-07-2005 08:36 AM
Hash::MixIn and Python style Object#dict Florian Gross Ruby 12 04-04-2005 12:39 AM