ADL

Ethan Watson via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 4 13:48:06 PDT 2016


On Saturday, 3 September 2016 at 01:09:18 UTC, Walter Bright 
wrote:
> Fourth solution:
>
>     module myalgorithm;
>
>     void test(T)(T t)
>     {
>         import std.traits;
>         mixin("import " ~ std.traits.moduleName!T ~ ";");
>         mixin("alias M = " ~ std.traits.moduleName!T ~ ";");
>         // The above could be encapsulated into an eponymous 
> template
>         // that takes T as a parameter and returns the alias
>
>         M.f(t);
>     }

Chipping in to say that I currently do something this with 
Binderoo templates... and it sucks.

https://github.com/Remedy-Entertainment/binderoo/blob/master/binderoo_client/d/src/binderoo/variabledescriptor.d

One example is in there, the VariableDescriptors eponymous 
template, where a template that collects every member variable of 
an object has to mix in the module names of each encountered 
member variable type to stop the compiler complaining about 
module visibility. So I'm doing the double whammy of taxing the 
template expansion engine and the CTFE engine. It could be that 
switching it to a mixin template (and working out someway to make 
it as usable as eponymous templates) will solve the problem - but 
the way this codebase is going it's going to mean every template 
needs to be a mixin.

Surely the base template system can be more flexible than this?


More information about the Digitalmars-d mailing list