Mark <[EMAIL PROTECTED]> wrote: >> Likewise, instead of >> >> for(vector<int>::const_iterator it = v.begin(); it != v.end(); ++it) >> >> try >> >> for(vector<int>::const_iterator it = v.begin(), end = v.end(); it != >> end; ++it) >> >> to avoid calling v.end() every time. >> > > Aren't compilers smart enough yet to in effect do that if it sees there's > nothing done inside the loop that would change the vector's size? > That seems like something an optimizer should do.
It seems a very unlikely thing an optimizer _can_ do. It would basically need to inspect all the code inside the loop and make sure that the vector is not changed directly or by some external reference - and this is pretty unlikely if there is e.g. a call to some function in some different translation unit. It is not much more effort to write for(vector<int>::const_iterator it = v.begin(), end = v.end(); it != end; ++it) instead of for(vector<int>::const_iterator it = v.begin(); it != v.end(); ++it) and you can be sure that the end() call is evaluated only once. Andre' _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus