On Thursday, 8 August 2013 at 17:35:02 UTC, JS wrote:
Can we have UFCS for templates?

e.g.,

T New(T, A...)(A args) { }


T t = T.New(args);


Note, in this case, the type parameter is substituted.

Actually, what is wrong with New!T(args)? This works fine for me:

T t = New!T(args) ??

template New(T) if(is(T == class)) {
 T New(A...)(A args) {
    return new T(args);
 }
}


class Test {
    this(in string s, in int i) {
        writefln("s=%s, i=%s", s, i);
    }
}
class AnotherTest {
    this(in int i) {
        writefln("i=%s", i);
    }
}

void main() {
    auto test = New!Test("test", 10);
    auto test2 = New!AnotherTest("test2", 20);
}

Reply via email to