<div dir="ltr"><div dir="ltr">On Sun, Jul 26, 2020 at 11:30 AM Andrei Alexandrescu via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This topic came about during beerconf (it was fun!): Write an idiomatic <br>
template `forward` that takes an alias `fun` and defines (generates) one <br>
overload for each overload of `fun`. Example:<br>
<br>
template forward(alias fun)<br>
{<br>
     ...<br>
}<br>
<br>
Now for this function:<br>
<br>
void myfun(int, ref double, out string);<br>
int myfun(in string, inout double);<br>
<br>
the instantiation would be (stylized):<br>
<br>
template forward!myfun<br>
{<br>
     void myfun(int a, ref double b, out string c)<br>
     {<br>
         return myfun(a, b, c);<br>
     }<br>
     int myfun(in string a, inout double b)<br>
     {<br>
         return myfun(a, b);<br>
     }<br>
}<br>
<br>
So the challenge is implementing forward() to do this.<br></blockquote><div><br></div><div>As someone who's been doing exactly this repeatedly basically-forever, I can say the exercise is absolutely no fun at all.</div><div>It is my opinion that if the solution involves a text-mixin, the author gets an instant FAIL.</div><div>The major hangup in this exercise is dealing with 'storage class', which is impossible because it's not part of the language, and instantly forces synthesising strings.</div><div>Forwarding the default args is tricky; and I've never managed to produce a uniform solution that doesn't suffer some edge cases, but I've always made it work for the specific set of things I'm wrapping.</div><div><br></div><div>Template arg forwarding is another level above, but I think that should be taken as a secondary matter. Solve for normal functions first, and then maybe there's a hope.</div></div></div>