std::shared_ptr::unique
Aus cppreference.com
< cpp | memory | shared ptr
![]() | 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. |
bool unique()const; | ||
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.
You can help to correct and verify the translation. Click here for instructions.
Inhaltsverzeichnis |
[Bearbeiten]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.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten]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.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten]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
[Bearbeiten]Siehe auch
gibt die Anzahl der shared_ptr -Objekte zurück, die auf dasselbe verwaltete Objekt verweisen (öffentliche Elementfunktion) |