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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With