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
Add Identifiers tuple to std.typecons.Tuple #1493
Conversation
Useful to have, trivial to implement, awkward to do from outside
Ugh... We really need to agree on a solution to this tuple naming mess. Any suggestions as to how to word the docs for this to work around it for now? |
* | ||
* Examples: | ||
* ---- | ||
* auto t = Tuple!(int, "num", string, "name", bool); |
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.
Is it just me, or does that code not compile? I get:
Error: type Tuple!(int, "num", string, "name", bool) has no value
Adding a paren, with either no args, or full args, fixes it though:
//auto t0 = Tuple!(int, "num", string, "name", bool)(); //FAILS
auto t1 = Tuple!(int, "num", string, "name", bool)(); //OK
//auto t2 = Tuple!(int, "num", string, "name", bool)(5); //FAILS
auto t3 = Tuple!(int, "num", string, "name", bool)(5, "hello", true); //OK
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.
Hmmm. One of the unittests does this:
Tuple!(int, "x", real, "y", double, "z", string) t;
which passes.
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.
Tuple!(...)
is a type. In a declaration, a type is followed by an identifier token, so the snippet from the unittest is perfectly fine. However, if the declaration has an initializer, that initializer is the expression followed by the =
token. A type, on its own, is not a valid expression, which is why the proposed example code will not and should not compile.
To illustrate, it's the difference between:
int a = int; // ?
and
int a = int.init; // OK
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.
Woops, I had assumed that the no-parenthesis syntax worked there (like it does when using new)
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.
fixed.
I think expression tuples are typically not capitalized. |
should be good to go now. |
I'm against this change. When we add "identifiers" member, Essentially, I think std.typecons.Tuple should have few library-specific members as far as possible so they would conflict with user-specific field names. (Based on the principle, even current I think followings would be more generic and better ways.
|
@9rnsr, I completely agree, except (again) I think it should be named Also, edit: Unless |
What is the status of this pull? I mean... its already decided we don't want it...? Can I close this? |
Closed for now. |
Useful to have, trivial to implement, awkward to do from outside.