digitalmars.D.learn - isSame/TemplateOf bug?
- SrMordred (20/20) Feb 19 2019 import std.traits;
- Paul Backus (5/26) Feb 19 2019 Inside a templated struct, the name of the template, by itself,
- SrMordred (5/36) Feb 19 2019 True!
- =?UTF-8?Q?Ali_=c3=87ehreli?= (3/11) Feb 19 2019 For reference, it is the same in C++.
import std.traits; import std.stdio; struct Test(T) { this(T)( auto ref T value ) { writeln( TemplateOf!(typeof(value)).stringof); writeln( __traits(isSame, TemplateOf!(typeof(value)), Test) ); } } void main(){ auto value = Test!int(Test!int()); writeln( TemplateOf!(typeof(value)).stringof); writeln( __traits(isSame, TemplateOf!(typeof(value)), Test) ); } //output: Test(T) false Test(T) true
Feb 19 2019
On Tuesday, 19 February 2019 at 22:43:25 UTC, SrMordred wrote:import std.traits; import std.stdio; struct Test(T) { this(T)( auto ref T value ) { writeln( TemplateOf!(typeof(value)).stringof); writeln( __traits(isSame, TemplateOf!(typeof(value)), Test) ); } } void main(){ auto value = Test!int(Test!int()); writeln( TemplateOf!(typeof(value)).stringof); writeln( __traits(isSame, TemplateOf!(typeof(value)), Test) ); } //output: Test(T) false Test(T) trueInside a templated struct, the name of the template, by itself, actually refers to the current instantiation. So when you write `Test` in your __traits(isSame) test, the compiler interprets it as `Test!T`.
Feb 19 2019
On Tuesday, 19 February 2019 at 23:03:37 UTC, Paul Backus wrote:On Tuesday, 19 February 2019 at 22:43:25 UTC, SrMordred wrote:True! writeln(Test.stringof) inside the struct give me Test!int. Thanks! Little unexpected D dark corner :Pimport std.traits; import std.stdio; struct Test(T) { this(T)( auto ref T value ) { writeln( TemplateOf!(typeof(value)).stringof); writeln( __traits(isSame, TemplateOf!(typeof(value)), Test) ); } } void main(){ auto value = Test!int(Test!int()); writeln( TemplateOf!(typeof(value)).stringof); writeln( __traits(isSame, TemplateOf!(typeof(value)), Test) ); } //output: Test(T) false Test(T) trueInside a templated struct, the name of the template, by itself, actually refers to the current instantiation. So when you write `Test` in your __traits(isSame) test, the compiler interprets it as `Test!T`.
Feb 19 2019
On 02/19/2019 03:21 PM, SrMordred wrote:On Tuesday, 19 February 2019 at 23:03:37 UTC, Paul Backus wrote:For reference, it is the same in C++. AliInside a templated struct, the name of the template, by itself, actually refers to the current instantiation. So when you write `Test` in your __traits(isSame) test, the compiler interprets it as `Test!T`.True! writeln(Test.stringof) inside the struct give me Test!int. Thanks! Little unexpected D dark corner :P
Feb 19 2019