ADL

Marc Schütz via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 5 03:57:57 PDT 2016


On Saturday, 3 September 2016 at 11:24:01 UTC, Walter Bright 
wrote:
> On 9/3/2016 3:12 AM, Walter Bright wrote:
>> 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.
>
> Eh, I realized it's simpler than that. Based on the code I 
> already presented, each argument can be used to generate an 
> import for its corresponding version of the function. Then, 
> overloading rules apply and it works. Something like:
>
> Something like:
>
> void foo(T,U)(T t, U u)
> {
>     alias func = ModuleOf!T.func;
>     alias func = ModuleOf!U.func;
>
>     func(t, u);
> }

Can we use a `with` statement? E.g. something along those lines

     void foo(T, U, alias context = __CURRENT_MODULE__)(T t, U u) {
         with(context)
             return func(t, u);
     }


More information about the Digitalmars-d mailing list