How to get value of type at CT given only an alias

FoxyBrown via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 14 10:51:37 PDT 2017


Trying to do some tricky stuff but I can't seem to get the value 
of a type(enum in my case, but must work in general).

Basically, given a type T or an alias T(alias preferred), I'd 
like to be able to get the "default value" of that type.

e.g.,

if it is an enum and I have an alias to a member, instead of 
(Enum)3 I want 3.

if it is a member field, I want the default value.

if it is a function pointer, the address(probably 0, but 
whatever).

Basically a sort of generic "getValue" that attempts to get the 
CT value of any type, if it exists. (obviously the value of class 
is meaningless, so returns ""... class isn't even a type, but can 
still query).

In fact, I'd like to also naturally resolve the value back in to 
the expression that created it.

e.g.,

(Enum)3 -> Enum.ThirdEntry




More information about the Digitalmars-d-learn mailing list