Skip to content

Latest commit

 

History

History
63 lines (47 loc) · 975 Bytes

File metadata and controls

63 lines (47 loc) · 975 Bytes

swap (非メンバ関数)

  • memory[meta header]
  • std[meta namespace]
  • function template[meta id-type]
  • cpp11[meta cpp]
namespace std {
  template <class T>
  void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
}

概要

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

効果

a.swap(b)

戻り値

なし

例外

投げない

#include <iostream>
#include <memory>

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

  // aとbを入れ替える
  std::swap(a, b);

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

出力

1
3

バージョン

言語

  • C++11

処理系