map::upper_bound (STL/CLR)

Finds end of range that matches a specified key.

Syntax

iterator upper_bound(key_type key);  

Parameters

key
Key value to search for.

Remarks

The member function determines the last element X in the controlled sequence that has equivalent ordering to key. If no such element exists, or if X is the last element in the controlled sequence, it returns map::end (STL/CLR)(); otherwise it returns an iterator that designates the first element beyond X. You use it to locate the end of a sequence of elements currently in the controlled sequence that match a specified key.

Example

// cliext_map_upper_bound.cpp   
// compile with: /clr   
#include <cliext/map>   

typedef cliext::map<wchar_t, int> Mymap;   
int main()   
    {   
    Mymap c1;   
    c1.insert(Mymap::make_value(L'a', 1));   
    c1.insert(Mymap::make_value(L'b', 2));   
    c1.insert(Mymap::make_value(L'c', 3));   

// display contents " [a 1] [b 2] [c 3]"   
    for each (Mymap::value_type elem in c1)   
        System::Console::Write(" [{0} {1}]", elem->first, elem->second);   
    System::Console::WriteLine();   

    System::Console::WriteLine("upper_bound(L'x')==end() = {0}",   
        c1.upper_bound(L'x') == c1.end());   

    Mymap::iterator it = c1.upper_bound(L'a');   
    System::Console::WriteLine("*upper_bound(L'a') = [{0} {1}]",   
        it->first, it->second);   
    it = c1.upper_bound(L'b');   
    System::Console::WriteLine("*upper_bound(L'b') = [{0} {1}]",   
        it->first, it->second);   
    return (0);   
    }  
 [a 1] [b 2] [c 3]  
upper_bound(L'x')==end() = True  
*upper_bound(L'a') = [b 2]  
*upper_bound(L'b') = [c 3]  

Requirements

Header: <cliext/map>

Namespace: cliext

See Also

map (STL/CLR)
map::count (STL/CLR)
map::equal_range (STL/CLR)
map::find (STL/CLR)
map::lower_bound (STL/CLR)