c++ multimap equal_range found nothing

Steven Du picture Steven Du · Aug 25, 2011 · Viewed 7.1k times · Source

How can I know the equal_range didn't find any match cases?

like:

multimap<string,string> mapdic;
pair<multimap<string,string>::iterator,multimap<string,string>::iterator> ret;
// insert some string pairs


ret=mapdic.equal_range(thisUpperCaseName);


    if (???)//how to test equal_range find nothing?
    {       
}else{

     }

Anyone can help?

Thanks

Answer

Ajeet Ganga picture Ajeet Ganga · Aug 25, 2011

:)

say your equal_range returns result of type pair

If your result.first == result.second then it means there is nothing.

If there is even a single element then result.first != result.second

if(ret.first == ret.second)
{
 // empty range
}
else
{
  //at least an element.
}