If a container is likely to contain a large number of items, from a performance perspective, should one write
for (auto p = std::begin(container); p != std::end(container); ++p) {...}
or should one access the container's end outside the loop
const auto& theEnd = std::end(container);
for (auto p = std::begin(container); p != theEnd; ++p) {...}
I just wonder if std::end
is O(1) for containers like sets and lists as well as vectors.