is there any reason UFCS can't be used with 'new'?
Jay via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Sep 28 12:32:10 PDT 2014
thanks! but i'm still interested *why* you can't have this with
'new'. if there's no good reason i will file a bug report.
On Sunday, 28 September 2014 at 19:19:56 UTC, Foo wrote:
> mixin template New(T) if (is(T == class)) {
> static T New(Args...)(Args args) {
> return new T(args);
> }
> }
>
> class Bar {
> string txt;
>
> this() {
> txt = "Foo";
> }
>
> this(string t) {
> txt = t;
> }
>
> mixin New!Bar;
> }
>
> void main() {
> import std.stdio;
>
> writeln(Bar.New().txt);
> writeln(Bar.New("Bar").txt);
> }
More information about the Digitalmars-d-learn
mailing list