digitalmars.D - __traits(parent) borken on templates
- Shachar Shemesh (27/27) Dec 12 2017 module foo;
- Stefan Koch (5/8) Dec 12 2017 A template is not a symbol as is.
- Shachar Shemesh (4/14) Dec 12 2017 And yet, "bar", which is a template, works, but "bar!int", which is an
module foo; import std.traits; void bar(T)() { } pragma(msg, "id: ", fullyQualifiedName!(bar)); pragma(msg, "parent: ", fullyQualifiedName!(__traits(parent, bar))); pragma(msg, "id: ", fullyQualifiedName!(bar!int)); pragma(msg, "parent: ", fullyQualifiedName!(__traits(parent, bar!int))); pragma(msg, "grandparent: ", fullyQualifiedName!(__traits(parent, __traits(parent, bar!int)))); Compile, and the result is: id: foo.bar parent: foo id: foo.bar!(int) parent: foo.bar!(int) grandparent: foo.bar!(int) Once the object you have is an inside template, you cannot get its parent. I suspect the reason is that bar is actually defined as: template bar(T) { void bar() { } } So asking for the function's parent supposedly returns the template. This doesn't live up to scrutiny, though, because the template's parent is the module, but asking for the parent of the parent still returns the function.
Dec 12 2017
On Tuesday, 12 December 2017 at 14:49:04 UTC, Shachar Shemesh wrote:module foo; import std.traits; [...]A template is not a symbol as is. And eponymous templates alias them-selfs to the symbol they define on instancing
Dec 12 2017
On 12/12/17 17:20, Stefan Koch wrote:On Tuesday, 12 December 2017 at 14:49:04 UTC, Shachar Shemesh wrote:And yet, "bar", which is a template, works, but "bar!int", which is an identifier, doesn't. Shacharmodule foo; import std.traits; [...]A template is not a symbol as is. And eponymous templates alias them-selfs to the symbol they define on instancing
Dec 12 2017