<div dir="ltr"><div dir="ltr">On Wed, Jul 29, 2020 at 10:35 PM Jean-Louis Leroy 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">On Wednesday, 29 July 2020 at 10:38:29 UTC, Manu wrote:<br>
> On Wed, Jul 29, 2020 at 9:40 AM Jean-Louis Leroy via <br>
> Digitalmars-d < <a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>> wrote:<br>
><br>
>> On Tuesday, 28 July 2020 at 22:48:16 UTC, Manu wrote:<br>
>> > It is my opinion that if the solution involves a text-mixin, <br>
>> > the author gets an instant FAIL.<br>
>><br>
>> But:<br>
>><br>
>> > The major hangup in this exercise is dealing with 'storage<br>
>> > class', which is<br>
>> > impossible because it's not part of the language, and <br>
>> > instantly<br>
>> > forces synthesising strings.<br>
>><br>
>> Guaranteed failure then? ;-)<br>
>><br>
><br>
> Yes.<br>
<br>
This is a problem I spent a lot of time on while trying to <br>
support all the variations of functions in openmethods (and the <br>
problem is even harder because I need to alter the storage <br>
classes of a subset of the parameters).<br>
<br>
Doesn't this cut it?<br>
<br>
module challenge;<br>
<br>
template forward(alias fun)<br>
{<br>
     import std.format;<br>
     import std.traits;<br>
     enum name = __traits(identifier, fun);<br>
     static foreach (ovl; __traits(getOverloads, __traits(parent, <br>
fun), name)) {<br>
         mixin(q{<br>
                 auto ref %s(Parameters!ovl args) {<br>
                     return __traits(parent, fun).%s(args);<br>
                 }<br>
             }.format(name, name));<br>
     }<br>
}<br>
<br>
void myfun(int, ref double, out string);<br>
<br>
int myfun(in string, inout double);<br>
<br>
pragma(msg, typeof(__traits(getOverloads, forward!myfun, <br>
"myfun")[0]));<br>
pragma(msg, typeof(__traits(getOverloads, forward!myfun, <br>
"myfun")[1]));<br>
<br>
Output:<br>
void(int, ref double, out string)<br>
int(const(string), inout(double))<br>
<br>
This deals with storage classes all right.<br>
<br>
As for the string mixin, it would be nice to be able to do with <br>
it, or at least to narrow it to the function name, but in this <br>
respect D is more C than Lisp.<br>
<br></blockquote><div><br></div><div>I mean... std.format in a forward macro? I find that embarrassing. Compile times are important. 

Of course, the usual casualties occur; debugging steps through string mixins, etc.</div><div>Also, your solution doesn't perform any interesting transformation on args... forwarding functions usually transform some argument(/s) in some way, or inject additional arguments.</div><div>Hard and really lame to write any of the actual meat of the exercise inside a string.</div><div><br></div><div>I'm not saying your solution is bad, just that the problem is bad, and it really sucks that this thread exists. I've been complaining about this since day-one. 'Storage class' is the problem as usual.</div><div></div></div></div>