isSame/TemplateOf bug?
Paul Backus
snarwin at gmail.com
Tue Feb 19 23:03:37 UTC 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)
> true
Inside 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`.
More information about the Digitalmars-d-learn
mailing list