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

jkpl via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 9 05:30:07 PST 2017


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 == "grep");
}
```

Ideally this would work like this:

```
Tool grep = namedTool!Tool;
assert(grep.name == "grep");
```

Possible ?


More information about the Digitalmars-d-learn mailing list