-
-
Notifications
You must be signed in to change notification settings - Fork 740
Add std.typecons.Tuple.rename #4043
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
Would this be considered an equivalent to Python's |
@JackStouffer Not quite. This is just a convenience function for renaming tuples. |
* there are members of `t`. | ||
*/ | ||
template named(names ...) | ||
if (allSatisfy!(isSomeString, staticMap!(TypeOf, names))) |
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.
Does typeof(names)
work instead of staticMap?
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.
Yes, thanks for the hint, fixed.
auto t2Named = t2.named!(["a": "b", "b": "c"]); | ||
assert(t2Named.b == 3); | ||
assert(t2Named.c == 4); | ||
|
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.
Nitpick: afaik this empty line should be removed?
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.
done (and another one in the test below)
9eddb86
to
f5a66d9
Compare
ping @andralex |
This doesn't seem that different from |
Ping @John-Colvin. Did you read this comment? |
I approve with two requests:
|
@John-Colvin, thanks for your PR! By analyzing the annotation information on this pull request, we identified @9rnsr, @sinfu and @andralex to be potential reviewers. @9rnsr: The PR was automatically assigned to you, please reassign it if you were identified mistakenly. |
@JakobOvrum in the most basic case, yes. But if you look at the examples you'll see it makes things like
much easier. |
Current coverage is 88.84% (diff: 97.26%)@@ master #4043 diff @@
==========================================
Files 124 121 -3
Lines 77300 74357 -2943
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
- Hits 68495 66060 -2435
+ Misses 8805 8297 -508
Partials 0 0
|
May I ask why the template is called |
@Cauterite I think I'm going to rename it as I change it to a member of Tuple, as per @andralex's advice. |
Oh, no problem then. |
@andralex (or anyone else), I'm struggling to work out how to make this return by |
@John-Colvin use a trusted cast to pointer to your target type, and return |
@andralex yes, that works thanks. I just remembered why I originally made it a free function: zip(iota(10), iota(10, 20)).map!(rename!("a", "b")) instead of now: zip(iota(10), iota(10, 20)).map!(t => t.rename!("a", "b")) I guess it's not really an important difference. |
So I added some extra tests and found what seems to be a dmd bug: https://issues.dlang.org/show_bug.cgi?id=16418 I have a workaround for it in this case, see 40162fc It seems that @dlang-bot thinks I'm posting fix because I mentioned it in the commit message :/ |
No, the fix column in the bot message contains an X, not a V, so the bot is correctly considering this only a mention, not a fix. |
anyone got any idea why the win 32 autotesters are failing? |
Seriously this limit? Without really looking too much into this, it looks this PR is causing a growth in the number of symbols instantiated. |
Auto-merge toggled off |
It's been on the hot list of the auto tester for a while now and thus blocking other PRs.
You get:
|
I don't have a windows machine to test on so this is a bit difficult for me to debug and fix. |
I've moved the unittests to module scope in order to try and get the tests to pass on windows, but that means lack of documentation. Could do with some advice from compiler devs with windows knowledge here. @yebblies @9rnsr @WalterBright ?? |
Ok so it now passes on win32, that's good. But that leaves the documentation very much lacking. I guess I could duplicate the unittest inside the ddoc comments, but that's just.... ewww |
Related: http://wiki.dlang.org/DIP82 |
@John-Colvin: could you please try the solution discussed in the forum? |
Done |
Auto-merge toggled on |
CircleCI failing because it can't find dub? And the auto tester is timing out in std.datetime... |
Hooray! I wrote the first draft of this function almost 2 years ago, made the pull request 7 months ago, now we're finally here! I feel a blog post coming on... Thanks to @andralex for getting back to this and helping make it phobos worthy, also thanks to everyone else involved for helping and nagging me to get it done. |
Thanks for pushing this through. A blog post sounds like a terrific idea. |
Particularly useful to
map
on to a range of tuples generated from e.g.zip
orcartesianProduct
.