Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

m.find(...) == m.end() - which is used, iterator or const_iterator

Tags:

c++

templates

stl

std::map find/end both provides const_iterator and iterator, e.g.

  iterator end ();
  const_iterator end () const

Out of curiosity,if I have a std::map , which will be called/compared here, an iterator or a const_iterator ? :

if(m.find(key) != m.end()) {
   ...
}

And should I care ?

like image 977
leeeroy Avatar asked Apr 13 '10 19:04

leeeroy


1 Answers

If m is const, then a const_iterator will be returned; otherwise an iterator will be returned.

If all you are doing is testing for existence of an element in the map, then it doesn't really matter which one is used.

like image 194
James McNellis Avatar answered Sep 26 '22 18:09

James McNellis