samedi 26 décembre 2015

How can I get the value type of an enum member

For example

template EnumValueType(T)
if (is(T == enum))
{
    alias EnumValueType = /* ??? */;
}

enum E: ubyte {e0 = 123}
enum D: float {d0 = 0.5}

void main()
{
    E e;
    D d;
    assert( is(EnumValueType!(typeof(e)) == ubyte));
    assert( is(EnumValueType!(typeof(d)) == float));
}

So far I can only detect if it's a enum. I see a way to do this but it's bad. It would consist in iterating trough an AliasSeq seq made of D basic types and to see if a T is convertible to seq[n].

Any other idea ?





Aucun commentaire:

Enregistrer un commentaire