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
source share
8 answers

std::list<T>::end() , , . , , . , . , , , .

, , : , . , - , , std::list<T>::end() ( , , , , , , t , ). , list.end() .

, , iterator++ ++iterator, , . , -, list.end(), .

+4

list::end() , , , , , , .

, ( , ).

, , .

+8

.

, . , , . : list::iterator, , , iterator ?

, .

, , . - , , .

+4

, , . end() , , , . , ? , , , end(). , , , , .

+4

STL container::end() . ++ ( ) container::end() .

, , , . , , , list.end(), , , x86, .

, , list.end() .

+2

-, .

list.end() , , . , .. , .

, for (iterator = list.start(), end = list.end; iteration != end; ++iterator). ( pre-inc) .

, .end() , .

+1

, . , .. , :

for (mylist::iterator it = alist.begin(), finish = alist.end();  it != finish;  ++it)

, , .

, , .

+1

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
source

All Articles