Added practical example to std.algorithm.iteration.group#5177
Added practical example to std.algorithm.iteration.group#5177dlang-bot merged 1 commit intodlang:masterfrom
Conversation
e3759ee to
86cae56
Compare
wilzbach
left a comment
There was a problem hiding this comment.
Nice!
Definitely worth to be shown to the user as an example :)
|
Awesome example! |
std/algorithm/iteration.d
Outdated
|
|
||
| uint[string] result; | ||
| auto range = ["a", "b", "a", "c", "b", "c", "c", "d", "e"]; | ||
| result = range.sort!("a < b") |
There was a problem hiding this comment.
This should be a regular lambda.
There was a problem hiding this comment.
It's also the default, so it could be omitted here as well..
There was a problem hiding this comment.
Unfortunately it can't be omitted, because then the compiler assumes you're using array.sort rather than std.algorithm.sort().
And for some reason, unlike Phobos, DMD does not stick to actually deprecating things when it says it will. array.sort has been a warning for almost three years now.
86cae56 to
e656eec
Compare
Just use empty parentheses (
Well, I guess nobody has bothered to make a PR so far :/ |
|
Hmm. According to the git log, this warning was turned into a deprecation last year (Apr 29, see dmd commit |
|
The deed is done: dlang/dmd#6554 |
Just discovered this useful idiom. I was doing this manually using
foreachover ranges and incrementing the count in an AA for my stats plotting code.All manual
foreachloops in user code are bugs!