| |
 | Posted by Simen Kjaeraas in reply to andrea9940 | Permalink Reply |
|
Simen Kjaeraas 
Posted in reply to andrea9940
| 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
|