On 09/09/2012 18:25, Philippe Sigaud wrote:
On Sun, Sep 9, 2012 at 5:16 PM, Nick Treleaven <[email protected]> wrote:Maybe you could use a template: auto create(T, Args...)(Args args) { return new T(args); } class A { int i; this(int i){this.i = i;} } import std.stdio; void main() { create!A(5).i.writeln(); }A generic 'create' template would be good for generic code: on a reference type, use 'new' and pass args, whereas for a value type, use the type directly. Of course, this should manage builtins (like int, int[], int[3]) correctly.
I assumed he only needed class construction. I forgot that we already have std.container.make (which also works with structs):
make!A(5).i.writeln(); I noticed jmdavis has a pull request for what you describe: https://github.com/D-Programming-Language/phobos/pull/756
