What does __parameters return?
simendsjo
simendsjo at gmail.com
Thu Sep 12 23:33:08 PDT 2013
On Thursday, 12 September 2013 at 21:33:48 UTC, Andrej Mitrovic
wrote:
> On 9/12/13, simendsjo <simendsjo at gmail.com> wrote:
>> Thanks. I just ended up using both is(__parameters and
>> is(function to fetch the parameter names. Sometimes it seems
>> things are added to D without a very thorough design phase, but
>> then again, it starts with "__", so I guess I'm on my own :)
>
> Have you tried using ParameterIdentifierTuple from std.traits?
The problem with this is that you need to supply the symbol. If
you are located inside an overloaded function, you will get the
first function defined when using the function name. This means
you'll have to look at the parent, get overloads, and then find
the correct overload (the one you're currently in) by doing some
__parameters hacking.
And if you're in a templated function, it looks even worse. Seems
I cannot get the "overloads" of a template.
So my solution is to use a mixin template..
The template itself defines a dummy variable (so you don't have
to pass a symbol), use __traits(parent), and then use
__parameters and __traits(function) to find the names.
Of course, calling ParameterIdentifierTuple!(__traits(parent ...
in the mixin template simplifies the implementation quite a bit.
Didn't know you could call __traits(identifier for the
__parameter values. __parameters is practically undocumented, and
doesn't even have an example.
More information about the Digitalmars-d-learn
mailing list