ADL
Walter Bright via Digitalmars-d
digitalmars-d at puremagic.com
Sat Sep 3 03:12:36 PDT 2016
On 9/3/2016 2:37 AM, Manu via Digitalmars-d wrote:
> On 3 September 2016 at 18:56, Walter Bright via Digitalmars-d
> <digitalmars-d at puremagic.com> wrote:
>> On 9/3/2016 1:37 AM, Walter Bright wrote:
>>>
>>> I thought #4 in particular was rather cool, I plan to use it as an
>>> example.
>>
>>
>> https://github.com/dlang/phobos/pull/4762
> Complexity ramps up further if there are N arguments to the algorithm.
> It needs to search each of the arguments modules.
I suggest posting the actual problems you're having, because twice now you've
gotten solutions to the problems you posted, then said they weren't your actual
problems.
This template:
// Find module in which T was defined
template ModuleOf(alias T)
{
import std.traits : moduleName;
mixin("import " ~ moduleName!T ~ ";");
mixin("alias ModuleOf = " ~ moduleName!T ~ ";");
}
can be used to qualify any function with the module in which one expects to find it.
> Complexity ramps up further if there are N arguments to the algorithm.
> It needs to search each of the arguments modules.
Bluntly, if a library is designed around multi-argument ADL as a core
requirement, redesign it. I.e. the same advice as for multiple inheritance. It's
just not worth it.
If you are still determined to use it, you can use:
__traits(compiles, ...)
like you would SFINAE in C++ to select which of the modules from the argument
types selects a function that compiles.
More information about the Digitalmars-d
mailing list