![]() |
Home | Libraries | People | FAQ | More |
boost::interprocess::weak_ptr
// In header: <boost/interprocess/smart_ptr/weak_ptr.hpp> template<typename T, typename A, typename D> class weak_ptr { public: // types typedef ; typedef ; // construct/copy/destruct (); template<typename Y> (weak_ptr< ); template<typename Y> (shared_ptr< ); template<typename Y> weak_ptr & (weak_ptr< ); template<typename Y> weak_ptr & (shared_ptr< ); // public member functions shared_ptr< () ; () ; () ; (); (); };
The weak_ptr class template stores a "weak reference" to an object that's already managed by a shared_ptr. To access the object, a weak_ptr can be converted to a shared_ptr using the shared_ptr constructor or the member function lock. When the last shared_ptr to the object goes away and the object is deleted, the attempt to obtain a shared_ptr from the weak_ptr instances that refer to the deleted object will fail: the constructor will throw an exception of type bad_weak_ptr, and weak_ptr::lock will return an empty shared_ptr.
Every weak_ptr meets the CopyConstructible and Assignable requirements of the C++ Standard Library, and so can be used in standard library containers. Comparison operators are supplied so that weak_ptr works with the standard library's associative containers.
weak_ptr operations never throw exceptions.
The class template is parameterized on T, the type of the object pointed to.
weak_ptr
public
construct/copy/destruct();
Effects: Constructs an empty weak_ptr
. Postconditions: use_count() == 0.
template<typename Y> (weak_ptr< r);
Effects: If r is empty, constructs an empty weak_ptr
; otherwise, constructs a weak_ptr
that shares ownership with r as if by storing a copy of the pointer stored in r.
Postconditions: use_count() == r.use_count().
Throws: nothing.
template<typename Y> (shared_ptr< r);
Effects: If r is empty, constructs an empty weak_ptr
; otherwise, constructs a weak_ptr
that shares ownership with r as if by storing a copy of the pointer stored in r.
Postconditions: use_count() == r.use_count().
Throws: nothing.
template<typename Y> weak_ptr & (weak_ptr< r);
Effects: Equivalent to weak_ptr(r).swap(*this).
Throws: nothing.
Notes: The implementation is free to meet the effects (and the implied guarantees) via different means, without creating a temporary.
template<typename Y> weak_ptr & (shared_ptr< r);
Effects: Equivalent to weak_ptr(r).swap(*this).
Throws: nothing.
Notes: The implementation is free to meet the effects (and the implied guarantees) via different means, without creating a temporary.
weak_ptr
public member functionsshared_ptr< () ;
Returns: expired()? shared_ptr<T>(): shared_ptr<T>(*this).
Throws: nothing.
() ;
Returns: 0 if *this is empty; otherwise, the number of shared_ptr
objects that share ownership with *this.
Throws: nothing.
Notes: use_count() is not necessarily efficient. Use only for debugging and testing purposes, not for production code.
() ;
Returns: Returns: use_count() == 0.
Throws: nothing.
Notes: expired() may be faster than use_count().
();
Effects: Equivalent to: weak_ptr().swap(*this).
( other);
Effects: Exchanges the contents of the two smart pointers.
Throws: nothing.