Re: Factory using an alias template parameter to set a member of the new tool ?

2017-02-09 Thread jkpl via Digitalmars-d-learn
On Thursday, 9 February 2017 at 15:00:21 UTC, angel wrote: On Thursday, 9 February 2017 at 14:39:41 UTC, angel wrote: On Thursday, 9 February 2017 at 13:30:07 UTC, jkpl wrote: I'm looking for a better way to do this, if possible: Or actually, maybe this will suite your case better: ```

Re: Factory using an alias template parameter to set a member of the new tool ?

2017-02-09 Thread angel via Digitalmars-d-learn
On Thursday, 9 February 2017 at 14:39:41 UTC, angel wrote: On Thursday, 9 February 2017 at 13:30:07 UTC, jkpl wrote: I'm looking for a better way to do this, if possible: ``` class Tool { string name; } T namedTool(alias Variable, T)() { T result = new T; result.name =

Re: Factory using an alias template parameter to set a member of the new tool ?

2017-02-09 Thread angel via Digitalmars-d-learn
On Thursday, 9 February 2017 at 13:30:07 UTC, jkpl wrote: I'm looking for a better way to do this, if possible: ``` class Tool { string name; } T namedTool(alias Variable, T)() { T result = new T; result.name = Variable.stringof; return result; } void main() { Tool grep;

Factory using an alias template parameter to set a member of the new tool ?

2017-02-09 Thread jkpl via Digitalmars-d-learn
I'm looking for a better way to do this, if possible: ``` class Tool { string name; } T namedTool(alias Variable, T)() { T result = new T; result.name = Variable.stringof; return result; } void main() { Tool grep; grep = namedTool!(grep,Tool); assert(grep.name ==