std::weak_ptr::expired
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 expired() const; |
(desde C++11) | |
Verifica se o objeto gerenciado já foi excluído. Equivalente a
use_count() == 0.Original:
Checks whether the managed object has already been deleted. Equivalent to
use_count() == 0.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.
Parâmetros
(Nenhum)
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.
Valor de retorno
true se o objeto gerenciado já foi excluído, false outra forma.Original:
true if the managed object has already been deleted, 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.
Exceções
Notas
expired() pode ser mais rápida do que use_count().Original:
expired() may be faster than use_count().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.
Exemplo
Demonstra como expirado é utilizado para verificar a validade do ponteiro .
Original:
Demonstrates how expired is used to check validity of the pointer.
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.
#include <iostream>
#include <memory>
std::weak_ptr<int> gw;
void f()
{
if (!gw.expired()) {
std::cout << "gw is valid\n";
}
else {
std::cout << "gw is expired\n";
}
}
int main()
{
{
auto sp = std::make_shared<int>(42);
gw = sp;
f();
}
f();
}
Saída:
gw is valid
gw is expired
Veja também
cria um shared_ptr que gerencia o objeto referenciadoOriginal: creates a shared_ptr that manages the referenced objectThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
retorna o número de objetos shared_ptr que gerenciam o objeto Original: returns the number of shared_ptr objects that manage the object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |