Enum of types
Maxim Fomin
maxim at maxim-fomin.ru
Tue May 21 01:49:40 PDT 2013
On Tuesday, 21 May 2013 at 03:20:56 UTC, 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?
This looks like a runtime action which is unrelated to enum.
Since you almost cannot have unknown type but some possible value
of it, you can use typeids with pure byte arrays to store value,
but you have to either use fixed size arrays (thus limiting
possible cases) or dynamic arrays (which may be impossible).
More information about the Digitalmars-d-learn
mailing list