Python's list equivalent with std.variant?

2021-10-03 Thread rjkilpatrick via Digitalmars-d-learn
Hi. I am trying to emulate Python's list in D, to store some derived classes My initial thought was to use a dynamic array of `std.variant`s. I've tried implementing something but seeing as we can only instantiate templates at compile-time, and I may only know the type at run-time, I'm not s

Templates for instantiating derived class

2021-09-20 Thread rjkilpatrick via Digitalmars-d-learn
Essentially, I would like to write a template that calls the constructor of the parent class or the constructor of the inherited class, depending on its type. ```d #!/usr/bin/env dub /+ dub.sdl: name "mwe" +/ class Super { private int _a; this(){} this(int a) { _a =