Does `list <T> :: end ()` invoke inefficiently?
In a C ++ programming book, I saw the following for an iterator std::list:
for (iterator = list.start(); iterator != list.end(); iterator++)
Isn't it ineffective to call list.end()all the time? Would it be better to save the end of another variable, or would it be a C ++ compiler automatically (e.g. g ++)?
+5
8 answers
end() on std::list , :
for (iterator = list.rstart(), end = list.rend(); iterator != end; iterator++) {
// modify list
No iterators will be canceled if you make changes to std::list, but are rendNOT sentinel (it points to the first element of the lower list), which means that it will cease to be the end of the list if you add to the end of the reverse list (also add to the beginning of the unreviewed list .)
0