std::shared_ptr::unique
De 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> bool unique() const; |
||
Vérifie si l'instance est
*this shared_ptr que la gestion de l'objet courant, à savoir si 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.
Paramètres
(Aucun)
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.
Retourne la valeur
true si *this est l'instance shared_ptr que la gestion de l'objet courant, false autrement .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.
Exemple
#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;
}
Résultat :
sp1.unique() == true
sp1.unique() == false
Voir aussi
retourne le nombre d'objets shared_ptr se référant au même objet géré Original: returns the number of shared_ptr objects referring to the same managed object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique) | |