gpt4 book ai didi

c++ - std::map 中的元素是否保证有序?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:54:39 26 4
gpt4 key购买 nike

这只是实现的副作用(红黑树)还是顺序由 c++ 标准保证?

最佳答案

有序迭代不是实现细节;它由 C++ 标准保证。它是所有关联容器的基本属性 (C++03 §23.1.2/9):

The fundamental property of iterators of associative containers is that they iterate through the containers in the non-descending order of keys where non-descending is defined by the comparison that was used to construct them. For any two dereferenceable iterators i and j such that distance from i to j is positive,

    value_comp(*j, *i) == false

value_comp是构建 map 的比较器(默认情况下,它是 std::less<T> )。

关于c++ - std::map 中的元素是否保证有序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3349655/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com