Variadic Mixin/Template classes?
Chirs Forest
CF at chrisforest.com
Sat Nov 25 09:52:01 UTC 2017
I'd like to make a class that takes multiple template types (1 -
several) which can hold an array/tuple of a second class that are
instantiated with those types.
class Bar(T) {
T bar;
}
class Foo(T[]){ // not sure how to take variadic types here?
Bar!(?)[] bars; //not sure how I'd define an array/tuple of
multiple types
this(){
foreach(int i, b; bars) b = new Bar!T[i];
}
}
void main(){
auto foo = new Foo!(string, int, string, ubyte[2]);
foo.bars[0].bar = "hello";
foo.bars[1].bar = 23;
foo.bars[2].bar = "hello";
foo.bars[3].bar[0] = 88;
foo.bars[3].bar[1] = 99;
auto foo2 = new Foo!(ubyte, string);
foo.bars[0].bar = 9;
foo.bars[1].bar = "world";
}
More information about the Digitalmars-d-learn
mailing list