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