Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::interprocess::shared_ptr< T, VoidAllocator, Deleter > Class Template Reference

shared_ptr stores a pointer to a dynamically allocated object. More...

#include <shared_ptr.hpp>

Public Types

typedef T element_type
 
typedef T value_type
 
typedef
boost::intrusive::pointer_traits
< typename
VoidAllocator::pointer >
::template rebind_pointer< T >
::type 
pointer
 
typedef
ipcdetail::add_reference
< value_type >::type 
reference
 
typedef
ipcdetail::add_reference
< const value_type >::type 
const_reference
 
typedef
boost::intrusive::pointer_traits
< typename
VoidAllocator::pointer >
::template rebind_pointer
< const Deleter >::type 
const_deleter_pointer
 
typedef
boost::intrusive::pointer_traits
< typename
VoidAllocator::pointer >
::template rebind_pointer
< const VoidAllocator >::type 
const_allocator_pointer
 
typedef void(this_type::* unspecified_bool_type )() const
 

Public Member Functions

 shared_ptr ()
 Constructs an empty shared_ptr. More...
 
 shared_ptr (const pointer &p, const VoidAllocator &a=VoidAllocator(), const Deleter &d=Deleter())
 Constructs a shared_ptr that owns the pointer p. More...
 
 shared_ptr (const shared_ptr &r)
 Copy constructs a shared_ptr. More...
 
 shared_ptr (const shared_ptr &other, const pointer &p)
 Constructs a shared_ptr that shares ownership with other and stores p. More...
 
template<class Y >
 shared_ptr (shared_ptr< Y, VoidAllocator, Deleter > const &r)
 If r is empty, constructs an empty shared_ptr. More...
 
template<class Y >
 shared_ptr (weak_ptr< Y, VoidAllocator, Deleter > const &r)
 Constructs a shared_ptr that shares ownership with r and stores a copy of the pointer stored in r. More...
 
 shared_ptr (BOOST_RV_REF(shared_ptr) other)
 Move-Constructs a shared_ptr that takes ownership of other resource and other is put in default-constructed state. More...
 
template<class Y >
 shared_ptr (shared_ptr< Y, VoidAllocator, Deleter > const &r, ipcdetail::static_cast_tag)
 
template<class Y >
 shared_ptr (shared_ptr< Y, VoidAllocator, Deleter > const &r, ipcdetail::const_cast_tag)
 
template<class Y >
 shared_ptr (shared_ptr< Y, VoidAllocator, Deleter > const &r, ipcdetail::dynamic_cast_tag)
 
template<class Y >
shared_ptroperator= (shared_ptr< Y, VoidAllocator, Deleter > const &r)
 Equivalent to shared_ptr(r).swap(*this). More...
 
shared_ptroperator= (BOOST_COPY_ASSIGN_REF(shared_ptr) r)
 Equivalent to shared_ptr(r).swap(*this). More...
 
shared_ptroperator= (BOOST_RV_REF(shared_ptr) other)
 Move-assignment. More...
 
void reset ()
 This is equivalent to: this_type().swap(*this);. More...
 
template<class Pointer >
void reset (const Pointer &p, const VoidAllocator &a=VoidAllocator(), const Deleter &d=Deleter())
 This is equivalent to: this_type(p, a, d).swap(*this);. More...
 
template<class Y >
void reset (shared_ptr< Y, VoidAllocator, Deleter > const &r, const pointer &p)
 
reference operator* () const
 Returns a reference to the pointed type. More...
 
pointer operator-> () const
 Returns the pointer pointing to the owned object. More...
 
pointer get () const
 Returns the pointer pointing to the owned object. More...
 
void unspecified_bool_type_func () const
 
 operator unspecified_bool_type () const
 
bool operator! () const
 Not operator. More...
 
bool unique () const
 Returns use_count() == 1. More...
 
long use_count () const
 Returns the number of shared_ptr objects, *this included, that share ownership with *this, or an unspecified nonnegative value when *this is empty. More...
 
void swap (shared_ptr< T, VoidAllocator, Deleter > &other)
 Exchanges the contents of the two smart pointers. More...
 
template<class T2 , class A2 , class Deleter2 >
bool _internal_less (shared_ptr< T2, A2, Deleter2 > const &rhs) const
 
const_deleter_pointer get_deleter () const
 

Friends

template<class T2 , class A2 , class Deleter2 >
class shared_ptr
 
template<class T2 , class A2 , class Deleter2 >
class weak_ptr
 

Detailed Description

template<class T, class VoidAllocator, class Deleter>
class boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >

shared_ptr stores a pointer to a dynamically allocated object.

The object pointed to is guaranteed to be deleted when the last shared_ptr pointing to it is destroyed or reset.

shared_ptr is parameterized on T (the type of the object pointed to), VoidAllocator (the void allocator to be used to allocate the auxiliary data) and Deleter (the deleter whose operator() will be used to delete the object.

The internal pointer will be of the same pointer type as typename VoidAllocator::pointer type (that is, if typename VoidAllocator::pointer is offset_ptr<void>, the internal pointer will be offset_ptr<T>).

Because the implementation uses reference counting, cycles of shared_ptr instances will not be reclaimed. For example, if main() holds a shared_ptr to A, which directly or indirectly holds a shared_ptr back to A, A's use count will be 2. Destruction of the original shared_ptr will leave A dangling with a use count of 1. Use weak_ptr to "break cycles."

Member Typedef Documentation

template<class T, class VoidAllocator, class Deleter>
typedef boost::intrusive:: pointer_traits<typename VoidAllocator::pointer>::template rebind_pointer<const VoidAllocator>::type boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::const_allocator_pointer
template<class T, class VoidAllocator, class Deleter>
typedef boost::intrusive:: pointer_traits<typename VoidAllocator::pointer>::template rebind_pointer<const Deleter>::type boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::const_deleter_pointer
template<class T, class VoidAllocator, class Deleter>
typedef ipcdetail::add_reference<const value_type>::type boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::const_reference
template<class T, class VoidAllocator, class Deleter>
typedef T boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::element_type
template<class T, class VoidAllocator, class Deleter>
typedef boost::intrusive:: pointer_traits<typename VoidAllocator::pointer>::template rebind_pointer<T>::type boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::pointer
template<class T, class VoidAllocator, class Deleter>
typedef ipcdetail::add_reference<value_type>::type boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::reference
template<class T, class VoidAllocator, class Deleter>
typedef void(this_type::* boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::unspecified_bool_type)() const
template<class T, class VoidAllocator, class Deleter>
typedef T boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::value_type

Constructor & Destructor Documentation

template<class T, class VoidAllocator, class Deleter>
boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::shared_ptr ( )
inline

Constructs an empty shared_ptr.

Use_count() == 0 && get()== 0.

template<class T, class VoidAllocator, class Deleter>
boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::shared_ptr ( const pointer p,
const VoidAllocator &  a = VoidAllocator(),
const Deleter &  d = Deleter() 
)
inlineexplicit

Constructs a shared_ptr that owns the pointer p.

Auxiliary data will be allocated with a copy of a and the object will be deleted with a copy of d. Requirements: Deleter and A's copy constructor must not throw.

References boost::BOOST_STATIC_ASSERT(), boost::interprocess::to_raw_pointer(), boost::detail::type, and boost::program_options::value().

template<class T, class VoidAllocator, class Deleter>
boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::shared_ptr ( const shared_ptr< T, VoidAllocator, Deleter > &  r)
inline

Copy constructs a shared_ptr.

If r is empty, constructs an empty shared_ptr. Otherwise, constructs a shared_ptr that shares ownership with r. Never throws.

template<class T, class VoidAllocator, class Deleter>
boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::shared_ptr ( const shared_ptr< T, VoidAllocator, Deleter > &  other,
const pointer p 
)
inline

Constructs a shared_ptr that shares ownership with other and stores p.

Postconditions: get() == p && use_count() == r.use_count(). Throws: nothing.

template<class T, class VoidAllocator, class Deleter>
template<class Y >
boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::shared_ptr ( shared_ptr< Y, VoidAllocator, Deleter > const &  r)
inline

If r is empty, constructs an empty shared_ptr.

Otherwise, constructs a shared_ptr that shares ownership with r. Never throws.

template<class T, class VoidAllocator, class Deleter>
template<class Y >
boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::shared_ptr ( weak_ptr< Y, VoidAllocator, Deleter > const &  r)
inlineexplicit

Constructs a shared_ptr that shares ownership with r and stores a copy of the pointer stored in r.

template<class T, class VoidAllocator, class Deleter>
boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::shared_ptr ( BOOST_RV_REF(shared_ptr< T, VoidAllocator, Deleter >)  other)
inlineexplicit

Move-Constructs a shared_ptr that takes ownership of other resource and other is put in default-constructed state.

Throws: nothing.

References boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::swap().

template<class T, class VoidAllocator, class Deleter>
template<class Y >
boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::shared_ptr ( shared_ptr< Y, VoidAllocator, Deleter > const &  r,
ipcdetail::static_cast_tag   
)
inline
template<class T, class VoidAllocator, class Deleter>
template<class Y >
boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::shared_ptr ( shared_ptr< Y, VoidAllocator, Deleter > const &  r,
ipcdetail::const_cast_tag   
)
inline
template<class T, class VoidAllocator, class Deleter>
template<class Y >
boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::shared_ptr ( shared_ptr< Y, VoidAllocator, Deleter > const &  r,
ipcdetail::dynamic_cast_tag   
)
inline

Member Function Documentation

template<class T, class VoidAllocator, class Deleter>
template<class T2 , class A2 , class Deleter2 >
bool boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::_internal_less ( shared_ptr< T2, A2, Deleter2 > const &  rhs) const
inline
template<class T, class VoidAllocator, class Deleter>
const_deleter_pointer boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::get_deleter ( ) const
inline
template<class T, class VoidAllocator, class Deleter>
boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::operator unspecified_bool_type ( ) const
inline
template<class T, class VoidAllocator, class Deleter>
bool boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::operator! ( ) const
inline

Not operator.

Returns true if this->get() != 0, false otherwise

template<class T, class VoidAllocator, class Deleter>
reference boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::operator* ( ) const
inline

Returns a reference to the pointed type.

References BOOST_ASSERT.

template<class T, class VoidAllocator, class Deleter>
pointer boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::operator-> ( ) const
inline

Returns the pointer pointing to the owned object.

References BOOST_ASSERT.

template<class T, class VoidAllocator, class Deleter>
template<class Y >
shared_ptr& boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::operator= ( shared_ptr< Y, VoidAllocator, Deleter > const &  r)
inline

Equivalent to shared_ptr(r).swap(*this).

Never throws

template<class T, class VoidAllocator, class Deleter>
shared_ptr& boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::operator= ( BOOST_COPY_ASSIGN_REF(shared_ptr< T, VoidAllocator, Deleter >)  r)
inline

Equivalent to shared_ptr(r).swap(*this).

Never throws

template<class T, class VoidAllocator, class Deleter>
shared_ptr& boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::operator= ( BOOST_RV_REF(shared_ptr< T, VoidAllocator, Deleter >)  other)
inline

Move-assignment.

Equivalent to shared_ptr(other).swap(*this). Never throws

References boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::swap().

template<class T, class VoidAllocator, class Deleter>
void boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::reset ( )
inline

This is equivalent to: this_type().swap(*this);.

template<class T, class VoidAllocator, class Deleter>
template<class Pointer >
void boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::reset ( const Pointer &  p,
const VoidAllocator &  a = VoidAllocator(),
const Deleter &  d = Deleter() 
)
inline

This is equivalent to: this_type(p, a, d).swap(*this);.

References boost::a, boost::BOOST_STATIC_ASSERT(), boost::detail::type, and boost::program_options::value().

template<class T, class VoidAllocator, class Deleter>
template<class Y >
void boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::reset ( shared_ptr< Y, VoidAllocator, Deleter > const &  r,
const pointer p 
)
inline
template<class T, class VoidAllocator, class Deleter>
void boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::swap ( shared_ptr< T, VoidAllocator, Deleter > &  other)
inline
template<class T, class VoidAllocator, class Deleter>
bool boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::unique ( void  ) const
inline

Returns use_count() == 1.

unique() might be faster than use_count()

template<class T, class VoidAllocator, class Deleter>
void boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::unspecified_bool_type_func ( ) const
inline
template<class T, class VoidAllocator, class Deleter>
long boost::interprocess::shared_ptr< T, VoidAllocator, Deleter >::use_count ( ) const
inline

Returns the number of shared_ptr objects, *this included, that share ownership with *this, or an unspecified nonnegative value when *this is empty.

use_count() is not necessarily efficient. Use only for debugging and testing purposes, not for production code.

Friends And Related Function Documentation

template<class T, class VoidAllocator, class Deleter>
template<class T2 , class A2 , class Deleter2 >
friend class shared_ptr
friend
template<class T, class VoidAllocator, class Deleter>
template<class T2 , class A2 , class Deleter2 >
friend class weak_ptr
friend

The documentation for this class was generated from the following files: