在 C++ 中,std::set::insert() 仅在不存在具有相同“值”的值时才插入一个值。同样,这意味着 operator== 还是意味着 operator< 对于任一排序都为 false ,还是意味着其他东西?
最佳答案
does it mean one for which operator< is false for either ordering?
是的,如果集合使用默认比较器并使用 <
比较键.更一般地说,在带有比较器的有序容器中 Compare
, 两个键 k1
和 k2
如果 !Compare(k1,k2) && !Compare(k2,k1)
被视为等价 .
实现operator==
不需要 key 或其他任何东西;它们只需要使用容器的比较器进行比较即可给出 strict weak ordering .
关于c++ - 相同的 'value' 对 std::set 意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12682694/