Search code examples
c++multimap

c++ multimap equal_range found nothing


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


Solution

  • :)

    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.
    }