[Issue 13372] traits parent does not work on eponymous templates
https://issues.dlang.org/show_bug.cgi?id=13372 Iain Buclaw changed: What|Removed |Added Priority|P1 |P2 --
[Issue 13372] traits parent does not work on eponymous templates
https://issues.dlang.org/show_bug.cgi?id=13372 Adam D. Ruppe changed: What|Removed |Added CC||destructiona...@gmail.com --- Comment #5 from Adam D. Ruppe --- Here's something related I just came upon: template wrap(string foo) { enum wrap = foo; } pragma(msg, __traits(parent, wrap!"lol")); // says lol pragma(msg, __traits(parent, __traits(parent, wrap!"lol"))); // says argument "lol" has no parent So in the first one, it appears it evaluates to the outer template which is then instantly evaluated back to the enum literal. Then the second one sees the literal and says literals have no parents. Quite bizarre indeed. --
[Issue 13372] traits parent does not work on eponymous templates
https://issues.dlang.org/show_bug.cgi?id=13372 Basile-z changed: What|Removed |Added CC|b2.t...@gmx.com | --
[Issue 13372] traits parent does not work on eponymous templates
https://issues.dlang.org/show_bug.cgi?id=13372 --- Comment #4 from Mike Franklin--- (In reply to Basile B. from comment #2) > = > import std.meta; > > template Parent(T) > { > alias Parent = AliasSeq!(__traits(parent, T))[0]; > } > > unittest > { > class A(T){} > static assert(A!int.stringof != Parent!(A!int).stringof); > } > = > > yields: Error: static assert ("A!int" != "A!int") is false > > > the longer form > > = > import std.meta; > > template Parent(T) > { > alias Parent = AliasSeq!(__traits(parent, T))[0]; > } > > unittest > { > template B(T){class B{}} > alias T = B!int; > static assert(is(T)); > static assert(T.stringof != Parent!T.stringof); > } > = > > yields: Error: static assert ("B!int" != "B!int") is false These two tests now pass in v2.078.1 --
[Issue 13372] traits parent does not work on eponymous templates
https://issues.dlang.org/show_bug.cgi?id=13372 Mikechanged: What|Removed |Added See Also||https://issues.dlang.org/sh ||ow_bug.cgi?id=12496 --
[Issue 13372] traits parent does not work on eponymous templates
https://issues.dlang.org/show_bug.cgi?id=13372 --- Comment #3 from b2.t...@gmx.com --- Strangely enough this bug can lead to think that we can detect an eponymous template: == template isTemplateInstance(alias T : Base!Args, alias Base, Args...) { enum isTemplateInstance = is(typeof(T)); } template isTemplateInstance(T : Base!Args, alias Base, Args...) { enum isTemplateInstance = is(T); } template isTemplateInstance(T) { enum isTemplateInstance = false; } template isTemplateInstance(alias T) { enum isTemplateInstance = isTemplateInstance!(typeof(T)); } template isEponymousTemplate(T) { static if (is(T == class) || is(T == interface) || is(T == struct) || is(T == union)) { enum p = __traits(parent, T).stringof == T.stringof; enum isEponymousTemplate = p && isTemplateInstance!T; } else enum isEponymousTemplate = false; } unittest { class A(T){} struct B(T){} static assert(isEponymousTemplate!(A!int)); static assert(isEponymousTemplate!(B!int)); static assert(!isEponymousTemplate!int); template C(T) { class C{} } static assert(isEponymousTemplate!(C!int)); } unittest { template A(T) { class A{} } static assert(isEponymousTemplate!(A!int)); template B(T) { class A{} } static assert(!isEponymousTemplate!(B!int.A)); class C(T){} static assert(!isEponymousTemplate!int); A!int a; static assert(isEponymousTemplate!a); } == Indeed we can detect it but we can't get the parent ! What's happen is that "isEponymousTemplate" yield true for an eponymous template because the template itself points to its argument ! --
[Issue 13372] traits parent does not work on eponymous templates
https://issues.dlang.org/show_bug.cgi?id=13372 b2.t...@gmx.com changed: What|Removed |Added Hardware|x86_64 |All OS|Linux |All --
[Issue 13372] traits parent does not work on eponymous templates
https://issues.dlang.org/show_bug.cgi?id=13372 b2.t...@gmx.com changed: What|Removed |Added CC||b2.t...@gmx.com Summary|traits parent shows |traits parent does not work |template function as its|on eponymous templates |own parent | Severity|normal |major --- Comment #2 from b2.t...@gmx.com --- = import std.meta; template Parent(T) { alias Parent = AliasSeq!(__traits(parent, T))[0]; } unittest { class A(T){} static assert(A!int.stringof != Parent!(A!int).stringof); = yields: Error: static assert ("A!int" != "A!int") is false the longer form = import std.meta; template Parent(T) { alias Parent = AliasSeq!(__traits(parent, T))[0]; } unittest { template B(T){class B{}} alias T = B!int; static assert(is(T)); static assert(T.stringof != Parent!T.stringof); } = yields: Error: static assert ("B!int" != "B!int") is false --