BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsl::shared_ptr< ELEMENT_TYPE > Class Template Reference

#include <bslstl_sharedptr.h>

Public Types

typedef bsl::remove_extent< ELEMENT_TYPE >::type element_type
 
typedef weak_ptr< ELEMENT_TYPE > weak_type
 

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (shared_ptr< ELEMENT_TYPE >, bsl::is_nothrow_move_constructible)
 
BSLS_KEYWORD_CONSTEXPR shared_ptr () BSLS_KEYWORD_NOEXCEPT
 
BSLS_KEYWORD_CONSTEXPR shared_ptr (bsl::nullptr_t) BSLS_KEYWORD_NOEXCEPT
 
template<class CONVERTIBLE_TYPE BSLSTL_SHAREDPTR_DECLARE_IF_CONVERTIBLE>
 shared_ptr (CONVERTIBLE_TYPE *ptr)
 
template<class CONVERTIBLE_TYPE BSLSTL_SHAREDPTR_DECLARE_IF_CONVERTIBLE>
 shared_ptr (CONVERTIBLE_TYPE *ptr, BloombergLP::bslma::Allocator *basicAllocator)
 
 shared_ptr (element_type *ptr, BloombergLP::bslma::SharedPtrRep *rep)
 
 shared_ptr (ELEMENT_TYPE *ptr, BloombergLP::bslma::SharedPtrRep *rep, BloombergLP::bslstl::SharedPtr_RepFromExistingSharedPtr)
 
template<class CONVERTIBLE_TYPE , class DELETER BSLSTL_SHAREDPTR_DECLARE_IF_CONVERTIBLE BSLSTL_SHAREDPTR_DECLARE_IF_DELETER>
 shared_ptr (CONVERTIBLE_TYPE *ptr, DELETER *deleter)
 
template<class CONVERTIBLE_TYPE , class DELETER BSLSTL_SHAREDPTR_DECLARE_IF_CONVERTIBLE BSLSTL_SHAREDPTR_DECLARE_IF_DELETER>
 shared_ptr (CONVERTIBLE_TYPE *ptr, DELETER deleter, BloombergLP::bslma::Allocator *basicAllocator=0)
 
template<class CONVERTIBLE_TYPE , class DELETER , class ALLOCATOR BSLSTL_SHAREDPTR_DECLARE_IF_CONVERTIBLE BSLSTL_SHAREDPTR_DECLARE_IF_DELETER>
 shared_ptr (CONVERTIBLE_TYPE *ptr, DELETER deleter, ALLOCATOR basicAllocator, typename ALLOCATOR::value_type *=0)
 
 shared_ptr (nullptr_t nullPointerLiteral, BloombergLP::bslma::Allocator *basicAllocator)
 
template<class DELETER BSLSTL_SHAREDPTR_DECLARE_IF_NULLPTR_DELETER>
 shared_ptr (nullptr_t nullPointerLiteral, DELETER deleter, BloombergLP::bslma::Allocator *basicAllocator=0)
 
template<class DELETER , class ALLOCATOR BSLSTL_SHAREDPTR_DECLARE_IF_NULLPTR_DELETER>
 shared_ptr (nullptr_t nullPointerLiteral, DELETER deleter, ALLOCATOR basicAllocator, typename ALLOCATOR::value_type *=0)
 
template<class CONVERTIBLE_TYPE BSLSTL_SHAREDPTR_DECLARE_IF_CONVERTIBLE>
 shared_ptr (BloombergLP::bslma::ManagedPtr< CONVERTIBLE_TYPE > managedPtr, BloombergLP::bslma::Allocator *basicAllocator=0)
 
template<class ANY_TYPE >
 shared_ptr (const shared_ptr< ANY_TYPE > &source, ELEMENT_TYPE *object) BSLS_KEYWORD_NOEXCEPT
 
template<class COMPATIBLE_TYPE BSLSTL_SHAREDPTR_DECLARE_IF_COMPATIBLE>
 shared_ptr (const shared_ptr< COMPATIBLE_TYPE > &other) BSLS_KEYWORD_NOEXCEPT
 
 shared_ptr (const shared_ptr &original) BSLS_KEYWORD_NOEXCEPT
 
 shared_ptr (BloombergLP::bslmf::MovableRef< shared_ptr > original) BSLS_KEYWORD_NOEXCEPT
 
template<class COMPATIBLE_TYPE BSLSTL_SHAREDPTR_DECLARE_IF_COMPATIBLE>
 shared_ptr (BloombergLP::bslmf::MovableRef< shared_ptr< COMPATIBLE_TYPE > > other) BSLS_KEYWORD_NOEXCEPT
 
template<class COMPATIBLE_TYPE BSLSTL_SHAREDPTR_DECLARE_IF_COMPATIBLE>
 shared_ptr (const weak_ptr< COMPATIBLE_TYPE > &ptr)
 
template<class COMPATIBLE_TYPE BSLSTL_SHAREDPTR_DECLARE_IF_COMPATIBLE>
 shared_ptr (BloombergLP::bslmf::MovableRef< weak_ptr< COMPATIBLE_TYPE > > ptr)
 
 ~shared_ptr ()
 
shared_ptroperator= (const shared_ptr &rhs) BSLS_KEYWORD_NOEXCEPT
 
shared_ptroperator= (BloombergLP::bslmf::MovableRef< shared_ptr > rhs) BSLS_KEYWORD_NOEXCEPT
 
template<class COMPATIBLE_TYPE >
enable_if< is_convertible< COMPATIBLE_TYPE *, ELEMENT_TYPE * >::value, shared_ptr & >::type operator= (const shared_ptr< COMPATIBLE_TYPE > &rhs) BSLS_KEYWORD_NOEXCEPT
 
template<class COMPATIBLE_TYPE >
enable_if< is_convertible< COMPATIBLE_TYPE *, ELEMENT_TYPE * >::value, shared_ptr & >::type operator= (BloombergLP::bslmf::MovableRef< shared_ptr< COMPATIBLE_TYPE > > rhs) BSLS_KEYWORD_NOEXCEPT
 
template<class COMPATIBLE_TYPE >
enable_if< is_convertible< COMPATIBLE_TYPE *, ELEMENT_TYPE * >::value, shared_ptr & >::type operator= (BloombergLP::bslma::ManagedPtr< COMPATIBLE_TYPE > rhs)
 
void reset () BSLS_KEYWORD_NOEXCEPT
 
template<class COMPATIBLE_TYPE >
enable_if< is_convertible< COMPATIBLE_TYPE *, ELEMENT_TYPE * >::value >::type reset (COMPATIBLE_TYPE *ptr)
 
template<class COMPATIBLE_TYPE , class DELETER >
enable_if< is_convertible< COMPATIBLE_TYPE *, ELEMENT_TYPE * >::value >::type reset (COMPATIBLE_TYPE *ptr, DELETER deleter)
 
template<class COMPATIBLE_TYPE , class DELETER , class ALLOCATOR >
enable_if< is_convertible< COMPATIBLE_TYPE *, ELEMENT_TYPE * >::value >::type reset (COMPATIBLE_TYPE *ptr, DELETER deleter, ALLOCATOR basicAllocator)
 
template<class ANY_TYPE >
void reset (const shared_ptr< ANY_TYPE > &source, ELEMENT_TYPE *ptr)
 
void swap (shared_ptr &other) BSLS_KEYWORD_NOEXCEPT
 
void createInplace ()
 
template<class... ARGS>
void createInplace (BloombergLP::bslma::Allocator *basicAllocator, ARGS &&... args)
 
template<class ANY_TYPE >
void loadAlias (const shared_ptr< ANY_TYPE > &source, ELEMENT_TYPE *object)
 
pair< element_type *, BloombergLP::bslma::SharedPtrRep * > release () BSLS_KEYWORD_NOEXCEPT
 
void clear () BSLS_KEYWORD_NOEXCEPT
 
template<class COMPATIBLE_TYPE >
void load (COMPATIBLE_TYPE *ptr)
 
template<class COMPATIBLE_TYPE >
void load (COMPATIBLE_TYPE *ptr, BloombergLP::bslma::Allocator *basicAllocator)
 
template<class COMPATIBLE_TYPE , class DELETER >
void load (COMPATIBLE_TYPE *ptr, const DELETER &deleter, BloombergLP::bslma::Allocator *basicAllocator)
 
 operator BoolType () const BSLS_KEYWORD_NOEXCEPT
 
add_lvalue_reference< ELEMENT_TYPE >::type operator* () const BSLS_KEYWORD_NOEXCEPT
 
ELEMENT_TYPE * operator-> () const BSLS_KEYWORD_NOEXCEPT
 
element_typeget () const BSLS_KEYWORD_NOEXCEPT
 
add_lvalue_reference< element_type >::type operator[] (ptrdiff_t index) const
 
template<class ANY_TYPE >
bool owner_before (const shared_ptr< ANY_TYPE > &other) const BSLS_KEYWORD_NOEXCEPT
 
template<class ANY_TYPE >
bool owner_before (const weak_ptr< ANY_TYPE > &other) const BSLS_KEYWORD_NOEXCEPT
 
template<class ANY_TYPE >
bool owner_equal (const shared_ptr< ANY_TYPE > &other) const BSLS_KEYWORD_NOEXCEPT
 
template<class ANY_TYPE >
bool owner_equal (const weak_ptr< ANY_TYPE > &other) const BSLS_KEYWORD_NOEXCEPT
 
size_t owner_hash () const BSLS_KEYWORD_NOEXCEPT
 
 BSLS_DEPRECATE_FEATURE ("bsl", "deprecated_cpp17_standard_library_features", "do not use") bool unique() const BSLS_KEYWORD_NOEXCEPT
 
long use_count () const BSLS_KEYWORD_NOEXCEPT
 
BloombergLP::bslma::ManagedPtr< ELEMENT_TYPE > managedPtr () const
 
BloombergLP::bslma::SharedPtrRep * rep () const BSLS_KEYWORD_NOEXCEPT
 
int numReferences () const BSLS_KEYWORD_NOEXCEPT
 
element_typeptr () const BSLS_KEYWORD_NOEXCEPT
 
template<class ELEMENT_TYPE >
 shared_ptr (typename shared_ptr< ELEMENT_TYPE >::element_type *ptr, BloombergLP::bslma::SharedPtrRep *rep)
 
template<class CONVERTIBLE_TYPE , class DISPATCH BSLSTL_SHAREDPTR_DEFINE_IF_CONVERTIBLE BSLSTL_SHAREDPTR_DEFINE_IF_DELETER>
 shared_ptr (CONVERTIBLE_TYPE *ptr, DISPATCH *dispatch)
 

Friends

template<class COMPATIBLE_TYPE >
class shared_ptr
 
struct BloombergLP::bslstl::SharedPtr_ImpUtil
 

Detailed Description

template<class ELEMENT_TYPE>
class bsl::shared_ptr< ELEMENT_TYPE >

This class provides a thread-safe reference-counted "smart pointer" to support "shared ownership" of objects: a shared pointer ensures that the shared object is destroyed, using the appropriate deletion method, only when there are no shared references to it. The object (of template parameter type ELEMENT_TYPE) referred to by a shared pointer may be accessed directly using the -> operator, or the dereference operator (operator *) can be used to obtain a reference to that object.

Note that the object referred to by a shared pointer representation is usually the same as the object referred to by that shared pointer (of the same ELEMENT_TYPE), but this need not always be true in the presence of conversions or "aliasing": the object referred to (of template parameter type ELEMENT_TYPE) by the shared pointer may differ from the object of type COMPATIBLE_TYPE (see the "Aliasing" section in the component-level documentation) referred to by the shared pointer representation.

More generally, this class supports a complete set of in-*core* pointer semantic operations.

See bslstl_sharedptr

Member Typedef Documentation

◆ element_type

template<class ELEMENT_TYPE >
typedef bsl::remove_extent<ELEMENT_TYPE>::type bsl::shared_ptr< ELEMENT_TYPE >::element_type

For shared pointers to non-array types, element_type is an alias to the ELEMENT_TYPE template parameter. Otherwise, it is an alias to the type contained in the array.

◆ weak_type

template<class ELEMENT_TYPE >
typedef weak_ptr<ELEMENT_TYPE> bsl::shared_ptr< ELEMENT_TYPE >::weak_type

weak_type is an alias to a weak pointer with the same element type as this shared_ptr.

Constructor & Destructor Documentation

◆ shared_ptr() [1/22]

template<class ELEMENT_TYPE >
BSLS_KEYWORD_CONSTEXPR bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( )
inline

Create an empty shared pointer, i.e., a shared pointer with no representation that does not refer to any object and has no deleter.

◆ shared_ptr() [2/22]

template<class ELEMENT_TYPE >
BSLS_KEYWORD_CONSTEXPR bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( bsl::nullptr_t  )
inline

Create an empty shared pointer, i.e., a shared pointer with no representation that does not refer to any object and has no deleter.

◆ shared_ptr() [3/22]

template<class ELEMENT_TYPE >
template<class CONVERTIBLE_TYPE BSLSTL_SHAREDPTR_DEFINE_IF_CONVERTIBLE>
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( CONVERTIBLE_TYPE *  ptr)
inlineexplicit

Create a shared pointer that manages a modifiable object of (template parameter) type CONVERTIBLE_TYPE and refers to the specified (ELEMENT_TYPE *)ptr. The currently installed default allocator is used to allocate and deallocate the internal representation of the shared pointer. When all references have been released, the object pointed to by the managed pointer will be destroyed by a call to delete ptr. If CONVERTIBLE_TYPE * is not implicitly convertible to ELEMENT_TYPE *, then a compiler diagnostic will be emitted indicating the error. If ptr is 0, then this shared pointer will still allocate an internal representation to share ownership of that empty state, which will be reclaimed when the last reference is destroyed. If an exception is thrown allocating storage for the representation, then delete ptr will be called. Note that if ptr is a null-pointer constant, the compiler will actually select the shared_ptr(bsl::nullptr_t) constructor, resulting in an empty shared pointer.

◆ shared_ptr() [4/22]

template<class ELEMENT_TYPE >
template<class CONVERTIBLE_TYPE BSLSTL_SHAREDPTR_DEFINE_IF_CONVERTIBLE>
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( CONVERTIBLE_TYPE *  ptr,
BloombergLP::bslma::Allocator *  basicAllocator 
)
inline

Create a shared pointer that manages a modifiable object of (template parameter) type CONVERTIBLE_TYPE and refers to the specified ptr cast to a pointer to the (template parameter) type ELEMENT_TYPE. If the specified basicAllocator is not 0, then basicAllocator is used to allocate and deallocate the internal representation of the shared pointer and to destroy the shared object when all references have been released; otherwise, the currently installed default allocator is used. If CONVERTIBLE_TYPE * is not implicitly convertible to ELEMENT_TYPE *, then a compiler diagnostic will be emitted indicating the error. If ptr is 0, then this shared pointer will still allocate an internal representation to share ownership of that empty state, which will be reclaimed when the last reference is destroyed. Note that if ptr is a null-pointer constant, the compiler will actually select the shared_ptr(bsl::nullptr_t, BloombergLP::bslma::Allocator *) constructor, resulting in an empty shared pointer. Note that if basicAllocator is a pointer to a class derived from bslma::Allocator, the compiler will actually select the following (more general) constructor that has the same behavior:

template <class CONVERTIBLE_TYPE, class DELETER>
shared_ptr(CONVERTIBLE_TYPE *ptr, DELETER * deleter);
element_type * ptr() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_sharedptr.h:5688
friend class shared_ptr
Definition bslstl_sharedptr.h:1867

◆ shared_ptr() [5/22]

template<class ELEMENT_TYPE >
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( element_type ptr,
BloombergLP::bslma::SharedPtrRep *  rep 
)

Create a shared pointer that takes ownership of the specified rep and refers to the modifiable object at the specified ptr address. The number of references to rep is NOT incremented. Note that if rep is a pointer to a class derived from BloombergLP::bslma::SharedPtrRep, the compiler will actually select the following (more general) constructor that has the same behavior:

template <class COMPATIBLE_TYPE, class DELETER>
shared_ptr(COMPATIBLE_TYPE *ptr, DELETER * deleter);

◆ shared_ptr() [6/22]

template<class ELEMENT_TYPE >
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( ELEMENT_TYPE *  ptr,
BloombergLP::bslma::SharedPtrRep *  rep,
BloombergLP::bslstl::SharedPtr_RepFromExistingSharedPtr   
)
inline

Create a shared pointer that takes ownership of the specified rep and refers to the modifiable object at the specified ptr address. The number of references to rep is NOT incremented. The behavior is undefined unless rep was previously obtained from an existing shared_ptr, rep->disposeObject has not been called, and rep->numReferences() > 0. Note that this constructor is intended for use by weak_ptr::lock, and it would be surprising to find another client. This solves an obscure problem that arises from unusual use of classes derived from enable_shared_from_this. Further note that the caller is responsible for incrementing the numReferences count prior to calling this constructor, in order to maintain a consistent reference count when this shared_ptr object releases the shared object from its management.

◆ shared_ptr() [7/22]

template<class ELEMENT_TYPE >
template<class CONVERTIBLE_TYPE , class DELETER BSLSTL_SHAREDPTR_DECLARE_IF_CONVERTIBLE BSLSTL_SHAREDPTR_DECLARE_IF_DELETER>
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( CONVERTIBLE_TYPE *  ptr,
DELETER *  deleter 
)

Create a shared pointer that manages a modifiable object of (template parameter) type CONVERTIBLE_TYPE, refers to the specified ptr cast to a pointer to the (template parameter) type ELEMENT_TYPE, and uses the specified deleter to delete the shared object when all references have been released. Use the currently installed default allocator to allocate and deallocate the internal representation of the shared pointer, unless DELETER is a class derived from either bslma::Allocator or bslma::SharedPtrRep; if DELETER is a class derived from bslma::allocator, create a shared pointer as if calling the constructor:

template <class CONVERTIBLE_TYPE>
shared_ptr(CONVERTIBLE_TYPE *ptr,
BloombergLP::bslma::Allocator *basicAllocator);

If DELETER is a class derived from bslma::SharedPtrRep, create a shared pointer as if calling the constructor:

shared_ptr(ELEMENT_TYPE *ptr,
BloombergLP::bslma::SharedPtrRep *rep);
BloombergLP::bslma::SharedPtrRep * rep() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_sharedptr.h:5670

If DELETER does not derive from either bslma::Allocator or BloombergLP::bslma::SharedPtrRep, then deleter shall be a pointer to a factory object that exposes a member function that can be invoked as deleteObject(ptr) that will be called to destroy the object at the ptr address (i.e., deleter->deleteObject(ptr) will be called to delete the shared object). (See the "Deleters" section in the component-level documentation.) If CONVERTIBLE_TYPE * is not implicitly convertible to ELEMENT_TYPE *, then a compiler diagnostic will be emitted indicating the error. If ptr is 0, then the null pointer will be reference counted, and the deleter will be called when the last reference is destroyed. If an exception is thrown when allocating storage for the internal representation, then deleter(ptr) will be called. Note that this method is a BDE extension and not part of the C++ standard interface.

◆ shared_ptr() [8/22]

template<class ELEMENT_TYPE >
template<class CONVERTIBLE_TYPE , class DELETER BSLSTL_SHAREDPTR_DEFINE_IF_CONVERTIBLE BSLSTL_SHAREDPTR_DEFINE_IF_DELETER>
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( CONVERTIBLE_TYPE *  ptr,
DELETER  deleter,
BloombergLP::bslma::Allocator *  basicAllocator = 0 
)
inline

Create a shared pointer that manages a modifiable object of (template parameter) type CONVERTIBLE_TYPE, refers to the specified (ELEMENT_TYPE *)ptr, and uses the specified deleter to delete the shared object when all references have been released. Optionally specify a basicAllocator to allocate and deallocate the internal representation of the shared pointer (including a copy of deleter). If basicAllocator is 0, the currently installed default allocator is used. DELETER shall be either a function pointer or a "factory" deleter that may be invoked to destroy the object referred to by a single argument of type CONVERTIBLE_TYPE * (i.e., deleter(ptr) or deleter->deleteObject(ptr) will be called to destroy the shared object). (See the "Deleters" section in the component-level documentation.) If CONVERTIBLE_TYPE * is not implicitly convertible to ELEMENT_TYPE *, then this constructor will not be selected by overload resolution. If ptr is 0, then the null pointer will be reference counted, and deleter(ptr) will be called when the last reference is destroyed. If an exception is thrown when allocating storage for the internal representation, then deleter(ptr) will be called. The behavior is undefined unless the constructor making a copy of deleter does not throw an exception.

◆ shared_ptr() [9/22]

template<class ELEMENT_TYPE >
template<class CONVERTIBLE_TYPE , class DELETER , class ALLOCATOR BSLSTL_SHAREDPTR_DEFINE_IF_CONVERTIBLE BSLSTL_SHAREDPTR_DEFINE_IF_DELETER>
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( CONVERTIBLE_TYPE *  ptr,
DELETER  deleter,
ALLOCATOR  basicAllocator,
typename ALLOCATOR::value_type *  = 0 
)
inline

Create a shared pointer that manages a modifiable object of (template parameter) type CONVERTIBLE_TYPE, refers to the specified ptr cast to a pointer to the (template parameter) type ELEMENT_TYPE, and uses the specified deleter to delete the shared object when all references have been released. Use the specified basicAllocator to allocate and deallocate the internal representation of the shared pointer (including a copy of the deleter). The (template parameter) type DELETER shall be either a function pointer or a function-like deleter that may be invoked to destroy the object referred to by a single argument of type CONVERTIBLE_TYPE * (i.e., deleter(ptr) will be called to destroy the shared object). (See the "Deleters" section in the component- level documentation.) The (template parameter) type ALLOCATOR shall satisfy the Allocator requirements of the C++ standard (C++11 17.6.3.5, [allocator.requirements]). If CONVERTIBLE_TYPE * is not implicitly convertible to ELEMENT_TYPE *, then a compiler diagnostic will be emitted indicating the error. If ptr is 0, then the null pointer will be reference counted, and deleter(ptr) will be called when the last reference is destroyed. If an exception is thrown when allocating storage for the internal representation, then deleter(ptr) will be called. The behavior is undefined unless the constructor making a copy of deleter does not throw an exception. Note that the final dummy parameter is a simple SFINAE check that the (template parameter) ALLOCATOR type probably satisfies the standard allocator requirements; in particular, it will not match pointer types, so any pointers to bslma::Allocator derived classes will dispatch to the constructor above this, and not be greedily matched to a generic type parameter.

◆ shared_ptr() [10/22]

template<class ELEMENT_TYPE >
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( nullptr_t  nullPointerLiteral,
BloombergLP::bslma::Allocator *  basicAllocator 
)
inline

Create an empty shared pointer. The specified nullPointerLiteral and basicAllocator are not used. Note that use of this constructor is equivalent to calling the default constructor.

◆ shared_ptr() [11/22]

template<class ELEMENT_TYPE >
template<class DELETER BSLSTL_SHAREDPTR_DEFINE_IF_NULLPTR_DELETER>
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( nullptr_t  nullPointerLiteral,
DELETER  deleter,
BloombergLP::bslma::Allocator *  basicAllocator = 0 
)
inline

Create a shared pointer that reference-counts the null pointer, and calls the specified deleter with a null pointer (i.e., invokes deleter((ELEMENT_TYPE *)0)) when the last shared reference is destroyed. The specified nullPointerLiteral is not used. Optionally specify a basicAllocator to allocate and deallocate the internal representation of the shared pointer (including a copy of deleter). If basicAllocator is 0, the currently installed default allocator is used. If an exception is thrown when allocating storage for the internal representation, then deleter((ELEMENT_TYPE *)0) will be called. The behavior is undefined unless deleter can be called with a null pointer, and unless the constructor making a copy of deleter does not throw an exception.

◆ shared_ptr() [12/22]

template<class ELEMENT_TYPE >
template<class DELETER , class ALLOCATOR BSLSTL_SHAREDPTR_DEFINE_IF_NULLPTR_DELETER>
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( nullptr_t  nullPointerLiteral,
DELETER  deleter,
ALLOCATOR  basicAllocator,
typename ALLOCATOR::value_type *  = 0 
)
inline

Create a shared pointer that reference-counts the null pointer, calls the specified deleter with a null pointer (i.e., invokes deleter((ELEMENT_TYPE *)0)) when the last shared reference is destroyed, and uses the specified basicAllocator to allocate and deallocate the internal representation of the shared pointer (including a copy of the deleter). The (template parameter) type DELETER shall be either a function pointer or a function-like deleter (See the "Deleters" section in the component- level documentation). The (template parameter) type ALLOCATOR shall satisfy the Allocator requirements of the C++ standard (C++11 17.6.3.5, [allocator.requirements]). The specified nullPointerLiteral is not used. If an exception is thrown when allocating storage for the internal representation, then deleter((ELEMENT_TYPE *)0) will be called. The behavior is undefined unless deleter can be called with a null pointer, and unless the constructor making a copy of deleter does not throw an exception. Note that the final dummy parameter is a simple SFINAE check that the ALLOCATOR type probably satisfies the standard allocator requirements; in particular, it will not match pointer types, so any pointers to bslma::Allocator derived classes will dispatch to the constructor above this, and not be greedily matched to a generic type parameter.

◆ shared_ptr() [13/22]

template<class ELEMENT_TYPE >
template<class CONVERTIBLE_TYPE BSLSTL_SHAREDPTR_DEFINE_IF_CONVERTIBLE>
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( BloombergLP::bslma::ManagedPtr< CONVERTIBLE_TYPE >  managedPtr,
BloombergLP::bslma::Allocator *  basicAllocator = 0 
)

Create a shared pointer that takes over the management of the modifiable object (if any) previously managed by the specified managedPtr to the (template parameter) type CONVERTIBLE_TYPE, and that refers to (ELEMENT_TYPE *)managedPtr.ptr(). The deleter used in the managedPtr will be used to destroy the shared object when all references have been released. Optionally specify a basicAllocator used to allocate and deallocate the internal representation of the shared pointer. If basicAllocator is 0, the currently installed default allocator is used. If CONVERTIBLE_TYPE * is not implicitly convertible to ELEMENT_TYPE *, then a compiler diagnostic will be emitted indicating the error. Note that if managedPtr is empty, then an empty shared pointer is created and basicAllocator is ignored. Also note that if managedPtr owns a reference to another shared object (due to a previous call to shared_ptr<T>::managedPtr) then no memory will be allocated, and this shared_ptr will adopt the ManagedPtrs ownership of that shared object.

◆ shared_ptr() [14/22]

template<class ELEMENT_TYPE >
template<class ANY_TYPE >
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( const shared_ptr< ANY_TYPE > &  source,
ELEMENT_TYPE *  object 
)

Create a shared pointer that manages the same modifiable object (if any) as the specified source shared pointer to the (template parameter) type ANY_TYPE, and that refers to the modifiable object at the specified object address. The resulting shared pointer is known as an "alias" of source. Note that typically the objects referred to by source and object have identical lifetimes (e.g., one might be a part of the other), so that the deleter for source will destroy them both, but they do not necessarily have the same type. Also note that if source is empty, then an empty shared pointer is created, even if object is not null (in which case this empty shared pointer will refer to the same object as object). Also note that if object is null and source is not empty, then a reference-counted null pointer alias will be created.

◆ shared_ptr() [15/22]

template<class ELEMENT_TYPE >
template<class COMPATIBLE_TYPE BSLSTL_SHAREDPTR_DEFINE_IF_COMPATIBLE>
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( const shared_ptr< COMPATIBLE_TYPE > &  other)

Create a shared pointer that manages the same modifiable object (if any) as the specified other shared pointer to the (template parameter) type COMPATIBLE_TYPE, uses the same deleter as other to destroy the shared object, and refers to (ELEMENT_TYPE*)other.get(). If COMPATIBLE_TYPE * is not implicitly convertible to ELEMENT_TYPE *, then a compiler diagnostic will be emitted indicating the error. Note that if other is empty, then an empty shared pointer is created, which may still point to an un-managed object if other were constructed through an aliasing constructor.

◆ shared_ptr() [16/22]

template<class ELEMENT_TYPE >
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( const shared_ptr< ELEMENT_TYPE > &  original)

Create a shared pointer that refers to and manages the same object (if any) as the specified original shared pointer, and uses the same deleter as original to destroy the shared object. Note that if original is empty, then an empty shared pointer is created, which may still point to an un-managed object if original were constructed through an aliasing constructor.

◆ shared_ptr() [17/22]

template<class ELEMENT_TYPE >
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( BloombergLP::bslmf::MovableRef< shared_ptr< ELEMENT_TYPE > >  original)

Create a shared pointer that refers to and assumes management of the same object (if any) as the specified original shared pointer, using the same deleter as original to destroy the shared object, and reset original to an empty state, not pointing to any object. Note that if original is empty, then an empty shared pointer is created, which may still point to an un-managed object if original were constructed through an aliasing constructor.

◆ shared_ptr() [18/22]

template<class ELEMENT_TYPE >
template<class COMPATIBLE_TYPE BSLSTL_SHAREDPTR_DEFINE_IF_COMPATIBLE>
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( BloombergLP::bslmf::MovableRef< shared_ptr< COMPATIBLE_TYPE > >  other)

Create a shared pointer that refers to and assumes management of the same object (if any) as the specified other shared pointer to the (template parameter) type COMPATIBLE_TYPE, using the same deleter as other to destroy the shared object, and refers to (ELEMENT_TYPE*)other.get(). If COMPATIBLE_TYPE * is not implicitly convertible to ELEMENT_TYPE *, then a compiler diagnostic will be emitted indicating the error. Note that if other is empty, then an empty shared pointer is created, which may still point to an un-managed object if other were constructed through an aliasing constructor.

◆ shared_ptr() [19/22]

template<class ELEMENT_TYPE >
template<class COMPATIBLE_TYPE BSLSTL_SHAREDPTR_DEFINE_IF_COMPATIBLE>
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( const weak_ptr< COMPATIBLE_TYPE > &  ptr)
explicit

Create a shared pointer that refers to and manages the same object as the specified ptr if ptr.expired() is false; otherwise, create a shared pointer in the empty state. Note that the referenced and managed objects may be different if ptr was created from a shared_ptr in an aliasing state.

◆ shared_ptr() [20/22]

template<class ELEMENT_TYPE >
template<class COMPATIBLE_TYPE BSLSTL_SHAREDPTR_DEFINE_IF_COMPATIBLE>
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( BloombergLP::bslmf::MovableRef< weak_ptr< COMPATIBLE_TYPE > >  ptr)
explicit

Create a shared pointer that refers to and manages the same object as the specified ptr if ptr.expired() is false; otherwise, create a shared pointer in the empty state. Note that the referenced and managed objects may be different if ptr was created from a shared_ptr in an aliasing state. Also note that this overloaded constructor is necessary only for C++03 compilers that rely on the BDE move-emulation type, bslmf::MovableRef; a C++11 compiler will pass rvalues directly to the constructor taking a const weak_ptr&, rendering this constructor redundant.

◆ ~shared_ptr()

template<class ELEMENT_TYPE >
bsl::shared_ptr< ELEMENT_TYPE >::~shared_ptr ( )

Destroy this shared pointer. If this shared pointer refers to a (possibly shared) object, then release the reference to that object, and destroy the shared object using its associated deleter if this shared pointer is the last reference to that object.

◆ shared_ptr() [21/22]

template<class ELEMENT_TYPE >
template<class ELEMENT_TYPE >
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( typename shared_ptr< ELEMENT_TYPE >::element_type ptr,
BloombergLP::bslma::SharedPtrRep *  rep 
)
inline

◆ shared_ptr() [22/22]

template<class ELEMENT_TYPE >
template<class CONVERTIBLE_TYPE , class DISPATCH BSLSTL_SHAREDPTR_DEFINE_IF_CONVERTIBLE BSLSTL_SHAREDPTR_DEFINE_IF_DELETER>
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( CONVERTIBLE_TYPE *  ptr,
DISPATCH *  dispatch 
)
inline

Member Function Documentation

◆ BSLMF_NESTED_TRAIT_DECLARATION()

template<class ELEMENT_TYPE >
bsl::shared_ptr< ELEMENT_TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( shared_ptr< ELEMENT_TYPE >  ,
bsl::is_nothrow_move_constructible   
)

◆ BSLS_DEPRECATE_FEATURE()

template<class ELEMENT_TYPE >
bsl::shared_ptr< ELEMENT_TYPE >::BSLS_DEPRECATE_FEATURE ( "bsl"  ,
"deprecated_cpp17_standard_library_features"  ,
"do not use"   
) const

Return true if this shared pointer is not empty and does not share ownership of the object it managed with any other shared pointer, and false otherwise. Note that a shared pointer with a custom deleter can refer to a null pointer without being empty, and so may be unique. Also note that the result of this function may not be reliable in a multi-threaded program, where a weak pointer may be locked on another thread.

DEPRECATED: This function is deprecated in C++17 because its correctness is not guaranteed since the value returned by the used use_count function is approximate.

◆ clear()

template<class ELEMENT_TYPE >
void bsl::shared_ptr< ELEMENT_TYPE >::clear ( )
inline

[DEPRECATED] Use reset instead.

Reset this shared pointer to the empty state. If this shared pointer is managing a (possibly shared) object, then release the reference to the shared object, calling the associated deleter to destroy the shared object if this shared pointer is the last reference. Note that the behavior of this method is the same as reset().

◆ createInplace() [1/2]

template<class ELEMENT_TYPE >
void bsl::shared_ptr< ELEMENT_TYPE >::createInplace ( )

Create "in-place" in a large enough contiguous memory region both an internal representation for this shared pointer and a default-constructed object of ELEMENT_TYPE, and make this shared pointer refer to the newly-created ELEMENT_TYPE object. The currently installed default allocator is used to supply memory. If an exception is thrown during allocation or construction of the ELEMENT_TYPE object, this shared pointer will be unchanged. Otherwise, if this shared pointer is already managing a (possibly shared) object, then release the shared reference to that shared object, and destroy it using its associated deleter if this shared pointer held the last shared reference to that object.

◆ createInplace() [2/2]

template<class ELEMENT_TYPE >
template<class... ARGS>
void bsl::shared_ptr< ELEMENT_TYPE >::createInplace ( BloombergLP::bslma::Allocator *  basicAllocator,
ARGS &&...  args 
)

Create "in-place" in a large enough contiguous memory region, using the specified basicAllocator to supply memory, both an internal representation for this shared pointer and an object of ELEMENT_TYPE using the ELEMENT_TYPE constructor that takes the specified args... arguments, and make this shared pointer refer to the newly-created ELEMENT_TYPE object. If an exception is thrown during the construction of the ELEMENT_TYPE object, this shared pointer will be unchanged. Otherwise, if this shared pointer is already managing a (possibly shared) object, then release the shared reference to that shared object, and destroy it using its associated deleter if this shared pointer held the last shared reference to that object. Note that the allocator argument is not implicitly passed to the constructor for ELEMENT_TYPE; to construct an object of ELEMENT_TYPE with an allocator, pass the allocator as one of the arguments (typically the last argument), or assign with a shared_ptr created using the standard allocate_shared function.

◆ get()

template<class ELEMENT_TYPE >
shared_ptr< ELEMENT_TYPE >::element_type * bsl::shared_ptr< ELEMENT_TYPE >::get ( ) const
inline

Return the address providing modifiable access to the object referred to by this shared pointer, or 0 if this shared pointer does not refer to an object.

◆ load() [1/3]

template<class ELEMENT_TYPE >
template<class COMPATIBLE_TYPE >
void bsl::shared_ptr< ELEMENT_TYPE >::load ( COMPATIBLE_TYPE *  ptr)
inline

[DEPRECATED] Use reset instead.

Modify this shared pointer to manage the modifiable object of the (template parameter) type COMPATIBLE_TYPE at the specified ptr address and to refer to (ELEMENT_TYPE *)ptr. If this shared pointer is already managing a (possibly shared) object, then, unless an exception is thrown allocating memory to manage ptr, release the reference to the shared object, calling the associated deleter to destroy the shared object if this shared pointer is the last reference. The currently installed default allocator is used to allocate the internal representation of this shared pointer, and the shared object will be destroyed by a call to delete ptr when all references have been released. If an exception is thrown allocating the internal representation, then delete ptr is called and this shared pointer retains ownership of its original object. If COMPATIBLE_TYPE* is not implicitly convertible to ELEMENT_TYPE*, then a compiler diagnostic will be emitted indicating the error. Note that if ptr is 0, then this shared pointer will still allocate an internal representation to share ownership of that empty state, which will be reclaimed when the last reference is destroyed. Also note also that the behavior of this method is the same as reset(ptr).

◆ load() [2/3]

template<class ELEMENT_TYPE >
template<class COMPATIBLE_TYPE >
void bsl::shared_ptr< ELEMENT_TYPE >::load ( COMPATIBLE_TYPE *  ptr,
BloombergLP::bslma::Allocator *  basicAllocator 
)
inline

[DEPRECATED] Use reset instead.

Modify this shared pointer to manage the modifiable object of the (template parameter) type COMPATIBLE_TYPE at the specified ptr address and to refer to (ELEMENT_TYPE *)ptr. If this shared pointer is already managing a (possibly shared) object, then, unless an exception is thrown allocating memory to manage ptr, release the reference to the shared object, calling the associated deleter to destroy the shared object if this shared pointer is the last reference. Use the specified basicAllocator to allocate the internal representation of this shared pointer and to destroy the shared object when all references have been released; if basicAllocator is 0, the currently installed default allocator is used. If an exception is thrown allocating the internal representation, then destroy *ptr with a call to alloc->deleteObject(ptr) where alloc is the chosen allocator, and this shared pointer retains ownership of its original object. If COMPATIBLE_TYPE * is not implicitly convertible to ELEMENT_TYPE *, then a compiler diagnostic will be emitted indicating the error. Note that if ptr is 0, then this shared pointer will still allocate an internal representation to share ownership of that empty state, which will be reclaimed when the last reference is destroyed. Also note that this function is logically equivalent to:

*this = shared_ptr<ELEMENT_TYPE>(ptr, basicAllocator);
Definition bslstl_sharedptr.h:1830

◆ load() [3/3]

template<class ELEMENT_TYPE >
template<class COMPATIBLE_TYPE , class DELETER >
void bsl::shared_ptr< ELEMENT_TYPE >::load ( COMPATIBLE_TYPE *  ptr,
const DELETER &  deleter,
BloombergLP::bslma::Allocator *  basicAllocator 
)
inline

[DEPRECATED] Use reset instead.

Modify this shared pointer to manage the modifiable object of the (template parameter) type COMPATIBLE_TYPE at the specified ptr address, refer to (ELEMENT_TYPE *)ptr and use the specified deleter to delete the shared object when all references have been released. Use the specified basicAllocator to allocate and deallocate the internal representation of the shared pointer. If basicAllocator is 0, the currently installed default allocator is used. If this shared pointer is already managing a (possibly shared) object, then, unless an exception is thrown creating storage to manage ptr, release the shared reference to that shared object, and destroy it using its associated deleter if this shared pointer held the last shared reference to that object. If DELETER is a reference type, then deleter is assumed to be a function-like deleter that may be invoked to destroy the object referred to by a single argument of type COMPATIBLE_TYPE * (i.e., deleter(ptr) will be called to destroy the shared object). If DELETER is a pointer type, then deleter is assumed to be a pointer to a factory object that exposes a member function that can be invoked as deleteObject(ptr) that will be called to destroy the object at the ptr address (i.e., deleter->deleteObject(ptr) will be called to delete the shared object). (See the "Deleters" section in the component-level documentation.) If an exception is thrown allocating the internal representation, then deleter(ptr) is called (or deleter->deleteObject(ptr) for factory-type deleters) and this shared pointer retains ownership of its original object. The behavior is undefined unless deleter(ptr) is a well-defined expression (or deleter->deleteObject(ptr) for factory-type deleters), and unless the copy constructor for deleter does not throw an exception. If COMPATIBLE_TYPE * is not implicitly convertible to ELEMENT_TYPE *, then a compiler diagnostic will be emitted indicating the error. Note that, for factory deleters, the deleter must remain valid until all references to ptr have been released. Also note that if ptr is 0, then an internal representation will still be allocated, and this shared pointer will share ownership of a copy of deleter. Further note that this function is logically equivalent to:

*this = shared_ptr<ELEMENT_TYPE>(ptr, deleter, basicAllocator);

◆ loadAlias()

template<class ELEMENT_TYPE >
template<class ANY_TYPE >
void bsl::shared_ptr< ELEMENT_TYPE >::loadAlias ( const shared_ptr< ANY_TYPE > &  source,
ELEMENT_TYPE *  object 
)

[DEPRECATED] Use reset instead.

Modify this shared pointer to manage the same modifiable object (if any) as the specified source shared pointer to the (template parameter) type ANY_TYPE, and refer to the modifiable object at the specified object address (i.e., make this shared pointer an "alias" of source). If this shared pointer is already managing a (possibly shared) object, then release the shared reference to that shared object, and destroy it using its associated deleter if this shared pointer held the last shared reference to that object. Note that typically the objects referred to by source and object have identical lifetimes (e.g., one might be a part of the other), so that the deleter for source will destroy them both, but they do not necessarily have the same type. Also note that if source is empty, then this shared pointer will be reset to an empty state, even if object is not null (in which case this empty shared pointer will refer to the same object as object). Also note that if object is null and source is not empty, then this shared pointer will be reset to a (reference-counted) null pointer alias. Also note that this function is logically equivalent to:

*this = shared_ptr<ELEMENT_TYPE>(source, object);

Further note that the behavior of this method is the same as reset(source, object).

◆ managedPtr()

template<class ELEMENT_TYPE >
BloombergLP::bslma::ManagedPtr< ELEMENT_TYPE > bsl::shared_ptr< ELEMENT_TYPE >::managedPtr ( ) const

Return a managed pointer that refers to the same object as this shared pointer. If this shared pointer is not empty, and is not null, then increment the shared count on the shared object, and give the managed pointer a deleter that decrements the reference count for the shared object. Note that if this shared_ptr is reference- counting a null pointer, the empty bslma::ManagedPtr returned will not participate in that shared ownership.

◆ numReferences()

template<class ELEMENT_TYPE >
int bsl::shared_ptr< ELEMENT_TYPE >::numReferences ( ) const
inline

[DEPRECATED] Use use_count instead.

Return a "snapshot" of the number of shared pointers (including this one) that share ownership of the object managed by this shared pointer. Note that the behavior of this function is the same as use_count , and the result may be unreliable in multi-threaded code for the same reasons.

◆ operator BoolType()

template<class ELEMENT_TYPE >
bsl::shared_ptr< ELEMENT_TYPE >::operator BoolType ( ) const
inline

Return a value of an "unspecified bool" type that evaluates to false if this shared pointer does not refer to an object, and true otherwise. Note that this conversion operator allows a shared pointer to be used within a conditional context (e.g., within an if or while statement), but does not allow shared pointers to unrelated types to be compared (e.g., via < or >).

◆ operator*()

template<class ELEMENT_TYPE >
add_lvalue_reference< ELEMENT_TYPE >::type bsl::shared_ptr< ELEMENT_TYPE >::operator* ( ) const
inline

Return a reference providing modifiable access to the object referred to by this shared pointer. The behavior is undefined unless this shared pointer refers to an object, and ELEMENT_TYPE is not (potentially const or volatile qualified) void.

◆ operator->()

template<class ELEMENT_TYPE >
ELEMENT_TYPE * bsl::shared_ptr< ELEMENT_TYPE >::operator-> ( ) const
inline

Return the address providing modifiable access to the object referred to by this shared pointer, or 0 if this shared pointer does not refer to an object. Note that applying this operator conventionally (e.g., to invoke a method) to an shared pointer that does not refer to an object will result in undefined behavior.

◆ operator=() [1/5]

template<class ELEMENT_TYPE >
template<class COMPATIBLE_TYPE >
enable_if< is_convertible< COMPATIBLE_TYPE *, ELEMENT_TYPE * >::value, shared_ptr< ELEMENT_TYPE > & >::type bsl::shared_ptr< ELEMENT_TYPE >::operator= ( BloombergLP::bslma::ManagedPtr< COMPATIBLE_TYPE >  rhs)
inline

Transfer, to this shared pointer, ownership of the modifiable object managed by the specified rhs managed pointer to the (template parameter) type COMPATIBLE_TYPE, and make this shared pointer refer to (ELEMENT_TYPE *)rhs.ptr(). The deleter used in the rhs will be used to destroy the shared object when all references have been released. The default allocator is used to allocate a SharedPtrRep, if needed (users must use the copy-constructor and swap instead of using this operator to supply an alternative allocator). If this shared pointer is already managing a (possibly shared) object, then release the reference to that shared object, and destroy it using its associated deleter if this shared pointer held the last shared reference to that object. Note that if rhs is empty, then this shared pointer will be empty after the assignment. Also note that if rhs owns a reference to another shared object (due to a previous call to shared_ptr<T>::managedPtr) then this shared_ptr will adopt the ManagedPtrs ownership of that shared object.

◆ operator=() [2/5]

template<class ELEMENT_TYPE >
shared_ptr< ELEMENT_TYPE > & bsl::shared_ptr< ELEMENT_TYPE >::operator= ( BloombergLP::bslmf::MovableRef< shared_ptr< ELEMENT_TYPE > >  rhs)

Make this shared pointer manage the same modifiable object as the specified rhs shared pointer to the (template parameter) type COMPATIBLE_TYPE, use the same deleter as rhs, and refer to rhs.get(); return a reference providing modifiable access to this shared pointer. Reset rhs to an empty state, not pointing to any object, unless *this is the same object as rhs. Note that if rhs is empty, then this shared pointer will also be empty after the assignment.

◆ operator=() [3/5]

template<class ELEMENT_TYPE >
template<class COMPATIBLE_TYPE >
enable_if< is_convertible< COMPATIBLE_TYPE *, ELEMENT_TYPE * >::value, shared_ptr< ELEMENT_TYPE > & >::type bsl::shared_ptr< ELEMENT_TYPE >::operator= ( BloombergLP::bslmf::MovableRef< shared_ptr< COMPATIBLE_TYPE > >  rhs)

Make this shared pointer refer to and manage the same modifiable object as the specified rhs shared pointer to the (template parameter) type COMPATIBLE_TYPE, using the same deleter as rhs and referring to (ELEMENT_TYPE *)rhs.get(), and return a reference to this modifiable shared pointer. If this shared pointer is already managing a (possibly shared) object, then release the shared reference to that object, and destroy it using its associated deleter if this shared pointer held the last shared reference to that object. Reset rhs to an empty state, not pointing to any object, unless *this is the same object as rhs. This function does not exist unless a pointer to (template parameter) COMPATIBLE_TYPE is convertible to a pointer to the (template parameter) ELEMENT_TYPE of this shared_ptr. Note that if rhs is empty, then this shared pointer will also be empty after the assignment.

◆ operator=() [4/5]

template<class ELEMENT_TYPE >
shared_ptr< ELEMENT_TYPE > & bsl::shared_ptr< ELEMENT_TYPE >::operator= ( const shared_ptr< ELEMENT_TYPE > &  rhs)

Make this shared pointer manage the same modifiable object as the specified rhs shared pointer to the (template parameter) type COMPATIBLE_TYPE, use the same deleter as rhs, and refer to (ELEMENT_TYPE *)rhs.get(); return a reference providing modifiable access to this shared pointer. Note that if rhs is empty, then this shared pointer will also be empty after the assignment. Also note that if *this is the same object as rhs, then this method has no effect.

◆ operator=() [5/5]

template<class ELEMENT_TYPE >
template<class COMPATIBLE_TYPE >
enable_if< is_convertible< COMPATIBLE_TYPE *, ELEMENT_TYPE * >::value, shared_ptr< ELEMENT_TYPE > & >::type bsl::shared_ptr< ELEMENT_TYPE >::operator= ( const shared_ptr< COMPATIBLE_TYPE > &  rhs)

Make this shared pointer refer to and manage the same modifiable object as the specified rhs shared pointer to the (template parameter) type COMPATIBLE_TYPE, using the same deleter as rhs and referring to (ELEMENT_TYPE *)rhs.get(), and return a reference to this modifiable shared pointer. If this shared pointer is already managing a (possibly shared) object, then release the shared reference to that object, and destroy it using its associated deleter if this shared pointer held the last shared reference to that object. Note that if rhs is empty, then this shared pointer will also be empty after the assignment.

◆ operator[]()

template<class ELEMENT_TYPE >
add_lvalue_reference< typenameshared_ptr< ELEMENT_TYPE >::element_type >::type bsl::shared_ptr< ELEMENT_TYPE >::operator[] ( ptrdiff_t  index) const
inline

Return a reference providing modifiable access to the object at the specified index offset in the object referred to by this shared pointer. The behavior is undefined unless this shared pointer is not empty, ELEMENT_TYPE is not void (a compiler error will be generated if this operator is instantiated within the shared_ptr<void> class), and this shared pointer refers to an array of ELEMENT_TYPE objects. Instead of element_type &, we use add_lvalue_reference<element_type>::type for the return type because that allows people to instantiate shared_ptr<cv_void>, as long as they don't use this method. Note that this method is logically equivalent to *(get() + index).

◆ owner_before() [1/2]

template<class ELEMENT_TYPE >
template<class ANY_TYPE >
bool bsl::shared_ptr< ELEMENT_TYPE >::owner_before ( const shared_ptr< ANY_TYPE > &  other) const
inline

◆ owner_before() [2/2]

template<class ELEMENT_TYPE >
template<class ANY_TYPE >
bool bsl::shared_ptr< ELEMENT_TYPE >::owner_before ( const weak_ptr< ANY_TYPE > &  other) const
inline

Return true if the address of the BloombergLP::bslma::SharedPtrRep object used by this shared pointer is ordered before the address of the BloombergLP::bslma::SharedPtrRep object used by the specified other shared pointer under the total ordering defined by std::less<BloombergLP::bslma::SharedPtrRep *>, and false otherwise.

◆ owner_equal() [1/2]

template<class ELEMENT_TYPE >
template<class ANY_TYPE >
bool bsl::shared_ptr< ELEMENT_TYPE >::owner_equal ( const shared_ptr< ANY_TYPE > &  other) const
inline

◆ owner_equal() [2/2]

template<class ELEMENT_TYPE >
template<class ANY_TYPE >
bool bsl::shared_ptr< ELEMENT_TYPE >::owner_equal ( const weak_ptr< ANY_TYPE > &  other) const
inline

Return true if the address of the BloombergLP::bslma::SharedPtrRep object used by this shared pointer is equal to the address of the BloombergLP::bslma::SharedPtrRep object used by the specified other shared pointer, and false otherwise.

◆ owner_hash()

template<class ELEMENT_TYPE >
size_t bsl::shared_ptr< ELEMENT_TYPE >::owner_hash ( ) const
inline

Return an unspecified value such that, for any object x where owner_equal(x) is true, owner_hash() == x.owner_hash() is true. Note that this is based on the hash of the address of the BloombergLP::bslma::SharedPtrRep object used by this object. Note also that for two empty smart pointers x and y, x.owner_hash() == y.owner_hash() is true.

◆ ptr()

template<class ELEMENT_TYPE >
shared_ptr< ELEMENT_TYPE >::element_type * bsl::shared_ptr< ELEMENT_TYPE >::ptr ( ) const
inline

[DEPRECATED] Use get instead.

Return the address providing modifiable access to the object referred to by this shared pointer, or 0 if this shared pointer does not refer to an object. Note that the behavior of this function is the same as get.

◆ release()

template<class ELEMENT_TYPE >
pair< typename shared_ptr< ELEMENT_TYPE >::element_type *, BloombergLP::bslma::SharedPtrRep * > bsl::shared_ptr< ELEMENT_TYPE >::release ( )

Return the pair consisting of the addresses of the modifiable ELEMENT_TYPE object referred to, and the representation shared by, this shared pointer, and reset this shared pointer to the empty state, referring to no object, with no effect on the representation. The reference counter is not modified nor is the shared object deleted; if the reference count of the representation is greater than one, then it is not safe to release the representation (thereby destroying the shared object), but it is always safe to create another shared pointer with the representation using the constructor with the following signature:

'shared_ptr(ELEMENT_TYPE *ptr,
BloombergLP::bslma::SharedPtrRep *rep)'

Note that this function returns a pair of null pointers if this shared pointer is empty.

◆ rep()

template<class ELEMENT_TYPE >
BloombergLP::bslma::SharedPtrRep * bsl::shared_ptr< ELEMENT_TYPE >::rep ( ) const
inline

Return the address providing modifiable access to the BloombergLP::bslma::SharedPtrRep object used by this shared pointer, or 0 if this shared pointer is empty.

◆ reset() [1/5]

template<class ELEMENT_TYPE >
void bsl::shared_ptr< ELEMENT_TYPE >::reset ( )
inline

Reset this shared pointer to the empty state. If this shared pointer is managing a (possibly shared) object, then release the reference to the shared object, calling the associated deleter to destroy the shared object if this shared pointer is the last shared reference.

◆ reset() [2/5]

template<class ELEMENT_TYPE >
template<class COMPATIBLE_TYPE >
enable_if< is_convertible< COMPATIBLE_TYPE *, ELEMENT_TYPE * >::value >::type bsl::shared_ptr< ELEMENT_TYPE >::reset ( COMPATIBLE_TYPE *  ptr)
inline

Modify this shared pointer to manage the modifiable object of the (template parameter) type COMPATIBLE_TYPE at the specified ptr address and to refer to (ELEMENT_TYPE *)ptr. If this shared pointer is already managing a (possibly shared) object, then, unless an exception is thrown allocating memory to manage ptr, release the reference to the shared object, calling the associated deleter to destroy the shared object if this shared pointer is the last reference. The currently installed default allocator is used to allocate the internal representation of this shared pointer, and the shared object will be destroyed by a call to delete ptr when all references have been released. If an exception is thrown allocating the internal representation, then delete ptr is called and this shared pointer retains ownership of its original object. If COMPATIBLE_TYPE* is not implicitly convertible to ELEMENT_TYPE*, then a compiler diagnostic will be emitted indicating the error. Note that if ptr is 0, then this shared pointer will still allocate an internal representation to share ownership of that empty state, which will be reclaimed when the last reference is destroyed.

◆ reset() [3/5]

template<class ELEMENT_TYPE >
template<class COMPATIBLE_TYPE , class DELETER >
enable_if< is_convertible< COMPATIBLE_TYPE *, ELEMENT_TYPE * >::value >::type bsl::shared_ptr< ELEMENT_TYPE >::reset ( COMPATIBLE_TYPE *  ptr,
DELETER  deleter 
)
inline

Modify this shared pointer to manage the modifiable object of the (template parameter) type COMPATIBLE_TYPE at the specified ptr address, refer to (ELEMENT_TYPE *)ptr, and use the specified deleter to delete the shared object when all references have been released. If this shared pointer is already managing a (possibly shared) object, then unless an exception is thrown allocating memory to manage ptr, release the reference to the shared object, calling the associated deleter to destroy the shared object if this shared pointer is the last reference. If DELETER is an object type, then deleter is assumed to be a function-like deleter that may be invoked to destroy the object referred to by a single argument of type COMPATIBLE_TYPE * (i.e., deleter(ptr) will be called to destroy the shared object). If DELETER is a pointer type that is not a function pointer, then deleter shall be a pointer to a factory object that exposes a member function that can be invoked as deleteObject(ptr) that will be called to destroy the object at the ptr address (i.e., deleter->deleteObject(ptr) will be called to delete the shared object). (See the "Deleters" section in the component-level documentation.) If DELETER is also a pointer to bslma::Allocator or to a class derived from bslma::Allocator, then that allocator will also be used to allocate and destroy the internal representation of this shared pointer when all references have been released; otherwise, the currently installed default allocator is used to allocate and destroy the internal representation of this shared pointer when all references have been released. If an exception is thrown allocating the internal representation, then deleter(ptr) is called (or deleter->deleteObject(ptr) for factory-type deleters) and this shared pointer retains ownership of its original object. If COMPATIBLE_TYPE* is not implicitly convertible to ELEMENT_TYPE*, then a compiler diagnostic will be emitted indicating the error. Note that, for factory deleters, deleter must remain valid until all references to ptr have been released. If ptr is 0, then an internal representation will still be allocated, and this shared pointer will share ownership of a copy of deleter. Further note that this function is logically equivalent to:

*this = shared_ptr<ELEMENT_TYPE>(ptr, deleter);

◆ reset() [4/5]

template<class ELEMENT_TYPE >
template<class COMPATIBLE_TYPE , class DELETER , class ALLOCATOR >
enable_if< is_convertible< COMPATIBLE_TYPE *, ELEMENT_TYPE * >::value >::type bsl::shared_ptr< ELEMENT_TYPE >::reset ( COMPATIBLE_TYPE *  ptr,
DELETER  deleter,
ALLOCATOR  basicAllocator 
)
inline

Modify this shared pointer to manage the modifiable object of the (template parameter) type COMPATIBLE_TYPE at the specified ptr address, refer to (ELEMENT_TYPE *)ptr and use the specified deleter to delete the shared object when all references have been released. Use the specified basicAllocator to allocate and deallocate the internal representation of the shared pointer. If this shared pointer is already managing a (possibly shared) object, then, unless an exception is thrown allocating memory to manage ptr, release the shared reference to that shared object, and destroy it using its associated deleter if this shared pointer held the last shared reference to that object. If DELETER is a reference type, then deleter is assumed to be a function-like deleter that may be invoked to destroy the object referred to by a single argument of type COMPATIBLE_TYPE * (i.e., deleter(ptr) will be called to destroy the shared object). If DELETER is a pointer type, then deleter is assumed to be a pointer to a factory object that exposes a member function that can be invoked as deleteObject(ptr) that will be called to destroy the object at the ptr address (i.e., deleter->deleteObject(ptr) will be called to delete the shared object). (See the "Deleters" section in the component-level documentation.) If an exception is thrown allocating the internal representation, then deleter(ptr) is called (or deleter->deleteObject(ptr) for factory-type deleters) and this shared pointer retains ownership of its original object. The behavior is undefined unless deleter(ptr) is a well-defined expression (or deleter->deleteObject(ptr) for factory-type deleters), and unless the copy constructor for deleter does not throw an exception. If COMPATIBLE_TYPE * is not implicitly convertible to ELEMENT_TYPE *, then a compiler diagnostic will be emitted indicating the error. Note that, for factory deleters, the deleter must remain valid until all references to ptr have been released. Also note that if ptr is 0, then an internal representation will still be allocated, and this shared pointer will share ownership of a copy of deleter. Further note that this function is logically equivalent to:

*this = shared_ptr<ELEMENT_TYPE>(ptr, deleter, basicAllocator);

◆ reset() [5/5]

template<class ELEMENT_TYPE >
template<class ANY_TYPE >
void bsl::shared_ptr< ELEMENT_TYPE >::reset ( const shared_ptr< ANY_TYPE > &  source,
ELEMENT_TYPE *  ptr 
)
inline

Modify this shared pointer to manage the same modifiable object (if any) as the specified source shared pointer to the (template parameter) type ANY_TYPE, and refer to the modifiable object at the specified ptr address (i.e., make this shared pointer an "alias" of source). If this shared pointer is already managing a (possibly shared) object, then release the reference to the shared object, calling the associated deleter to destroy the shared object if this shared pointer is the last reference. Note that typically the objects referred to by source and ptr have identical lifetimes (e.g., one might be a part of the other), so that the deleter for source will destroy them both, but do not necessarily have the same type. Also note that if source is empty, then this shared pointer will be reset to an empty state, even if ptr is not null (in which case this empty shared pointer will refer to the same object as ptr). Also note that if ptr is null and source is not empty, then this shared pointer will be reset to a (reference-counted) null pointer alias. Further note that the behavior of this method is the same as loadAlias(source, ptr). Finally note that this is a non-standard BDE extension to the C++ Standard shared_ptr interface, which does not provide an alias overload for the reset function.

◆ swap()

template<class ELEMENT_TYPE >
void bsl::shared_ptr< ELEMENT_TYPE >::swap ( shared_ptr< ELEMENT_TYPE > &  other)
inline

Efficiently exchange the states of this shared pointer and the specified other shared pointer such that each will refer to the object formerly referred to by the other and each will manage the object formerly managed by the other.

◆ use_count()

template<class ELEMENT_TYPE >
long bsl::shared_ptr< ELEMENT_TYPE >::use_count ( ) const
inline

Return a "snapshot" of the number of shared pointers (including this one) that share ownership of the object managed by this shared pointer. Note that 0 is returned if this shared pointer is empty. Also note that any result other than 0 may be unreliable in a multi-threaded program, where another pointer sharing ownership in a different thread may be copied or destroyed, or a weak pointer may be locked in the case that 1 is returned (that would otherwise indicate unique ownership).

Friends And Related Symbol Documentation

◆ BloombergLP::bslstl::SharedPtr_ImpUtil

template<class ELEMENT_TYPE >
friend struct BloombergLP::bslstl::SharedPtr_ImpUtil
friend

◆ shared_ptr

template<class ELEMENT_TYPE >
template<class COMPATIBLE_TYPE >
friend class shared_ptr
friend

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