Skip to content

Latest commit

 

History

History
66 lines (49 loc) · 1.08 KB

swap.md

File metadata and controls

66 lines (49 loc) · 1.08 KB

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));

  std::cout << a << std::endl;
  std::cout << b << std::endl;

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

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

出力例

0x14ab010
0x14ab060
0x14ab060
0x14ab010

バージョン

言語

  • C++11

処理系

  • GCC: 4.3.6 [mark verified]
  • Clang: 3.0 [mark verified]
  • ICC: ?
  • Visual C++: 2008 (TR1) [mark verified], 2010 [mark verified], 2012 [mark verified], 2013 [mark verified]