Handling different types gracefully

bearophile bearophileHUGS at lycos.com
Tue Jul 2 14:45:56 PDT 2013


Roderick Gibson:

> I should know the types at compile time, so I will be using it 
> most likely, but reading the docs it looks like Algebraic is 
> built on top of the same structure as Variant. Is there any 
> difference in implementation?

Take a look at the Phobos source code, it's much faster than 
waiting for my answer. Algebraic is built on top of VariantN. 
Algebraic accepts only a limited number of types, while Variant 
doesn't have such limitation. So Algebraic is type safe.

And maybe Algebraic can ideally be implemented more efficiently 
than a Variant because to denote the contained type an enum 
suffices, instead of a TypeInfo.

Please take a look at VariantN if it contains the enum or a 
Typeinfo or something else.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list