Template mixin enum stringof
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Dec 10 06:48:34 PST 2014
On Wed, 10 Dec 2014 14:32:12 +0000
Lemonfiend via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:
> > mixin template S(alias fld) if (is(typeof(fld) == enum))
> > {
> > import std.conv : to;
> > enum s = to!string(fld); // "BAR"
> > // or this:
> > //import std.traits : fullyQualifiedName;
> > //enum s = to!string(fullyQualifiedName!(fld)); //
> > "test.Foo.BAR"
> > }
> >
> > enum Foo { BAR, }
> >
> > void main()
> > {
> > mixin S!(Foo.BAR);
> > }
>
> Perfect, thanks.
p.s. be careful with imports, as they will go to the same scope as `s`.
this may or may not be important.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141210/f2f67c9c/attachment.sig>
More information about the Digitalmars-d-learn
mailing list