On Monday, 15 October 2018 at 16:46:34 UTC, Steven Schveighoffer wrote:
On 10/15/18 12:40 PM, Márcio Martins wrote:
import std.stdio;

void incx(T, Args...)(ref T t) {
     ++t.x;
}

static struct Test(T) {
     T x;
}

void main() {
     Test!uint t;
     t.incx();           // works
     t.incx!();          // works
     incx(t);            // works
     t.incx!(1, 2, 3);   // what?
     incx(t, 1, 2, 3);   // what?
     writeln(t.x);
}


test.d(16): Error: template test.incx cannot deduce function from argument types !(1, 2, 3)(Test!uint), candidates are:
test.d(3):        test.incx(T, Args...)(ref T t)

No, not a bug.

I suspect you want this?

void incx(Args..., T)(ref T t);

This doesn't seem to work, because:
test.d(3): Error: template `test.incx(Args..., T)(ref T t)` template tuple parameter must be last one

Are you sure it's not a bug? It would be very un-intuitive otherwise, no? Considering that the declaration is legal, and that the template parameter deduction works when Args.length == 0, but stops working when Args.length > 0.

There seems to be no way around it, except manually specifying the type, which is not only annoying.

I was trying to use UFCS to emulate a method on a family of structs, but this makes it impossible :(

Reply via email to