Should I prefer iterators over const_iterators?

前端 未结 6 2148
没有蜡笔的小新
没有蜡笔的小新 2020-12-14 16:07

Someone here recently brought up the article from Scott Meyers that says:

  • Prefer iterators over const_iterators (pdf link).
6条回答
  •  醉梦人生
    2020-12-14 16:42

    I don't think this particular statement of Meyer's needs to be taken with special concern. When you want a non-modifying operation, it is best to use a const_iterator. Otherwise, use an ordinary iterator. However, do note the one important thing: Never mix iterators i.e. const ones with non-const ones. As long as you are aware of the latter, you should be fine.

提交回复
热议问题