GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::weak_ptr::expired(3) C++ Standard Libary std::weak_ptr::expired(3)

std::weak_ptr::expired - std::weak_ptr::expired


bool expired() const noexcept; (since C++11)


Equivalent to use_count() == 0. The destructor for the managed object may not yet
have been called, but this object's destruction is imminent (or may have already
happened).


(none)


true if the managed object has already been deleted, false otherwise.


This function is inherently racy if the managed object is shared among threads. In
particular, a false result may become stale before it can be used. A true result is
reliable.


Demonstrates how expired is used to check validity of the pointer.

// Run this code


#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


lock creates a shared_ptr that manages the referenced object
(public member function)
use_count returns the number of shared_ptr objects that manage the object
(public member function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.