Template mixin enum stringof
Daniel Kozák via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Dec 10 04:43:38 PST 2014
V Wed, 10 Dec 2014 11:52:11 +0000
Lemonfiend via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
napsáno:
> 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?
import std.traits;
enum Foo { BAR, }
mixin template S(string s_)
{
enum s = s_;
}
void main()
{
mixin S!(fullyQualifiedName!(Foo.BAR));
enum e = fullyQualifiedName!(Foo.BAR);
mixin S!(e); // works fine
}
More information about the Digitalmars-d-learn
mailing list