【发布时间】:2010-11-21 04:38:13
【问题描述】:
我的同事声称对于对象类型,前增量比后增量更有效
例如
std::vector<std::string> vec;
... insert a whole bunch of strings into vec ...
// iterate over and do stuff with vec. Is this more efficient than the next
// loop?
std::vector<std::string>::iterator it;
for (it = vec.begin(); it != vec.end(); ++it){
}
// iterate over and do stuff with vec. Is this less efficient than the previous loop?
std::vector<std::string>::iterator it;
for (it = vec.begin(); it != vec.end(); it++){
}
【问题讨论】:
-
非常接近 *.com/questions/24901/… 的副本。这个问题确实指定了迭代器,而链接的问题更笼统。
-
感谢该链接有一个很好的答案。
标签: c++ performance