std::unique_ptr<T,Deleter>::swap (3) - Linux Manuals
std::unique_ptr<T,Deleter>::swap: std::unique_ptr<T,Deleter>::swap
Command to display std::unique_ptr<T,Deleter>::swap
manual in Linux: $ man 3 std::unique_ptr<T,Deleter>::swap
NAME
std::unique_ptr<T,Deleter>::swap - std::unique_ptr<T,Deleter>::swap
Synopsis
void swap(unique_ptr& other) noexcept; (since C++11)
Swaps the managed objects and associated deleters of *this and another unique_ptr object other.
Parameters
other - another unique_ptr object to swap the managed object and the deleter with
Return value
(none)
Example
// Run this code
#include <iostream>
#include <memory>
struct Foo {
Foo(int _val) : val(_val) { std::cout << "Foo...\n"; }
~Foo() { std::cout << "~Foo...\n"; }
int val;
};
int main()
{
std::unique_ptr<Foo> up1(new Foo(1));
std::unique_ptr<Foo> up2(new Foo(2));
up1.swap(up2);
std::cout << "up1->val:" << up1->val << std::endl;
std::cout << "up2->val:" << up2->val << std::endl;
}
Output:
Foo...
Foo...
up1->val:2
up2->val:1
~Foo...
~Foo...
Pages related to std::unique_ptr<T,Deleter>::swap
- std::unique_ptr<T,Deleter>::get (3) - std::unique_ptr<T,Deleter>::get
- std::unique_ptr<T,Deleter>::get_deleter (3) - std::unique_ptr<T,Deleter>::get_deleter
- std::unique_ptr<T,Deleter>::operator<< (3) - std::unique_ptr<T,Deleter>::operator<<
- std::unique_ptr<T,Deleter>::operator= (3) - std::unique_ptr<T,Deleter>::operator=
- std::unique_ptr<T,Deleter>::operator[] (3) - std::unique_ptr<T,Deleter>::operator[]
- std::unique_ptr<T,Deleter>::operatorbool (3) - std::unique_ptr<T,Deleter>::operatorbool
- std::unique_ptr<T,Deleter>::release (3) - std::unique_ptr<T,Deleter>::release
- std::unique_ptr<T,Deleter>::reset (3) - std::unique_ptr<T,Deleter>::reset
- std::unique_ptr<T,Deleter>::unique_ptr (3) - std::unique_ptr<T,Deleter>::unique_ptr
- std::unique_ptr<T,Deleter>::~unique_ptr (3) - std::unique_ptr<T,Deleter>::~unique_ptr
- std::unique_ptr (3) - std::unique_ptr
- std::unique_copy (3) - std::unique_copy
- std::unique_lock (3) - std::unique_lock
- std::unique_lock<Mutex>::lock (3) - std::unique_lock<Mutex>::lock
- std::unique_lock<Mutex>::mutex (3) - std::unique_lock<Mutex>::mutex
- std::unique_lock<Mutex>::operator= (3) - std::unique_lock<Mutex>::operator=