On 05/20/2013 08:20 PM, Diggory wrote:
I want to create an enum of some number of types, eg. { ubyte, ushort,
uint, float }

It should be straightforward to get a member of the enum from the type
itself. Basically I have an object that stores some typed data, but the
type may not be known at compile time, only the set of possible types.
When constructing the object the user should be able to tell it what
type of data it will hold. Also the underlying type of the enum should
be efficient to store and compare.

So far the best I can come up with is using a mixin and CTFE to generate
the code for an enum plus a template function to convert from a type to
a member of the enum, but it seems like there might be a better way?

Sounds like std.variant.Algebraic:

  http://dlang.org/phobos/std_variant.html#.Algebraic

Ali

Reply via email to