www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22291] New: __traits(arguments) to return a tuple of the

https://issues.dlang.org/show_bug.cgi?id=22291

          Issue ID: 22291
           Summary: __traits(arguments) to return a tuple of the function
                    arguments
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: destructionator gmail.com

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.

--
Sep 08 2021