Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions | Friends

bsl::shared_ptr< ELEMENT_TYPE > Class Template Reference

#include <bslstl_sharedptr.h>

List of all members.

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 >
 shared_ptr (CONVERTIBLE_TYPE *ptr)
template<class CONVERTIBLE_TYPE >
 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 >
 shared_ptr (CONVERTIBLE_TYPE *ptr, DELETER *deleter)
template<class CONVERTIBLE_TYPE , class DELETER >
 shared_ptr (CONVERTIBLE_TYPE *ptr, DELETER deleter, BloombergLP::bslma::Allocator *basicAllocator=0)
template<class CONVERTIBLE_TYPE , class DELETER , class ALLOCATOR >
 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 >
 shared_ptr (nullptr_t nullPointerLiteral, DELETER deleter, BloombergLP::bslma::Allocator *basicAllocator=0)
template<class DELETER , class ALLOCATOR >
 shared_ptr (nullptr_t nullPointerLiteral, DELETER deleter, ALLOCATOR basicAllocator, typename ALLOCATOR::value_type *=0)
template<class CONVERTIBLE_TYPE >
 shared_ptr (BloombergLP::bslma::ManagedPtr< CONVERTIBLE_TYPE > managedPtr, BloombergLP::bslma::Allocator *basicAllocator=0)
template<class COMPATIBLE_TYPE , class UNIQUE_DELETER >
 shared_ptr (std::unique_ptr< COMPATIBLE_TYPE, UNIQUE_DELETER > &&adoptee, BloombergLP::bslma::Allocator *basicAllocator=0, typename enable_if< is_convertible< typename std::unique_ptr< COMPATIBLE_TYPE, UNIQUE_DELETER >::pointer, ELEMENT_TYPE * >::value, BloombergLP::bslstl::SharedPtr_ImpUtil >::type=BloombergLP::bslstl::SharedPtr_ImpUtil())
template<class ANY_TYPE >
 shared_ptr (const shared_ptr< ANY_TYPE > &source, ELEMENT_TYPE *object) BSLS_KEYWORD_NOEXCEPT
template<class COMPATIBLE_TYPE >
 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 >
 shared_ptr (BloombergLP::bslmf::MovableRef< shared_ptr< COMPATIBLE_TYPE > > other) BSLS_KEYWORD_NOEXCEPT
template<class COMPATIBLE_TYPE >
 shared_ptr (const weak_ptr< COMPATIBLE_TYPE > &ptr)
template<class COMPATIBLE_TYPE >
 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)
template<class COMPATIBLE_TYPE , class UNIQUE_DELETER >
enable_if< is_convertible
< typename std::unique_ptr
< COMPATIBLE_TYPE,
UNIQUE_DELETER >::pointer,
ELEMENT_TYPE * >::value,
shared_ptr & >::type 
operator= (std::unique_ptr< COMPATIBLE_TYPE, UNIQUE_DELETER > &&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
 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_TYPE * ptr () const BSLS_KEYWORD_NOEXCEPT

Friends

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 Component bslstl_sharedptr


Member Typedef Documentation

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

Constructor & Destructor Documentation

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

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

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

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

template<class ELEMENT_TYPE>
template<class CONVERTIBLE_TYPE >
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( CONVERTIBLE_TYPE *  ptr  )  [explicit]

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.

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

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);
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);
template<class ELEMENT_TYPE>
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( ELEMENT_TYPE *  ptr,
BloombergLP::bslma::SharedPtrRep *  rep,
BloombergLP::bslstl::SharedPtr_RepFromExistingSharedPtr   
)

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.

template<class ELEMENT_TYPE>
template<class CONVERTIBLE_TYPE , class 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);

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.

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

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.

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

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.

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

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.

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

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.

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

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.

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

IMPLICIT: 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.

template<class ELEMENT_TYPE>
template<class COMPATIBLE_TYPE , class UNIQUE_DELETER >
bsl::shared_ptr< ELEMENT_TYPE >::shared_ptr ( std::unique_ptr< COMPATIBLE_TYPE, UNIQUE_DELETER > &&  adoptee,
BloombergLP::bslma::Allocator *  basicAllocator = 0,
typename enable_if< is_convertible< typename std::unique_ptr< COMPATIBLE_TYPE, UNIQUE_DELETER >::pointer, ELEMENT_TYPE * >::value, BloombergLP::bslstl::SharedPtr_ImpUtil >::type  = BloombergLP::bslstl::SharedPtr_ImpUtil() 
) [inline]
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.

template<class ELEMENT_TYPE>
template<class COMPATIBLE_TYPE >
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.

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.

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.

template<class ELEMENT_TYPE>
template<class COMPATIBLE_TYPE >
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.

template<class ELEMENT_TYPE>
template<class COMPATIBLE_TYPE >
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.

template<class ELEMENT_TYPE>
template<class COMPATIBLE_TYPE >
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.

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.


Member Function Documentation

template<class ELEMENT_TYPE>
bsl::shared_ptr< ELEMENT_TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( shared_ptr< ELEMENT_TYPE >  ,
bsl::is_nothrow_move_constructible   
)
template<class ELEMENT_TYPE>
shared_ptr& 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.

template<class ELEMENT_TYPE>
shared_ptr& 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.

template<class ELEMENT_TYPE>
template<class COMPATIBLE_TYPE >
enable_if< is_convertible<COMPATIBLE_TYPE *, ELEMENT_TYPE *>::value, shared_ptr&>::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.

template<class ELEMENT_TYPE>
template<class COMPATIBLE_TYPE >
enable_if<is_convertible<COMPATIBLE_TYPE *, ELEMENT_TYPE *>::value, shared_ptr&>::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.

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

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.

template<class ELEMENT_TYPE>
template<class COMPATIBLE_TYPE , class UNIQUE_DELETER >
enable_if< is_convertible< typename std::unique_ptr<COMPATIBLE_TYPE, UNIQUE_DELETER>::pointer, ELEMENT_TYPE *>::value, shared_ptr&>::type bsl::shared_ptr< ELEMENT_TYPE >::operator= ( std::unique_ptr< COMPATIBLE_TYPE, UNIQUE_DELETER > &&  rhs  ) 

Transfer, to this shared pointer, ownership of the object managed by the specified rhs unique pointer to the (template parameter) type COMPATIBLE_TYPE, and make this shared pointer refer to (ELEMENT_TYPE *)rhs.get(). The deleter of rhs will be called to destroy the shared object when all references have been released. 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. This function does not exist unless unique_ptr<COMPATIBLE_TYPE, DELETER>pointer is convertible to ELEMENT_TYPE *. Note that if rhs is empty, then this shared pointer will be empty after the assignment. Also note that this function creates a shared_ptr with an unspecified deleter type that satisfies this contract; the C++11 standard specifies the exact deleter that should be in use after assignment, so this implementation may be non-conforming.

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

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.

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  ) 

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.

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 
)

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);
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 
)

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);
template<class ELEMENT_TYPE>
template<class ANY_TYPE >
void bsl::shared_ptr< ELEMENT_TYPE >::reset ( const shared_ptr< ANY_TYPE > &  source,
ELEMENT_TYPE *  ptr 
)

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.

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

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.

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.

Referenced by bdlf::BindWrapper< RET, FUNC, TUPLE >::BindWrapper().

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.

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).

template<class ELEMENT_TYPE>
pair<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 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.

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

[!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().

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

[!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).

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

[!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);
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 
)

[!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);
template<class ELEMENT_TYPE>
bsl::shared_ptr< ELEMENT_TYPE >::operator BoolType (  )  const

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 >).

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

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.

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

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.

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

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.

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

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).

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

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.

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.

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

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).

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.

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

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.

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

[!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.

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

[!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.

Referenced by bdlf::BindWrapper< RET, FUNC, TUPLE >::operator->().


Friends And Related Function Documentation

template<class ELEMENT_TYPE>
friend class shared_ptr [friend]
template<class ELEMENT_TYPE>
friend struct BloombergLP::bslstl::SharedPtr_ImpUtil [friend]

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