Generating an enum from a tuple of Types?

Artur Skawina art.08.09 at gmail.com
Sat Jan 25 09:55:54 PST 2014


On 01/25/14 16:38, Johannes Pfau wrote:
> Is it possible to generate a enum from a tuple of types without string
> mixins?
> ------------
> struct S(Types...)
> {
>     enum Tag
>     {
>         //?
>     }
> }
> ------------
> 
> where the tag enum should have Types.length members. The exact names of
> the enum members don't matter and could be numbered, for example:
> Tag._1, Tag._2, ...

Well, if you don't need names then just use the index directly.

Eg, see 'DiscUnion.type' in 

http://forum.dlang.org/thread/mtkzbwfgwsstndxbesgy@forum.dlang.org#post-mailman.555.1377703234.1719.digitalmars-d-learn:40puremagic.com

(A newer compiler may allow for that offset-of calculation at CT)

artur


More information about the Digitalmars-d-learn mailing list