View source code
Display the source code in std/algorithm/searching.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.algorithm.searching.minPos
Returns the position of the minimum element of forward range , i.e. a subrange of range starting at the position of its
smallest element and with the same ending as range. The function
can actually be used for finding the maximum or rangeany other ordering
predicate (that's why maxPos is not provided).
Prototype
Range minPos(alias pred, Range)( Range range ) if (isForwardRange!Range && !isInfinite!Range && is(typeof(binaryFun!pred(range.front, range.front))));
Example
int[] a = [ 2, 3, 4, 1, 2, 4, 1, 1, 2 ];
// Minimum is 1 and first occurs in position 3
assert(minPos(a) == [ 1, 2, 4, 1, 1, 2 ]);
// Maximum is 4 and first occurs in position 2
assert(minPos!("a > b")(a) == [ 4, 1, 2, 4, 1, 1, 2 ]);