Trait or builtin that returns arguments passed to current function (if any)
Basile B.
b2.temp at gmx.com
Thu Sep 9 10:14:03 UTC 2021
On Thursday, 9 September 2021 at 08:39:05 UTC, bauss wrote:
> [...]
> Here is a working example:
>
> ```d
> string __ARGUMENTS__(string fn = __FUNCTION__)()
> {
> import std.traits : ParameterIdentifierTuple;
> import std.array : join;
>
> mixin("enum parameterNames = [ParameterIdentifierTuple!(" ~
> fn ~ ")];");
>
> return "auto __arguments = [" ~ parameterNames.join(",") ~
> "];";
> }
>
> void test(int x, int y)
> {
> import std.stdio;
>
> mixin(__ARGUMENTS__);
>
> auto c = __arguments[0];
> auto d = __arguments[1];
>
> writefln("%d %d", c, d);
> }
>
> void main()
> {
> test(1,2);
> }
> ```
> Output:
> 1 2
Nice.
> But yeah it would be nice if we could have it built-in, which I
> don't think has been done.
That's a contemporary D question that often comes in
conversations: should "feature x" be a builtin or should "feature
x" be made using metaprog...
Is this used often ? is the metaprog version slow ?
More information about the Digitalmars-d
mailing list