Bitfield-style enum to strings?

Nick Sabalausky via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 7 10:41:10 PDT 2015


Assuming a plain old bitfield-style enum like:

enum Foo {
     optionA = 1<<0;
     optionB = 1<<1;
     optionC = 1<<2;
     optionD = 1<<3;
     optionE = 1<<4;
}

Does a function already exist somewhere to take an instance of Foo and 
get a list of the switch names as strings?

Something kinda like:

Foo fooVar = Foo.optionB | Foo.optionD;
assert(
     DOES_THIS_FUNC_EXIST(fooVar)
         .equals(["optionB", "optionD"])
);

Seems entirely feasible, although my traits-fu is a bit rusty.



More information about the Digitalmars-d-learn mailing list