Returns an iterator pointing to the first element in the range [first, last] which does not compare less than val.
The elements in the range shall already be sorted or at least partitioned with respect to val.
ForwardIterator lower_bound (ForwardIterator first, ForwardIterator last, const T& val);
ForwardIterator lower_bound (ForwardIterator first, ForwardIterator last, const T& val, Compare comp);
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 of the lower bound to search for in the range.
Binary function that accepts two arguments (the first of the type pointed by ForwardIterator, and the second, always val), and returns a value convertible to bool. The function shall not modify any of its arguments. This can either be a function pointer or a function object.
Return type :
An iterator to the lower bound of val in the range. If all the element in the range compare less than val, the function returns last.If all the element in the range are larger than val, the function returns pointer to first element.
Input : 10 20 30 40 50 Output : lower_bound for element 35 at index 2 Input : 10 20 30 40 50 Output : lower_bound for element 55 is index 4
Vector contains : 10 20 30 40 50 lower_bound for element 20 at position 1 lower_bound for element 55 at position 5
This article is contributed by Sachin Bisht. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Minimum cells to be flipped to get a 2*2 submatrix with equal elements
- Nested Loops in C++ with Examples
- _Find_first() function in C++ bitset with Examples
- _Find_next() function in C++ bitset with Examples
- Left-Right traversal of all the levels of N-ary tree
- Difference between Iterators and Pointers in C/C++ with Examples
- ostream::seekp(pos) method in C++ with Exmaples
- Default Methods in C++ with Examples
- C++ Tutorial
- Hello World Program : First program while learning Programming
- Difference between Argument and Parameter in C/C++ with Examples
- <cfloat> float.h in C/C++ with Examples
- C/C++ #include directive with Examples
- C/C++ if else statement with Examples
- C/C++ if statement with Examples