Sample below, F.get, get error for class expected but OK for value type (no indirect type). D needs to do attribute inference (const nothrow pure @safe) for function(s) within template type
module X;
@safe:
struct F(T)
{
T[] data;
T get(size_t i) const nothrow @safe
{
return data[i];
}
}
struct T1
{
int x;
}
class T2
{
int x;
}
void main()
{
import std.stdio;
F!T1 t1;
writeln(t1.get(0));
F!T2 t2;
writeln(t2.get(0));
/*
onlineapp.d(11): Error: cannot implicitly convert expression `this.data[i]` of type `const(T2)` to `X.T2`
onlineapp.d(32): Error: template instance `X.F!(T2)` error instantiating
*/
}