Variadic Mixin/Template classes?
Chirs Forest
CF at chrisforest.com
Sat Nov 25 10:26:02 UTC 2017
On Saturday, 25 November 2017 at 10:08:36 UTC, vit wrote:
> On Saturday, 25 November 2017 at 09:52:01 UTC, Chirs Forest
> wrote:
>> [...]
>
> import std.meta : staticMap;
>
> class Bar(T) {
> T bar;
> }
>
> class Foo(Ts...){
> staticMap!(Bar, Ts) bars;
>
> this(){
> static foreach(i, alias T; Ts) bars[i] = new Bar!T;
> }
>
>
> }
>
> 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);
> foo2.bars[0].bar = 9;
> foo2.bars[1].bar = "world";
> }
thankyou!
More information about the Digitalmars-d-learn
mailing list