std.traits.ParameterIdentifierTuple producing empty results.
Carl Sturtivant
sturtivant at gmail.com
Wed Apr 3 15:24:34 UTC 2024
On Wednesday, 3 April 2024 at 10:13:56 UTC, Nick Treleaven wrote:
> I realized there's another way, inspired by your `extern
> FunctionType` idea:
>
> ```d
> import std.traits;
>
> void foo(int i, char c);
>
> void main()
> {
> pragma(msg, ParameterIdentifierTuple!foo); // i, c
> alias Foo = typeof(foo);
> pragma(msg, ParameterIdentifierTuple!Foo); // no identifiers
> static if (is(Foo PS == __parameters))
> void f(PS);
> pragma(msg, ParameterIdentifierTuple!f); // i, c
> }
> ```
A neat construction! You get a function (name) of the given
function type! This is the much needed crack in the wall. Very
handy that the bizarre __parameters tuple PS permits the
declaration of a function with those parameters including their
names.
So at least at the point where a function type has been created
this technique can produce the names inline with no coding
complications. Many thanks.
More information about the Digitalmars-d
mailing list