-
-
Notifications
You must be signed in to change notification settings - Fork 742
Add ParameterTuple to std.typecons #2677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Seems similar to: |
Similar, but different. The following code errors with ParameterTypeTuple:
My understanding is that However, it seems that there is a strange bug going on here. The auto-tester fails with: Declaring bar as not being variadic makes it work. Considering the auto-tester doesn't fail on every platform, I assume it's a compiler bug. |
Once compiler bug is taken care of it can make sense to implement |
Reported at: https://issues.dlang.org/show_bug.cgi?id=13769 |
45edffc
to
5cfe7c9
Compare
I removed the variadic argument, added a mention of the bug, and rebased. Not the best solution, but better than letting this rot. |
@@ -5875,3 +5875,93 @@ public: | |||
auto value = cast(int)flags_A; | |||
assert(value == Enum.A); | |||
} | |||
/** | |||
* Returns a Tuple of the parameters. | |||
* It can be used to declare function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No Params:
block, no Returns:
block.
5cfe7c9
to
91059f6
Compare
@WalterBright : Thanks, I updated the documentation. |
91059f6
to
5cfe7c9
Compare
Any additional concern ? |
Ping @Dicebot : Is it good to go ? |
LGTM, but there is a good chance we can merge #2687 - would be better to merge this after in that case, with |
Missed this one. Good news indeed ! |
5cfe7c9
to
5e8cb2d
Compare
Rebased & fixed in the light of https://issues.dlang.org/show_bug.cgi?id=14369 . |
* Returns a Tuple of the parameters. | ||
* It can be used to declare function. | ||
*/ | ||
template ParameterTuple(alias Func) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Func/func/
So this template exposes This definitely needs better documentation. In the current state of the PR, the only way for a user to use this is to emulate the examples. |
I don't like exposing For example, tuple indexing notation does not do what you think it does: it extracts the type of the indexed parameter, and discards all other info like name, default argument, etc.. The correct way of "indexing" a parameter type tuple is to take a 1-element slice. A lot of this unusual behaviour stems from the way it's implemented in DMD. I don't think it's a good idea to calcify DMD's implementation method in Phobos like this. I would rather we encapsulate parameter type tuples inside an opaque type / template that is abstracted from the nitty details of the implementation. Something that provides an abstract interface for indexing parameter type tuples, extracting parameter names, qualifiers, etc.. A lot of this is already provided by Phobos, the only thing is that they may have a less than ideal interface. Still, I would rather improve the user-facing APIs instead of baring implementation details like this, especially Not to mention, if this gets into Phobos, documented or not, it becomes a burden upon other D compiler implementors to expose the same counterintuitive, hackish, inconsistent parameter type tuple API, even if their implementations of D allows much cleaner interfaces. |
5e8cb2d
to
40b4590
Compare
That's the point. You have a list of parameters you can use to declare function. You don't want, and you should not use this list for something else, unless you know the arcanes of
It does exactly what I think it does. See line 6293. But we agree it doesn't do what you would expect at first sight.
We agree on |
With the recent changes, this doesn't have any value anymore. |
I often find myself in the need of writing / copy-pasting this code whenever I have a project where I need to do some meta-programming on functions.
It's basic, does one job, and is way simpler to start with than using an
is
expression.I was not sure where to put it though, as we don't have anything similar to
std.meta.codegen
.