Function std.range.SortedRange.upperBound
This function searches with policy sp
to find the largest right
subrange on which pred(value, x)
is true
for all x
(e.g., if pred
is "less than", returns the portion of the range
with elements strictly greater than value
). The search schedule
and its complexity are documented in SearchPolicy
.
auto auto upperBound(SearchPolicy sp = SearchPolicy .binarySearch, V)
(
V value
)
if (isTwoWayCompatible!(predFun, ElementType!Range, V));
For ranges that do not offer random access, SearchPolicy
is the only policy allowed (and it must be specified explicitly lest it exposes
user code to unexpected inefficiencies). For random-access searches, all
policies are allowed, and SearchPolicy
is the default.
Example
import std .algorithm .comparison : equal;
auto a = assumeSorted([ 1, 2, 3, 3, 3, 4, 4, 5, 6 ]);
auto p = a .upperBound(3);
assert(equal(p, [4, 4, 5, 6]));
Authors
Andrei Alexandrescu, David Simcha, Jonathan M Davis, and Jack Stouffer. Credit for some of the ideas in building this module goes to Leonardo Maffi.