我应该优先于const_iterators的迭代器吗? [英] Should I prefer iterators over const_iterators?
问题描述
Someone here recently brought up the article from Scott Meyers that says:
- 首选
迭代器
overconst_iterators
( pdf链接)。
- Prefer
iterators
overconst_iterators
(pdf link).
有人评论说这篇文章可能已过时。我想知道你的意见是什么?
Someone else was commenting that the article is probably outdated. I'm wondering what your opinions are?
这里是我的:文章的要点之一是你不能删除或插入 const_iterator
,但我认为使用它作为 const_iterators
的参数很有趣。我认为整个点 const_iterators
它,你根本不修改范围,元素本身通过替换它们的值和范围通过插入或删除。
Here is mine: One of the main points of the article is that you cannot erase or insert on a const_iterator
, but I think it's funny to use that as an argument against const_iterators
. I thought the whole point of const_iterators
it that you do not modify the range at all, neither the elements themselves by substituting their values nor the range by inserting or erasing. Or am I missing something?
推荐答案
我完全同意你的看法。
我想答案很简单:
使用const_iterators,其中const值是正确的使用,反之亦然。
对我来说,那些反对const_iterators的人一定是反对const的...
I totally agree with you. I think the answer is simple: Use const_iterators where const values are the right thing to use, and vice versa. Seems to me that those who are against const_iterators must be against const in general...
这篇关于我应该优先于const_iterators的迭代器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!