Template Function thrust::lower_bound(ForwardIterator, ForwardIterator, const LessThanComparable&)¶
Function Documentation¶
-
template<class
ForwardIterator
, classLessThanComparable
>
ForwardIteratorthrust
::
lower_bound
(ForwardIterator first, ForwardIterator last, const LessThanComparable &value) lower_bound
is a version of binary search: it attempts to find the element value in an ordered range[first, last)
. Specifically, it returns the first position where value could be inserted without violating the ordering. This version oflower_bound
usesoperator<
for comparison and returns the furthermost iteratori
in[first, last)
such that, for every iteratorj
in[first, i)
,*j < value
.The following code snippet demonstrates how to use
lower_bound
to search for values in a ordered range.- Return
The furthermost iterator
i
, such that*i < value
.- Parameters
first
: The beginning of the ordered sequence.last
: The end of the ordered sequence.value
: The value to be searched.
- Template Parameters
ForwardIterator
: is a model of Forward Iterator.LessThanComparable
: is a model of LessThanComparable.
#include <thrust/binary_search.h> #include <thrust/device_vector.h> ... thrust::device_vector<int> input(5); input[0] = 0; input[1] = 2; input[2] = 5; input[3] = 7; input[4] = 8; thrust::lower_bound(input.begin(), input.end(), 0); // returns input.begin() thrust::lower_bound(input.begin(), input.end(), 1); // returns input.begin() + 1 thrust::lower_bound(input.begin(), input.end(), 2); // returns input.begin() + 1 thrust::lower_bound(input.begin(), input.end(), 3); // returns input.begin() + 2 thrust::lower_bound(input.begin(), input.end(), 8); // returns input.begin() + 4 thrust::lower_bound(input.begin(), input.end(), 9); // returns input.end()
- See
- See
upper_bound
- See
equal_range
- See
binary_search