#include <iostream>
#include <map>
#include <string>
int main()
{
std::map< int, std::string > map { { 1, "one" }, { 3,"three" }, { 5,"five" },
{ 7, "seven" }, { 9, "nine" }, { 11, "eleven" } } ;
std::map<int,std::string>::key_type two = 2 ;
std::map<int,std::string>::key_type ten = 10 ;
// iterate from two to ten inclusive
// see: http://e...content-available-to-author-only...e.com/w/cpp/container/map/upper_bound
// see: http://e...content-available-to-author-only...e.com/w/cpp/container/map/lower_bound
auto end = map.upper_bound(ten) ;
for( auto iter = map.lower_bound(two) ; iter != end ; ++iter )
std::cout << '{' << iter->first << ',' << iter->second << "} " ;
std::cout << '\n' ;
// iterate from two up to not including ten
end = map.lower_bound(ten) ;
for( auto iter = map.lower_bound(two) ; iter != end ; ++iter )
std::cout << '{' << iter->first << ',' << iter->second << "} " ;
std::cout << '\n' ;
map[2] = "two" ;
map[10] = "ten" ;
// iterate from two to ten inclusive
end = map.upper_bound(ten) ;
for( auto iter = map.lower_bound(two) ; iter != end ; ++iter )
std::cout << '{' << iter->first << ',' << iter->second << "} " ;
std::cout << '\n' ;
// iterate from two up to not including ten
end = map.lower_bound(ten) ;
for( auto iter = map.lower_bound(two) ; iter != end ; ++iter )
std::cout << '{' << iter->first << ',' << iter->second << "} " ;
std::cout << '\n' ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8c3RyaW5nPgoKaW50IG1haW4oKQp7CiAgICBzdGQ6Om1hcDwgaW50LCBzdGQ6OnN0cmluZyA+IG1hcCB7IHsgIDEsICJvbmUiIH0sIHsgMywidGhyZWUiIH0sIHsgNSwiZml2ZSIgfSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgeyA3LCAic2V2ZW4iIH0sIHsgOSwgIm5pbmUiIH0sIHsgMTEsICJlbGV2ZW4iIH0gfSA7CgogICAgc3RkOjptYXA8aW50LHN0ZDo6c3RyaW5nPjo6a2V5X3R5cGUgdHdvID0gMiA7CiAgICBzdG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lCiAgICBlbmQgPSBtYXAudXBwZXJfYm91bmQodGVuKSA7CiAgICBmb3IoIGF1dG8gaXRlciA9IG1hcC5sb3dlcl9ib3VuZCh0d28pIDsgaXRlciAhPSBlbmQgOyArK2l0ZXIgKQogICAgICAgIHN0ZDo6Y291dCA8PCAneycgPDwgaXRlci0+Zmlyc3QgPDwgJywnIDw8IGl0ZXItPnNlY29uZCA8PCAifSAiIDsKICAgIHN0ZDo6Y291dCA8PCAnXG4nIDsKCiAgICAvLyBpdGVyYXRlIGZyb20gdHdvIHVwIHRvIG5vdCBpbmNsdWRpbmcgdGVuCiAgICBlbmQgPSBtYXAubG93ZXJfYm91bmQodGVuKSA7CiAgICBmb3IoIGF1dG8gaXRlciA9IG1hcC5sb3dlcl9ib3VuZCh0d28pIDsgaXRlciAhPSBlbmQgOyArK2l0ZXIgKQogICAgICAgIHN0ZDo6Y291dCA8PCAneycgPDwgaXRlci0+Zmlyc3QgPDwgJywnIDw8IGl0ZXItPnNlY29uZCA8PCAifSAiIDsKICAgIHN0ZDo6Y291dCA8PCAnXG4nIDsKfQo=
{3,three} {5,five} {7,seven} {9,nine}
{3,three} {5,five} {7,seven} {9,nine}
{2,two} {3,three} {5,five} {7,seven} {9,nine} {10,ten}
{2,two} {3,three} {5,five} {7,seven} {9,nine}