我应该优先于const_iterators的迭代器吗? [英] Should I prefer iterators over const_iterators?

查看:154
本文介绍了我应该优先于const_iterators的迭代器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近有人在提出了来自Scott Meyers的文章:

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

  • Prefer iterators over const_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆