Skip to content

Latest commit

 

History

History
61 lines (45 loc) · 928 Bytes

File metadata and controls

61 lines (45 loc) · 928 Bytes

swap

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

概要

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

効果

*thisxのデータを入れ替える。

戻り値

なし

例外

投げない

#include <iostream>
#include <memory>

int main()
{
  std::shared_ptr<int> a(new int(3));
  std::shared_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

処理系