The most awesome "forward to member" solution?

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sat May 2 21:20:56 PDT 2015


On 5/2/15 5:42 PM, Meta wrote:
> On Sunday, 3 May 2015 at 00:25:13 UTC, Dicebot wrote:
>> Sounds similar to http://dlang.org/phobos/std_typecons.html#.Proxy
>
> That's a good idea. Proxy could be improved to take a list of names of
> members to forward. That'd be pretty cool actually.

Here's what I have right now - simple as they come: 
http://dpaste.dzfl.pl/7ec11459a125. Kudos to whoever defined 
ParameterTypeTuple, it's exactly what the doctor prescribed.

The gist of it is:

string forwardToMember(string member, string[] funs...)
{
     string result;
     foreach (fun; funs)
     {
         result ~= "
             auto 
"~fun~"(ParameterTypeTuple!(typeof("~member~"."~fun~")) args)
             {
                 return "~member~"."~fun~"(args);
             }
         ";
     }
     return result;
}

which is used as:

     mixin(forwardToMember("member", "expand", "reallocate", "owns"));

Is this a common thing people wanna do? Put in Phobos?


Andrei



More information about the Digitalmars-d mailing list