It seems doable to have some kind of function transformer (adaptor?) for this.<br><br>from:<br><br>int foo(int a = 0, int b = 1, double c = 0.0, bool d = false) { return 1;}<br><br>alias namedParams!foo nfoo;<br><br>nfoo("d", true); // a = 0, b = 1, c = 0.0, d = true<br>
nfoo("d", true, "b", 100); // a=0, b=100, c=0.0, d=true<br>nfoo(1, 2, "d", true); // a=1, b=2, c=0.0, d=true<br><br>That is, it expects some values, then string/values couples.<br>Downside: in the above example, if foo accepts a string argument in first or second position the "d" will be passed down as an argument...<br>
<br>or, using AA syntax:<br><br>nfoo(1, ["d":true],["b":100]);<br><br>Would that be palatable? Because I think it's doable.<br><br>To obtain the arguments names:<br><br>int foo(int a, int b, double c = 0.0, bool d = true) { return 1;}<br>
<br>template Name(alias foo) if (isCallable!foo)<br>{<br> enum string Name = S!(foo.stringof);<br>}<br><br>template S(string s) // this template is just a trick because foo.stringof directly displeases DMD<br>{<br> enum string S = s;<br>
}<br><br>writeln(Name!foo); // "int(int a, int b, double c = 0, bool d = true)"<br><br>So this gives me:<br><br>- the arguments names<br>- which ones have default values<br>- what is that default value<br><br>The difficulty here is correctly parsing the ( ,,,) part, without getting desoriented by argument types that themselves use (,), like templated types.<br>
<br><br>Philippe<br>