The comparison is performed using either operator< for the first version, or comp for the second: A value, a, is considered equivalent to another, b, when (!(a<b) && !(b<a)) or (!comp(a,b) && !comp(b,a))
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).
The behavior of this function template is equivalent to:
| 1 2 3 4 5 6 |
|
Parameters
- first, last
- Forward iterators to the initial and final positions of the sequence to be searched. 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 search for.
- 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
true if an element in value is found, and false otherwise.Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Output:
looking for a 3... found! looking for a 6... not found. |
Complexity
At most, logarithmic number of comparisons and linear number of steps in the length of [first,last) +2.If used with random-access iterators, number of steps is reduced to logarithmic.
See also
| find | Find value in range (function template) |
| lower_bound | Return iterator to lower bound (function template) |
| upper_bound | Return iterator to upper bound (function template) |
| equal_range | Get subrange of equal elements (function template) |
