The most awesome "forward to member" solution?

Meta via Digitalmars-d digitalmars-d at puremagic.com
Thu Aug 13 21:04:45 PDT 2015


On Wednesday, 6 May 2015 at 22:59:16 UTC, Meta wrote:
> On Sunday, 3 May 2015 at 18:54:45 UTC, Andrei Alexandrescu 
> wrote:
>> You're right, that is lovely! I've improved it as follows:
>>
>> mixin template forwardToMember(alias member, methods...)
>> {
>>     import std.algorithm : among;
>>     import std.traits : ParameterTypeTuple;
>>     template opDispatch(string sym)
>>     if ((methods.length == 0 || sym.among(methods)))
>>     {
>>         auto ref opDispatch(
>>             ParameterTypeTuple!(__traits(getMember, member, 
>> sym)) args)
>>         {
>>             return __traits(getMember, member, sym)(args);
>>         }
>>     }
>> }
>>
>> So now ref returns are preserved and the mixin is 
>> self-contained (doesn't require imports from the outside).
>>
>> Compared to my solution, this has the advantage that if the 
>> child defines a method, it will take precedence over the 
>> formatted one. So that allowed me to add a feature: if no 
>> methods are specified, all are forwarded.
>>
>> There are a couple of ways in which this could and should be 
>> improved, most notably overloads control. Even as is it's 
>> pretty darn awesome, Meta could you please make it into a pull 
>> request? I think it should go in std.functional.
>>
>>
>> Andrei
>
> I have forgotten to mention that I will make a pull request for 
> this ASAP. I have been in the process of moving and starting a 
> new job this week and last so I only have enough time to 
> occasionally post currently.

http://forum.dlang.org/post/mqnhhbbyctwrfzvbrocg@forum.dlang.org


More information about the Digitalmars-d mailing list