gpt4 book ai didi

c++ - std::map 是否分配它的比较器?

转载 作者:可可西里 更新时间:2023-11-01 17:39:58 27 4
gpt4 key购买 nike

std::map 是否需要复制赋值(样式为 map1 = map2;)以将 map2 的比较器复制到 map1 ?

我已经测试过实际的实现是这样的。我对它在 C++ 标准中的指定位置更感兴趣。

最佳答案

如果我们查看 [associative.reqmts]/12,我们有

When an associative container is constructed by passing a comparison object the container shall not store a pointer or reference to the passed object, even if that object is passed by reference. When an associative container is copied, either through a copy constructor or an assignment operator, the target container shall then use the comparison object from the container being copied, as if that comparison object had been passed to the target container in its constructor.

强调我的

因此,在您的示例中,map1 将获得 map2 的比较器的拷贝。

关于c++ - std::map 是否分配它的比较器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45218398/

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