The standard containers all return references from their iterator (note, however, that some “containers aren’t really container, e.g., std::vector<bool>
which returns a proxy). Other iterators might return proxies or values although this isn’t strictly supported.
Of course, the standard doesn’t make any guarantees with respect to performance. Any sort of performance related feature (beyond complexity guarantees) are considered to be quality of implementation.
That said, you might want to consider having the compiler make the choice for you as it did before:
for (auto&& e: coll) { f(e); }
The main issue here is that f()
may receive a non-const
reference. This can be prevented if necessary using a const
version of coll
.