Variadic constructor conflict

andrea9940 no at mail.plz
Wed Jan 30 08:08:56 PST 2013


This code compiles fine:
------------
struct Vector(T, uint SIZE)
{
	T[SIZE] vector;

	this(T value) {
		foreach (ref v; vector) v = value;
	}
}
alias Vector!(int, 3) Vec3i;
------------

but if I add a variadic constructor:

------------
struct Vector(T, uint SIZE)
{
	[...]

	this(T...)(T values) if (values.length == SIZE) {
		foreach (i, v; values) vector[i] = v;
	}
}
alias Vector!(int, 3) Vec3i;
------------

I get:
main.d(54): Error: template main.Vector!(int, 
3).Vector.__ctor(T...)(T values) if (values.length == SIZE) 
conflicts with constructor main.Vector!(int, 3).Vector.this at 
main.d(46)
main.d(111): Error: template instance main.Vector!(int, 3) error 
instantiating


I think that should not happen because when there is a conflict 
call like Vec3i(3) the compiler must(?) use the specialized 
function...


More information about the Digitalmars-d-learn mailing list