std::unique_ptr::swap
Aus cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody> void swap(unique_ptr& other); |
(seit C++11) | |
Tauscht die verwalteten Objekte und zugehörige deleters mit einem anderen
unique_ptr Objekt other .Original:
Swaps the managed objects and associated deleters with another
unique_ptr object other.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Parameter
| other | - | anderen
unique_ptr Objekt, um das verwaltete Objekt und die deleter mit zu tauschenOriginal: another unique_ptr object to swap the managed object and the deleter withThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Rückgabewert
(None)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Ausnahmen
Beispiel
#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...