public member function
iterator upper_bound (const key_type& k);
const_iterator upper_bound (const key_type& k) const;
Return iterator to upper bound
Returns an iterator pointing to the first element in the container whose key is considered to go after k.
The function uses its internal comparison object (key_comp) to determine this, returning an iterator to the first element for which key_comp(k,element_key) would return true.
If the map class is instantiated with the default comparison type (less), the function returns an iterator to the first element whose key is greater than k.
A similar member function, lower_bound, has the same behavior as upper_bound, except in the case that the map contains an element with a key equivalent to k: In this case lower_bound returns an iterator pointing to that element, whereas upper_bound returns an iterator pointing to the next element.
- Key to search for.
Member type key_type is the type of the elements in the container, defined in map as an alias of its first template parameter (Key).
An iterator to the the first element in the container whose key is considered to go after k, or map::end if no keys are considered to go after k.
If the map object is const-qualified, the function returns a const_iterator. Otherwise, it returns an iterator.
Member types iterator and const_iterator are bidirectional iterator types pointing to elements.
int main ()
itlow=mymap.lower_bound ('b'); // itlow points to b
itup=mymap.upper_bound ('d'); // itup points to e (not d!)
mymap.erase(itlow,itup); // erases [itlow,itup)
// print content:
for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
std::cout << it->first << " => " << it->second << '\n';
Logarithmic in size.
The container is accessed (neither the const nor the non-const versions modify the container).
No mapped values are accessed: concurrently accessing or modifying elements is safe.
Strong guarantee: if an exception is thrown, there are no changes in the container.
- Return iterator to lower bound (public member function
- Get range of equal elements (public member function
- Get iterator to element (public member function
- Count elements with a specific key (public member function