The most awesome "forward to member" solution?

Meta via Digitalmars-d digitalmars-d at puremagic.com
Sun May 3 17:29:17 PDT 2015


On Sunday, 3 May 2015 at 23:54:49 UTC, Andrei Alexandrescu wrote:
> On 5/3/15 4:20 PM, Meta wrote:
>> On Sunday, 3 May 2015 at 20:25:45 UTC, Andrei Alexandrescu 
>> wrote:
>>> OK, here's what I have now - two templates that are self 
>>> contained and
>>> work well:
>>>
>>> The first uses opDispatch to dispatch to a member. The second 
>>> is a
>>> simple string function that generates the appropriate code. As
>>> discussed the latter composes but the former doesn't.
>>
>> I can't picture what you're talking about. Could you post an 
>> example?
>
> struct A
> {
>    void fun(int);
> }
>
> struct B
> {
>     A a;
>     mixin forwardToMember!(a, "fun");
> }
>
> struct C
> {
>     B b;
>     mixin forwardToMember!(b, "fun");
> }
>
>
> Andrei

I still don't get it. Your example works with both 
dispatchToMember and forwardToMember. What is the difference 
between these two exactly?

auto opDispatch(string sym: foo)(ParemeterTypeTuple!(/*etc*/) 
args)
{
     return parent.foo(args);
}

//Automatically generated
auto foo(ParameterTypeTuple!(/*etc*/) args)
{
     return parent.foo(args);
}




More information about the Digitalmars-d mailing list