Re: enum to flags

2015-09-29 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 29 September 2015 at 06:08:03 UTC, Cauterite wrote: On Tuesday, 29 September 2015 at 03:31:44 UTC, Nicholas Wilson wrote: so I have a bunch of enums (0 .. n) that i also want to represent as flags ( 1 << n foreach n ). Is there anyway to do this other than a string mixin? You

Re: enum to flags

2015-09-29 Thread Cauterite via Digitalmars-d-learn
On Tuesday, 29 September 2015 at 03:31:44 UTC, Nicholas Wilson wrote: so I have a bunch of enums (0 .. n) that i also want to represent as flags ( 1 << n foreach n ). Is there anyway to do this other than a string mixin? You could cheat with operator overloading: enum blah {

Re: enum to flags

2015-09-29 Thread Meta via Digitalmars-d-learn
On Tuesday, 29 September 2015 at 03:31:44 UTC, Nicholas Wilson wrote: so I have a bunch of enums (0 .. n) that i also want to represent as flags ( 1 << n foreach n ). Is there anyway to do this other than a string mixin? use like: enum blah { foo, bar, baz, } alias blahFlags =

Re: enum to flags

2015-09-29 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 29 September 2015 at 09:18:52 UTC, John Colvin wrote: On Tuesday, 29 September 2015 at 03:31:44 UTC, Nicholas Wilson wrote: so I have a bunch of enums (0 .. n) that i also want to represent as flags ( 1 << n foreach n ). Is there anyway to do this other than a string mixin? use

Re: enum to flags

2015-09-29 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 29 September 2015 at 03:31:44 UTC, Nicholas Wilson wrote: so I have a bunch of enums (0 .. n) that i also want to represent as flags ( 1 << n foreach n ). Is there anyway to do this other than a string mixin? use like: enum blah { foo, bar, baz, } alias blahFlags =

enum to flags

2015-09-28 Thread Nicholas Wilson via Digitalmars-d-learn
so I have a bunch of enums (0 .. n) that i also want to represent as flags ( 1 << n foreach n ). Is there anyway to do this other than a string mixin? use like: enum blah { foo, bar, baz, } alias blahFlags = EnumToFlags!blah; static assert(blahFlags.baz == 1 << blah.baz)