Ordered iteration is not an implementation detail; It is guaranteed by the C ++ standard. This is a fundamental property of all associative containers (C ++ 03 §23.1.2 / 9):
The fundamental property of associative container iterators is that they iterate over containers in non-decreasing order of keys, where non-descent is determined by the comparison that was used to create them. For any two dereferenced iterators iand jsuch that the distance from ito is jpositive,
value_comp(*j, *i) == false
value_comp- this is the comparator with which the map was built (by default this std::less<T>).
source
share