c++ - 相同的 'value' 对 std::set 意味着什么?

标签 c++ stl insert comparison stdset

在 C++ 中,std::set::insert() 仅在不存在具有相同“值”的值时才插入一个值。同样,这意味着 operator== 还是意味着 operator< 对于任一排序都为 false ,还是意味着其他东西?

最佳答案

does it mean one for which operator< is false for either ordering?

是的,如果集合使用默认比较器并使用 < 比较键.更一般地说,在带有比较器的有序容器中 Compare , 两个键 k1k2如果 !Compare(k1,k2) && !Compare(k2,k1) 被视为等价 .

实现operator==不需要 key 或其他任何东西;它们只需要使用容器的比较器进行比较即可给出 strict weak ordering .

关于c++ - 相同的 'value' 对 std::set 意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12682694/

相关文章:

c++ - GCC C++ 名称修改引用

c++ - 如何为控制台输入 (stdin) 获取类似 QIODevice 的信号?

c++ - C++11 中的 std::forward_list swap() 实现

javascript - "Working"脚本返回未捕获的 DOMException : Failed to execute 'insertBefore' on 'Node' : The new child element contains the parent

python - 如何使用Python执行MariaDB数据库插入?

c++ - grpc c++中的异步模型

c++ - 避免输出负零的最佳方法是什么?

c++ - 迭代器如何在以下程序中工作

C++ STL unordered_map问题与疑惑

MySQL:如果在 SELECT 语句中找不到记录,则插入数据