Containers are required to implement operator==()
. That is we can do:
container c;
c == c;
That relation is required to work the same as:
std::distance(a.begin(), a.end()) == std::distance(b.begin(), b.end()) &&
std::equal(a.begin(), a.end(), b.begin());
The important part here is the call to std::equal()
. This call requires that two independent calls to container.begin()
will produce the same sequence of values. If it didn't, then c == c
would be false, and that doesn't make any sense because ==
is an equivalence relation.
Therefore, my answer is that we can claim that the standard requires that two passes of any container must result in the same ordering. Obviously this requirement breaks if you do anything that changes the container or invalidates iterators.
Citations:
- C++ 2011 Table 96 — Container requirements
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…