Type deduction on templated constructor.
francesco cattoglio via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 24 02:29:14 PDT 2014
So, I have this code (also on http://dpaste.dzfl.pl/3f767b17e83c)
This Vector(T) struct is taken from gfm.math.vector.
struct Vector(T) {
T x, y, z;
this(X : T, Y : T, Z : T)(X x_, Y y_, Z z_)
{
x = x_; y = y_; z = z_;
}
}
void main()
{
Vector!ubyte test = Vector!ubyte(1, 1, 1);
}
It fails to compile because "template
f508.Vector!ubyte.Vector.__ctor cannot deduce function from
argument types !()(int, int, int)".
Note that if one just defines a constructor as this(T x_, T y_, T
z_) everything works.
My question is: should this code compile? I understand that the
literal "1" is "int" therefore it can screw type deduction, but I
wonder if the compiler should be smart enough to deduce it
correctly.
More information about the Digitalmars-d-learn
mailing list