- memory[meta header]
- std[meta namespace]
- unique_ptr[meta class]
- function[meta id-type]
- cpp11[meta cpp]
void swap(unique_ptr& x) noexcept;他のunique_ptrオブジェクトとデータを入れ替える。
デリータDが、例外を投げないという保証のもとにswap可能であること。
*thisとxが保持する、ポインタとデリータオブジェクトそれぞれに対して、swap()関数を実行する。
なし
#include <iostream>
#include <memory>
int main()
{
std::unique_ptr<int> a(new int(3));
std::unique_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.4.7
- Clang libc++, C++11 mode: 3.0
- ICC: ?
- Visual C++: 2010, 2012, 2013