std :: map find/end both提供了const_iterator和iterator,例如,m.find(...)== m.end() - 使用哪个,iterator或const_iterator
iterator end();
const_iterator end() const
出于好奇,如果我有一个std ::地图,将其称之为/这里相比,迭代器或常量性? :
if(m.find(key) != m.end()) {
...
}
我应该在意吗?
当你写你自己的算法时,它很重要。然后你应该指定你的算法是否是修改算法。如果不是那么你说它可以用'const_iterator'工作。知道你调用的哪些算法正在修改而哪些算法不是这样:这样,当你得到一个错误时,你可以告诉它是因为你传递了一个'const_iteratr'(可能是因为它来自一个'const'对象)修改算法。 – wilhelmtell 2010-04-13 19:42:01