Can I parametrize template mixin's identifiers?

Nick nick at example.com
Sat Feb 19 10:42:17 PST 2011


I know I can parametrize template mixin types, but how about mixin 
identifiers? This is the code:

----------------------------------------------------------------

mixin template Box(T) {
   T val;
}

class Set(A, B) {
   mixin Box!A a;
   mixin Box!B b;
}

alias Set!(int, int) IntSet;

int main(string[] argv) {
   scope auto s = new IntSet();
   s.a.val = 3;
}

----------------------------------------------------------------

As you can see, the A and B types can be changed and with them the boxed 
values. But they need disambiguation, since they have identically named 
members. I know only to hard-code that disambiguation.

I need this because I intend to change (A, B) with a type list 
eventually and I need to make operations on the boxed types independent 
on the template mixin  identifiers (a, b).

This pattern comes from C++ code, where Box(T) would be classes, Set (A, 
B, ...) would recursively apply multiple inheritance on the type list. 
Then each Box members could be addressed by casting to the correct Box(T).

Any idea if this is possible in D?

Thanks!


More information about the Digitalmars-d-learn mailing list