WeHack BBS
C++标准的std::map迭代器是否按序迭代? - 可打印的版本

+- WeHack BBS (https://bbs.wehack.space)
+-- 版块: 计算机技术 (https://bbs.wehack.space/forum-5.html)
+--- 版块: 程序设计讨论区 (https://bbs.wehack.space/forum-14.html)
+--- 主题: C++标准的std::map迭代器是否按序迭代? (/thread-224.html)



C++标准的std::map迭代器是否按序迭代? - vimacs - 02-03-2021

Stack Overflow 中相关问题:
https://stackoverflow.com/questions/7648756/is-the-order-of-iterating-through-stdmap-known-and-guaranteed-by-the-standard

答案是肯定的,这个在C++标准的Associative containers一节中说明。[n4659 26.2.6.1]


引用:11 The fundamental property of iterators of associative containers is that they iterate through the containersin the non-descending order of keys where non-descending is defined by the comparison that was used toconstruct them. For any two dereferenceable iterators i and j such that distance from i to j is positive, the following condition holds:

value_comp(*j, *i) == false