The weak_ptr class template stores a "weak reference" to an object that's already managed by a shared_ptr. More...
#include <weak_ptr.hpp>
Public Types | |
typedef T | element_type |
typedef T | value_type |
Public Member Functions | |
weak_ptr () | |
Effects: Constructs an empty weak_ptr. More... | |
template<class Y > | |
weak_ptr (weak_ptr< Y, A, D > const &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. More... | |
template<class Y > | |
weak_ptr (shared_ptr< Y, A, D > const &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. More... | |
template<class Y > | |
weak_ptr & | operator= (weak_ptr< Y, A, D > const &r) |
Effects: Equivalent to weak_ptr(r).swap(*this). More... | |
template<class Y > | |
weak_ptr & | operator= (shared_ptr< Y, A, D > const &r) |
Effects: Equivalent to weak_ptr(r).swap(*this). More... | |
shared_ptr< T, A, D > | lock () const |
Returns: expired()? shared_ptr<T>(): shared_ptr<T>(*this). More... | |
long | use_count () const |
Returns: 0 if *this is empty; otherwise, the number of shared_ptr objects that share ownership with *this. More... | |
bool | expired () const |
Returns: Returns: use_count() == 0. More... | |
void | reset () |
Effects: Equivalent to: weak_ptr().swap(*this). More... | |
void | swap (this_type &other) |
Effects: Exchanges the contents of the two smart pointers. More... | |
template<class T2 , class A2 , class D2 > | |
bool | _internal_less (weak_ptr< T2, A2, D2 > const &rhs) const |
template<class Y > | |
void | _internal_assign (const ipcdetail::shared_count< Y, A, D > &pn2) |
Friends | |
template<class T2 , class A2 , class D2 > | |
class | shared_ptr |
template<class T2 , class A2 , class D2 > | |
class | weak_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.
typedef T boost::interprocess::weak_ptr< T, A, D >::element_type |
typedef T boost::interprocess::weak_ptr< T, A, D >::value_type |
|
inline |
Effects: Constructs an empty weak_ptr.
Postconditions: use_count() == 0.
|
inline |
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.
|
inline |
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.
|
inline |
|
inline |
|
inline |
Returns: Returns: use_count() == 0.
Throws: nothing.
Notes: expired() may be faster than use_count().
Referenced by boost::interprocess::weak_ptr< element_type, A, D >::lock().
|
inline |
Returns: expired()? shared_ptr<T>(): shared_ptr<T>(*this).
Throws: nothing.
|
inline |
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.
|
inline |
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.
|
inline |
Effects: Equivalent to: weak_ptr().swap(*this).
|
inline |
Effects: Exchanges the contents of the two smart pointers.
Throws: nothing.
|
inline |
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.
|
friend |
|
friend |