
- C++ Library - Home
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- The C++ STL Library
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- The C++ Advanced Library
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ STL Library Cheat Sheet
- C++ STL - Cheat Sheet
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ multimap::upper_bound() Function
The C++ std::multimap::upper_bound() function is used to return an iterator pointing to the first element greater than the specified key. It is useful for finding the position where a new element could be inserted without disturbing the sorted order. unlike map, multimap allows duplicate keys, so upper_bound() provides access to the first element greater than the key, rather than the exact match. The time complexity of this function is logarithmic i.e. O(log n).
Syntax
Following is the syntax for std::multimap::upper_bound() function.
iterator upper_bound (const key_type& k); const_iterator upper_bound (const key_type& k) const;
Parameters
- k − It indicates the key to search for.
Return value
This function returns an iterator to the first element in the container.
Example
Let's look at the following example, where we are going to demonstrate the usage of the upper_bond() function.
#include#include
Output
Following is the output of the above code −
First element greater than key is : 3 --> CD
Example
Consider another scenario, where we are going to use the upper_bound() function in the loop.
#include#include
Output
Output of the above code is as follows −
2 --> Hi 3 --> Hello 3 --> Vanakam
Example
In the following example, we are going to use the upper_bound() function in combination with equal_range().
#include#include
Output
If we run the above code it will generate the following output −
Elements with given key : 1 --> TP 1 --> TutorialsPoint First element greater than key is : 2 --> Tutorix