Below is my code where i am inserting some values in map where two iterator it2 holds key and value "1-1","yes" and iterator it4 holds"1-1","no" . As i have inserted "1-1","yes" before "1-1","no" . The appearance of value "1-1","yes" in map is before "1-1","no". But when i try and compare which iterator comes before and which later then mycomp(it2->first,it4->first); or mycomp(it4->first,it2->first); both cases bool value returned is false. I know that map compares by Key and here key are same so probably it is returning false in both cases . But is there a way to determine whether a key related to which iterator is stored first and which last any how . I have to actually delete all values between a upper bound and lower bound . So i need to know in which is a forward direction for me While iterating for erasing the elements .
std::multimap<string, string> m;
std::multimap<string, string>::iterator it2;
std::multimap<string, string>::iterator it4;
std::multimap<string, string>::key_compare mycomp;
std::multimap<string, string> common;
mycomp = m.key_comp();
cout <<"Making Map m "<<endl;
m.insert(pair< string, string>("1-1"," yes" ));
m.insert(pair< string, string>("1-1"," no" ));
it2=m.lower_bound("1-0");
it4=it2++;
cout << "it2 values are : " << it2-> first << " and " << it2->second <<endl;
cout << "it4 values are : " << it4-> first << " and " << it4->second<< endl;
bool j =false;
j=mycomp(it2->first,it4->first);
if(j==true)
cout << " value of j returned is true" ;
if(j==false)
cout << " value of j returned is false" ;