function template
<unordered_set>

std::swap (unordered_multiset)

template <class Key, class Hash, class Pred, class Alloc>  void swap ( unordered_multiset<Key,Hash,Pred,Alloc>& lhs,              unordered_multiset<Key,Hash,Pred,Alloc>& rhs );
Exchanges contents of two unordered_multiset containers
容器lhs的內容與rhs的內容交換。兩個容器物件必須是相同的型別(相同的模板引數),但大小可能不同。

After the call to this member function, the elements in lhs are those which were in rhs before the call, and the elements of rhs are those which were in lhs. Other objects kept internally by the containers (such as theirhasherorkey_equal物件)也會被交換。

這是通用演算法 swap 的一個特化,它透過交換指向資料的內部指標來提高其效能,而無需實際對單個元素執行任何複製或移動操作。

引數

lhs,rhs
unordered_multiset containers (to the left- and right-hand side of the operator, respectively), having both the same template parameters (, Hash, PredAlloc).

返回值



示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// swap (unordered_multiset specialization)
#include <iostream>
#include <string>
#include <unordered_set>

int main ()
{
  std::unordered_multiset<std::string>
     first = {"cow","chicken","pig","pig"},
     second  = {"wolf","rabbit","rabbit"};

  swap(first,second);

  std::cout << "first:";
  for (const std::string& x: first) std::cout << " " << x;
  std::cout << std::endl;

  std::cout << "second:";
  for (const std::string& x: second) std::cout << " " << x;
  std::cout << std::endl;

  return 0;
}

可能的輸出
first: wolf rabbit rabbit
second: chicken cow pig pig


複雜度

常量。

迭代器有效性

所有迭代器、指標和引用都保持有效,但現在它們指向其他容器中的元素,並在其中進行迭代。

另見