copy/move/swap 是否也在 std::set/map 的比较器上运行?

Do copy/move/swap also operate on the comparators of std::set/map?

移动赋值、复制赋值和交换操作(如果有的话)中的哪些也对集合和映射的嵌入式比较器进行操作?

(换句话说,如果我例如 swap 两个 set,它们的比较器是否也会被交换?)

如果旧版本的 C++(例如 C++98 或 C++03)的答案不同,请注明。

标准包含以下保证

For associative containers, no swap function throws an exception unless that exception is thrown by the swap of the container’s Compare object (if any).

所以答案是肯定的 - 比较对象也被交换函数交换。

引用适用于 C++11-17。我没有更早的草稿。

对于复制和移动——我只能推断——因为 copy/move 的任何合理实现都使用交换,所以相同的答案是正确的。但是我没有找到具体的报价...

根据一般容器要求引用 n1905(我能找到的最接近 2003 年官方出版物的版本,尽管它较晚):

[lib.container.requirements]/11:

Unless otherwise specified all container types defined in this clause meet the following additional requirements:

  • no swap() function throws an exception unless that exception is thrown by the copy constructor or assignment operator of the container’s Compare object

因此,如果比较对象需要复制,这几乎指定了它应该被复制。