upper_bound
is a version of binary search: it attempts to find the element value in an ordered range [first, last)
. Specifically, it returns the last position where value could be inserted without violating the ordering. This version of upper_bound
uses operator<
for comparison and returns the furthermost iterator i
in [first, last)
such that, for every iterator j
in [first, i)
, value < *j
is false
.
The algorithm's execution is parallelized as determined by exec
.
- Parameters
-
exec | The execution policy to use for parallelization. |
first | The beginning of the ordered sequence. |
last | The end of the ordered sequence. |
value | The value to be searched. |
- Returns
- The furthermost iterator
i
, such that value < *i
is false
.
- Template Parameters
-
The following code snippet demonstrates how to use upper_bound
to search for values in a ordered range using the thrust::device
execution policy for parallelism:
...
thrust::device_vector<int> input(5);
input[0] = 0;
input[1] = 2;
input[2] = 5;
input[3] = 7;
input[4] = 8;
- See also
- https://en.cppreference.com/w/cpp/algorithm/upper_bound
-
lower_bound
-
equal_range
-
binary_search