C ++ multimap equal_range did not find anything

How can I find out that equal_range did not find any matches?

as:

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

+6
source share
2 answers

:)

let's say your equal_range returns a result of type pair

If your result.first == result.second , then there is nothing.

If there is at least one element, then result.first != result.second

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

Essentially the same as Ajeet answer :) ret.first == mapdic.end()

-1
source

Source: https://habr.com/ru/post/895830/


All Articles