Re: Is it possible to create a static factory method on a templated struct?

2016-06-18 Thread ketmar via Digitalmars-d-learn
On Saturday, 18 June 2016 at 16:05:53 UTC, Gary Willoughby wrote: I've tried the following code and I get the error: you still have to instantiate you `Foo` here: auto foo = Foo.of!(string); no, you can't call even static methods of *uninstantiated* template. uninstantiated template doesn'

Is it possible to create a static factory method on a templated struct?

2016-06-18 Thread Gary Willoughby via Digitalmars-d-learn
I've tried the following code and I get the error: Error: template Foo(A) does not have property 'of' struct Foo(A) { private int _foo; @disable this(); public this(int foo) { this._foo = foo; } public static auto of(B)()

Static Factory

2014-01-29 Thread Frustrated
(Guess is didn't get sent, I guess I'm just a big spam bot cause I keep getting flagged every post) The following code demonstrates a way to have an easy factory in D requiring very little work. I imagine it can be improved to handle the abstract case(basically dependencies/constraints). Any ide