December 10, 2014 Re: Template mixin enum stringof | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lemonfiend Attachments: | On Wed, 10 Dec 2014 14:32:12 +0000 Lemonfiend via Digitalmars-d-learn <digitalmars-d-learn@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. |
Copyright © 1999-2021 by the D Language Foundation