On https://doc-snapshots.qt.io/qtcreator-extending/coding-style.html it is recommended to write for loops like the following:
Container::iterator end = large
This is less about end
being costly and more about the ability of a compiler to see that end
will not change through a side effect in the loop body (that it is a loop invariant).
The complexity of end
is required to be constant by the standard. See table 96 in N3337 in 23.2.1
.
Using standard library algorithms circumvents the whole dilemma nicely.