- 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オブジェクトとデータを入れ替える。
*thisとxのデータを入れ替える。
なし
投げない
#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
- GCC: 4.3.6
- Clang libc++, C++11 mode: 3.0
- ICC: ?
- Visual C++: 2008 (TR1), 2010, 2012, 2013