Implicit conversion to templatized type

Andrey Zherikov andrey.zherikov at gmail.com
Fri Nov 6 15:01:21 UTC 2020


There is a way to implicitly convert non-template user type, for 
example:
--------------------
struct S2
{
     @property S1 s1() { return S1(); }
     alias s1 this;
}

struct S1 {}

S1 f() { return S2(); }   // implicit conversion from S2 to S1
--------------------

But how can I achieve the same result if S1 is a template "struct 
S1(T) {}" and S2 should be convertible to S1!T with any T?

Also why neither "opCast"
     struct S2 { S1 opCast(T)() const if(is(T == S1)) { return 
S1(); } }
nor suitable ctor
     struct S1 { this(const S2 s){} }
are used for implicit conversion?



More information about the Digitalmars-d-learn mailing list