Skip to content

Latest commit

 

History

History
70 lines (55 loc) · 1.27 KB

swap_free.md

File metadata and controls

70 lines (55 loc) · 1.27 KB

swap (非メンバ関数)

  • set[meta header]
  • std[meta namespace]
  • function template[meta id-type]
namespace std {
  template <class Key, class Compare, class Allocator>
  void swap(multiset<Key, Compare, Allocator>& x,
            multiset<Key, Compare, Allocator>& y);

  template <class Key, class Compare, class Allocator>
  void swap(multiset<Key, Compare, Allocator>& x,
            multiset<Key, Compare, Allocator>& y)
    noexcept(noexcept(x.swap(y))); // C++17
}

概要

2つのmultisetオブジェクトを入れ替える。

効果

x.swap(y);
  • swap[link swap.md]

計算量

定数時間

#include <iostream>
#include <set>

int main()
{
  std::multiset<int> c1, c2;

  c1.insert(10);
  c1.insert(20);
  c1.insert(30);

  c2.insert(5);
  c2.insert(15);

  std::swap(c1, c2);

  std::multiset<int>::iterator i = c1.begin();
  while (i != c1.end()) {
    std::cout << *(i++) << ",";
  }
  std::cout << std::endl;
}
  • std::swap[color ff0000]
  • insert[link insert.md]
  • c1.begin()[link begin.md]
  • c1.end()[link end.md]

出力

5,15,

参照