UFCS for templates
barryharris
slackovsky at gmail.com
Thu Aug 8 21:00:11 PDT 2013
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);
}
More information about the Digitalmars-d
mailing list