For the function to yield the expected result, the elements in the range shall already be ordered according to the same criterion (operator< or comp).
Unlike upper_bound, this function returns an iterator to the element also if it compares equivalent to value and not only if it compares greater.
The behavior of this function template is equivalent to:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Parameters
- first, last
- Forward iterators to the initial and final positions of the sequence to use. The range used is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
- value
- Element value to be checked for its lower bound.
- comp
- Comparison function object that, taking two values of the same type than those contained in the range, returns true if the first argument goes before the second argument in the specific strict weak ordering it defines, and false otherwise.
Return value
Iterator to the lower bound position for value in the range.Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
Output:
lower_bound at position 3 upper_bound at position 6 |
Complexity
At most, logarithmic number of comparisons and linear number of steps in the length of [first,last).If used with random-access iterators, number of steps is reduced to logarithmic.
See also
| upper_bound | Return iterator to upper bound (function template) |
| equal_range | Get subrange of equal elements (function template) |
| binary_search | Test if value exists in sorted array (function template) |
| min_element | Return smallest element in range (function template) |
