Template Collections of Different Types

DarthCthulhu via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Aug 15 18:39:52 PDT 2015


Say I want to do something like:

Propertery!int pi = 42;
PropertyCollection pc;

pc.attach("Life_and_Everything", pi);

assert(pc.Life_and_Everything == 42);

Property!string ps = "Hello World";

pc.attach("text", ps);

assert(pc.text == "Hello World");

How would one store the Property objects in the 
PropertyCollection? You can't use something like an array because 
the two Properties are of different types. Do you really need to 
do something like make a member of PropertyCollection for every 
type of Property you are interested in storing and using static 
ifs to determine which variable it goes into?

I feel like there is an obvious solution here that I'm missing.


More information about the Digitalmars-d-learn mailing list