typeof.stringof wrong type
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Aug 17 05:39:18 PDT 2016
On 08/17/2016 02:08 PM, Eugene Wissner wrote:
> I have a problem, that .stringof doesn't return what I'm expecting.
> Consider the following:
>
> template A(string T)
> {
> enum A : bool
> {
> yes = true,
> }
> }
>
> void main()
> {
> A!"asdf" a1;
> typeof(a1) a2;
> mixin(typeof(a1).stringof ~ " a3;");
> }
>
> I get an error: some.d-mixin-13|13 error| Error: template some.A(string
> T) is used as a type
>
> Why the second line in main() works but the third one not?
> typeof(a1).stringof seems to ignore the string template parameter T.
> pragma(msg, typeof(a1).stringof) would return just "A".
>
> Is it a bug?
Not exactly a bug. .stringof gives you a simple, readable name. It's not
meant to be used in code generation. You can use
std.traits.fullyQualifiedName instead:
import std.traits: fullyQualifiedName;
mixin(fullyQualifiedName!(typeof(a1)) ~ " a3;");
More information about the Digitalmars-d-learn
mailing list