On Thursday, 7 May 2015 at 17:41:10 UTC, Nick Sabalausky wrote:
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.
Hi, i have a specialized struct for "bit sets" that handles the
string representation:
https://github.com/BBasile/enumset/blob/master/import/enumset.d#L242
however it's not std. Building the string is easy (cf toString())
but if it can help...