digitalmars.D.learn - Variadic constructor conflict
- andrea9940 (32/32) Jan 30 2013 This code compiles fine:
- Simen Kjaeraas (9/39) Jan 30 2013 Known bug. For the moment, the workaround is to templatize all
- andrea9940 (1/1) Jan 30 2013 Aw
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...
Jan 30 2013
On 2013-01-30, 17:08, andrea9940 wrote: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...Known bug. For the moment, the workaround is to templatize all constructors: struct Vector(...) { this()(T value ) { ... -- Simen
Jan 30 2013