multimap - multmap equal_range in C++ -
multimap - multmap equal_range in C++ -
this illustration utilize of equal_range
offered on cplusplus.com site:
int main () { std::multimap<char,int> mymm; mymm.insert(std::pair<char,int>('a',10)); mymm.insert(std::pair<char,int>('b',20)); mymm.insert(std::pair<char,int>('b',30)); mymm.insert(std::pair<char,int>('b',40)); mymm.insert(std::pair<char,int>('c',50)); mymm.insert(std::pair<char,int>('c',60)); mymm.insert(std::pair<char,int>('d',60)); std::cout << "mymm contains:\n"; (char ch='a'; ch<='d'; ch++) { std::pair <std::multimap<char,int>::iterator, std::multimap<char,int>::iterator> ret; ret = mymm.equal_range(ch); std::cout << ch << " =>"; (std::multimap<char,int>::iterator it=ret.first; it!=ret.second; ++it) std::cout << ' ' << it->second; std::cout << '\n'; }
and output said be:
mymm contains: => 10 b => 20 30 40 c => 50 60 d => 60
but isn't wrong? 'd' instance status it!=ret.second
fail , loop never executed? or have got wrong? (this matters have based code on illustration , on sec think it's misbehave.)
the sec iterator in range "one-past-the-end" of way mymm.end()
works. if mymm.begin()
, mymm.end()
same there nil in container. here, ret.first
, ret.second
beingness same, means there no element in resulting range. since there 1 element 'd', ret.first
points element , ret.second
same mymm.end()
.
c++ multimap
Comments
Post a Comment