ęœ€ēµ‚ę›“ę–°ę—„ę™‚:
ćŒę›“ę–°

屄歓 編集

function
<memory>

std::shared_ptr::swap(C++11)

void
  swap(shared_ptr& x) noexcept; // (1) C++11
constexpr void
  swap(shared_ptr& x) noexcept; // (1) C++26

ꦂ要

他恮shared_ptrć‚Ŗćƒ–ć‚øć‚§ć‚ÆćƒˆćØćƒ‡ćƒ¼ć‚æć‚’å…„ć‚Œę›æćˆć‚‹ć€‚

åŠ¹ęžœ

*thisとxć®ćƒ‡ćƒ¼ć‚æć‚’å…„ć‚Œę›æćˆć‚‹ć€‚

ęˆ»ć‚Šå€¤

なし

例外

ęŠ•ć’ćŖć„

例

#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;
}

å‡ŗåŠ›ä¾‹

0x14ab010
0x14ab060
0x14ab060
0x14ab010

ćƒćƒ¼ć‚øćƒ§ćƒ³

čØ€čŖž

  • C++11

処理系

  • GCC: 4.3.6 āœ…
  • Clang: 3.0 āœ…
  • Visual C++: 2008 (TR1) āœ…, 2010 āœ…, 2012 āœ…, 2013 āœ…

å‚ē…§