std::weak_ptr::expired
Материал из 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. |
| bool expired() const; |
(начиная с C++11) | |
Проверяет, является ли управляемый объект уже удален. Эквивалент 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.
Содержание |
[править] Параметры
(Нет)
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.
[править] Возвращаемое значение
true если управляемый объект уже удален, false иначе.
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.
[править] Исключения
[править] Notes
expired() может быть быстрее, чем 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.
[править] Пример
Демонстрирует истекшим используется для проверки действия указателей .
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(); }
Вывод:
gw is valid gw is expired
[править] См. также
| создает shared_ptr, которая управляет указанный объектOriginal: 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. (public функция-член) | |
| возвращает количество объектов, которые shared_ptr управлять объектом 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. (public функция-член) | |