Template mixin enum stringof
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Dec 10 04:57:06 PST 2014
On Wed, 10 Dec 2014 12:35:44 +0000
Lemonfiend via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:
> On Wednesday, 10 December 2014 at 12:08:34 UTC, ketmar via
> Digitalmars-d-learn wrote:
> > On Wed, 10 Dec 2014 11:52:11 +0000
> > Lemonfiend via Digitalmars-d-learn
> > <digitalmars-d-learn at puremagic.com>
> > wrote:
> >
> >> Consider the following:
> >>
> >> ---
> >> enum Foo { BAR, }
> >>
> >> mixin template S(string s_)
> >> {
> >> enum s = s_;
> >> }
> >>
> >> void main()
> >> {
> >> mixin S!(Foo.BAR.stringof); // Error: identifier 'stringof'
> >> of 'Foo.BAR.stringof' is not defined
> >>
> >> enum e = Foo.BAR.stringof;
> >> mixin S!(e); // works fine
> >> }
> >> ---
> >>
> >> Why doesn't the first work? And is there an alternative to the
> >> second version?
> >
> > mixin S!((Foo.BAR).stringof);
> >
> > sorry, don't remember the parsing rule for this.
>
> Wow, I didn't even consider that.. Thanks!
also, you can use this:
import std.conv : to;
...
mixin S!(to!string(Foo.BAR));
people tend to forget that many `to!` variants are usable in CTFE.
-------------- 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/791ef851/attachment.sig>
More information about the Digitalmars-d-learn
mailing list