Skip to content

Latest commit

 

History

History
61 lines (45 loc) · 1.07 KB

File metadata and controls

61 lines (45 loc) · 1.07 KB

swap

  • memory[meta header]
  • std[meta namespace]
  • unique_ptr[meta class]
  • function[meta id-type]
  • cpp11[meta cpp]
void swap(unique_ptr& x) noexcept;

概要

他のunique_ptrオブジェクトとデータを入れ替える。

要件

デリータDが、例外を投げないという保証のもとにswap可能であること。

効果

*thisxが保持する、ポインタとデリータオブジェクトそれぞれに対して、swap()関数を実行する。

戻り値

なし

#include <iostream>
#include <memory>

int main()
{
  std::unique_ptr<int> a(new int(3));
  std::unique_ptr<int> b(new int(1));

  // aとbを入れ替える
  a.swap(b);

  std::cout << *a << std::endl;
  std::cout << *b << std::endl;
}
  • swap[color ff0000]

出力

1
3

バージョン

言語

  • C++11

処理系