开发者

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

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/compa开发者_运维知识库red 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.


It depends on if your map is const or not. If it is, you'll get a const_iterator. If not, you get an iterator.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜