std::shared_ptr::unique – cppreference.com
Aus cppreference.com
<metanoindex/>
<tbody> </tbody>
Prüft, ob *this ist die einzige shared_ptr beispielsweise die Verwaltung des aktuellen Objekts, dh ob use_count() == 1 .
Original:
Checks if *this is the only shared_ptr instance managing the current object, i.e. whether use_count() == 1.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Parameter
(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.
Rückgabewert
true wenn *this ist die einzige shared_ptr beispielsweise die Verwaltung des aktuellen Objekts, false sonst .
Original:
true if *this is the only shared_ptr instance managing the current object, false otherwise.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Beispiel
#include <memory> #include <iostream> int main() { std::shared_ptr<int> sp1 {std::make_shared<int>(5)}; std::cout << "sp1.unique() == " << std::boolalpha << sp1.unique() << std::endl; std::shared_ptr<int> sp2 {sp1}; std::cout << "sp1.unique() == " << std::boolalpha << sp1.unique() << std::endl; }
Output:
sp1.unique() == true sp1.unique() == false
Siehe auch
gibt die Anzahl der shared_ptr-Objekte zurück, die auf dasselbe verwaltete Objekt verweisen (öffentliche Elementfunktion) [edit] | |