D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22291 - __traits(arguments) to return a tuple of the function arguments
Summary: __traits(arguments) to return a tuple of the function arguments
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords: industry, pull
: 20266 (view as issue list)
Depends on:
Blocks:
 
Reported: 2021-09-09 00:55 UTC by Adam D. Ruppe
Modified: 2022-07-04 16:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Adam D. Ruppe 2021-09-09 00:55:09 UTC
http://dpldocs.info/this-week-in-d/Blog.Posted_2021_07_26.html#on-my-wish-list

I often wish there was a tuple of the function's arguments available. I call it __arguments. D already has something similar for the D-style variadics, but I'd like to see it for all functions.

---
void foo(int a, int b) {
     auto c = __arguments[0]; // same as int c = a;
     writeln(__arguments); // same as writeln(a, b);
}
---

It is such a little thing but it would make that kind of forwarding a lot easier.

I also wouldn't mind a __this_function thing, but that's fairly easy to hack around with __traits(parent, {}). And yah, you could kinda do some weird mixin thing with traits(parent) and pulling out the parameters tuple and mixing in the names. But much better to just have __arguments that just works.
Comment 1 Dlang Bot 2021-09-13 11:34:36 UTC
@maxhaton created dlang/dmd pull request #13071 "Fix Issue 22291 - Implement __traits(arguments)" fixing this issue:

- Fix Issue 22291 - Implement __traits(arguments)

https://github.com/dlang/dmd/pull/13071
Comment 2 Dlang Bot 2022-01-21 14:37:31 UTC
dlang/dmd pull request #13071 "Fix Issue 22291 - Implement __traits(parameters)" was merged into master:

- 7798569c3c80a22b9a7013209d25a1b16a72c7e0 by Max Haughton:
  Fix Issue 22291 - Implement __traits(arguments)

https://github.com/dlang/dmd/pull/13071
Comment 3 Andrej Mitrovic 2022-07-04 16:56:00 UTC
*** Issue 20266 has been marked as a duplicate of this issue. ***