可能的没有副本的交换图元素?

ste*_*km3 1 c++

我有一个 map<int,map<int,string>> themap

我想交换元素themap [1]和themap [2]。但是内部地图map<int,string>很大,所以我不想复制它们。有没有办法做到这一点,或者我必须更改地图以使用指针。

Ale*_*exD 5

您可以尝试std::map::swap外部地图:

void swap( map& other );

与其他容器交换内容。不对单个元素调用任何移动,复制或交换操作。