-
-
Notifications
You must be signed in to change notification settings - Fork 747
std.algorithm.search: expose extremum #4257
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
|
Btw during the minElement review no one complained, but is there a way to avoid the mapping element if a "a" noop function is used? |
|
ping @DmitryOlshansky |
41118b8 to
6a0b9a4
Compare
Yeah got it too work, so that now a |
a6a9668 to
593db68
Compare
Should I separate this optimization? (it doesn't depend on extremum being exposed to the public) |
|
What optimization and why do you think that this is optimization? |
If the alias is "a" (e.g. [0,2,3].minElement), currently this is executed: this PR reduces it down to: (have a look at the changes) |
593db68 to
277d346
Compare
74a3eb7 to
8178fa2
Compare
See #4265 ;-) |
they are equivalent, are not they? (i mean assembler code) |
Have a look: http://www.mergely.com/966byvI1/ - (e.g. unaryFun is called on the right) |
Try with |
|
Can't we define overloads to avoid map if not specified? Should we promote only to |
| } | ||
|
|
||
| private auto extremum(alias map = "a", alias selector = "a < b", Range, | ||
| auto extremum(alias map = "a", alias selector = "a < b", Range, |
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.
/// before this?
8178fa2 to
35f57e8
Compare
35f57e8 to
d0e69ca
Compare
Rebased to latest master. So do we want to expose |
|
I approve the addition, seeing I have a soft spot for |
While it would have been a nice Christmas present, after thinking about this for a while I reached my internal consensus that the use cases of a public
With #5001 we finally got this in :) |
On #4221 the consensus was that extremum is rarely needed, hence we set it to
private.It seems like @9il just found a nice use case for extremum,
std.math.cmp:Well it's also possible to use
reduce:However it gets neat, if map is needed:
I added a small goodie that checks whether the first template function can be used as an mapping function (unary function) and otherwise it falls back to the selector (binary function).
Additionally I added more tests.