私の同僚は、オブジェクト型の事前増分よりも後増分よりも効率的であると主張しています。++イテレータとイテレータ++のパフォーマンスの違いは?
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++){
}
http://stackoverflow.com/questions/24901/is-there-a-performance-difference-between-i--i-in-cの複製にかなり近いです。この質問は反復子を指定しますが、リンクされた質問はより一般的です。 – Eclipse
リンクには素晴らしい答えがあります。 – Matt