www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How can I distinguish an enum constant from an actual enum at compile

reply TheFlyingFiddle <borin.lukas gmail.com> writes:
I want to be able to do something like this:

enum a = 32
enum b = { q,w,e,r,t,y }

CtType ctype  = getCtType!(a); // -> Would become 
CtType.enumConstant
CtType ctype1 = getCtType!(b); // -> Would become CtType.enum_
Oct 30 2015
parent reply TheFlyingFiddle <borin.lukas gmail.com> writes:
On Friday, 30 October 2015 at 11:46:43 UTC, TheFlyingFiddle wrote:
 I want to be able to do something like this:

 enum a = 32
 enum b = { q,w,e,r,t,y }

 CtType ctype  = getCtType!(a); // -> Would become 
 CtType.enumConstant
 CtType ctype1 = getCtType!(b); // -> Would become CtType.enum_
Never mind if found out how: pragma(msg, is(b == enum)); //True pragma(msg, is(a == enum)); //False.
Oct 30 2015
parent reply Gary Willoughby <dev nomad.so> writes:
On Friday, 30 October 2015 at 12:03:50 UTC, TheFlyingFiddle wrote:
 pragma(msg, is(b == enum)); //True
 pragma(msg, is(a == enum)); //False.
enum isEnum(alias e) = is(e == enum); isEnum!(a) isEnum!(b) ;)
Oct 30 2015
parent Gary Willoughby <dev nomad.so> writes:
On Friday, 30 October 2015 at 12:18:21 UTC, Gary Willoughby wrote:
 On Friday, 30 October 2015 at 12:03:50 UTC, TheFlyingFiddle 
 wrote:
 pragma(msg, is(b == enum)); //True
 pragma(msg, is(a == enum)); //False.
enum isEnum(alias e) = is(e == enum); isEnum!(a) isEnum!(b) ;)
isEnum!(isEnum)
Oct 30 2015