Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++

Name: Snake4D 2012-04-11 17:38

A simple question...

is it better to traverse a std::vector like this:

std::vector<int> myvec;
//populate the vector
for(int i = 0; i < myvec.size(); ++i){
    myvec[i] += 1;
}


or is better like this?

std::vector<int> myvec;
typedef std::vector<int>::iterator IT_int;
for(IT_int it = myvec.begin(); it != myvec.end(); ++it){
     *it += 1;
}

Name: Anonymous 2012-04-13 2:40

>>24
>>25
Why is that wrong? On x86 gcc uses cmp to implement < and test-instruction to implement !=. What else do think causes the difference in speed if the only difference in generated loops is that one uses cmp and one uses test?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List