On Monday, 28 April 2014 at 10:32:18 UTC, bearophile wrote:
Chris:
I need an array that contains pointers to types created via
template. To stick to my usual example:
Person!(string)
How can I make an array with pointers to concrete "instances"
of Person!(string)?
Every template creates a new type, so you can't put them as
they are in an array. There are various solutions, none nice.
You can try with a wrapper that performs type erasure, or
simpler you can make all the same type giving them the string
at run-time. Another solution is use OOP, something like
(untested and I am not sure):
abstract class APerson {}
class Person(string name) : APerson {}
Bye,
bearophile
So there is no way of filling an array with something like
Person!(string) *pptr;
foreach(person; people) {
buf ~= &person;
}