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 07:21:48 PST 2017
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:
> ```
> template namedTool(T, alias Variable)
> {
> enum namedTool = T.stringof ~ " " ~ Variable ~ " = new " ~
> T.stringof ~ ";" ~
> Variable ~ ".name = \"" ~ Variable ~ "\";";
> }
>
> void main()
> {
> mixin(namedTool!(Tool, "grep"));
> assert(grep.name == "grep");
> }
> ```
Thanks for trying. I know that it doesn't make much sense but it
would have been a cool sugar for the tool class.
Mixins are not good for me because of completion in the IDE.
More information about the Digitalmars-d-learn
mailing list