Reading various questions here on Stack Overflow about C++ iterators and performance**, I started wondering if for(auto& elem : container)
gets "expanded" by the compiler into the best possible version? (Kind of like auto
, which the compiler infers into the right type right away and is therefore never slower and sometimes faster).
** For example, does it matter if you write
for(iterator it = container.begin(), eit = container.end(); it != eit; ++it)
or
for(iterator it = container.begin(); it != container.end(); ++it)
for non-invalidating containers?
See Question&Answers more detail:os