Constructors
Declared in <bslstl_sharedptr.h>
Create an empty shared pointer, i.e., a shared pointer with no representation that does not refer to any object and has no deleter.
constexpr
shared_ptr() noexcept;
» more...
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(shared_ptr const& original) noexcept;
» more...
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 COMPATIBLE_TYPE>
shared_ptr(shared_ptr<COMPATIBLE_TYPE> const& other) noexcept;
» more...
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 COMPATIBLE_TYPE>
shared_ptr(shared_ptr<COMPATIBLE_TYPE>&& other) noexcept;
» more...
Create an empty shared pointer, i.e., a shared pointer with no representation that does not refer to any object and has no deleter.
constexpr
shared_ptr(bsl::nullptr_t) noexcept;
» more...
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(BloombergLP::bslmf::MovableRef<shared_ptr> original) noexcept;
» more...
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 COMPATIBLE_TYPE>
explicit
shared_ptr(weak_ptr<COMPATIBLE_TYPE> const& ptr);
» more...
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 CONVERTIBLE_TYPE>
explicit
shared_ptr(CONVERTIBLE_TYPE* ptr);
» more...
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(
nullptr_t nullPointerLiteral,
BloombergLP::bslma::Allocator* basicAllocator);
» more...
Create a shared pointer that takes over the management of the modifiable object of (template parameter) type COMPATIBLE_TYPE previously managed by the auto pointer object that the specified autoRef refers to; this shared pointer refers to the same object that it manages, and delete(get()) will be called 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. This function does not exist unless COMPATIBLE_TYPE * is convertible to ELEMENT_TYPE *.
explicit
shared_ptr(
std::auto_ptr_ref<ELEMENT_TYPE> autoRef,
BloombergLP::bslma::Allocator* basicAllocator = 0);
» more...
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(
element_type* ptr,
BloombergLP::bslma::SharedPtrRep* rep);
» more...
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 CONVERTIBLE_TYPE>
shared_ptr(
BloombergLP::bslma::ManagedPtr<CONVERTIBLE_TYPE> managedPtr,
BloombergLP::bslma::Allocator* basicAllocator = 0);
» more...
Create a shared pointer that takes over the management of the modifiable object previously managed by the specified autoPtr to the (template parameter) type CONVERTIBLE_TYPE, and that refers to (ELEMENT_TYPE *)autoPtr.get(). delete(autoPtr.release()) will be called 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.
template<class CONVERTIBLE_TYPE>
explicit
shared_ptr(
std::auto_ptr<CONVERTIBLE_TYPE>& autoPtr,
BloombergLP::bslma::Allocator* basicAllocator = 0);
» more...
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 ANY_TYPE>
shared_ptr(
shared_ptr<ANY_TYPE> const& source,
ELEMENT_TYPE* object) noexcept;
» more...
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 CONVERTIBLE_TYPE>
shared_ptr(
CONVERTIBLE_TYPE* ptr,
BloombergLP::bslma::Allocator* basicAllocator);
» more...
Create a shared pointer that takes over the management of the modifiable object previously managed by the specified adoptee to the (template parameter) type COMPATIBLE_TYPE, and that refers to (ELEMENT_TYPE *)autoPtr.get(). delete(autoPtr.release()) will be called 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. This function does not exist unless unique_ptr<COMPATIBLE_TYPE, DELETER>::pointer is convertible to ELEMENT_TYPE *. Note that this function creates a shared_ptr with an unspecified deleter type that has satisfies this contract, which might not be the deleter of rhs, which is specified by the C++ standard.
template<
class COMPATIBLE_TYPE,
class UNIQUE_DELETER>
requires is_convertible<
typename std::unique_ptr<COMPATIBLE_TYPE,
UNIQUE_DELETER>::pointer,
ELEMENT_TYPE *>::value
shared_ptr(
std::unique_ptr<COMPATIBLE_TYPE, UNIQUE_DELETER>&& adoptee,
BloombergLP::bslma::Allocator* basicAllocator = 0);
» more...
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 CONVERTIBLE_TYPE,
class DELETER>
shared_ptr(
CONVERTIBLE_TYPE* ptr,
DELETER* deleter);
» more...
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(
ELEMENT_TYPE* ptr,
BloombergLP::bslma::SharedPtrRep* rep,
BloombergLP::bslstl::SharedPtr_RepFromExistingSharedPtr);
» more...
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 DELETER>
shared_ptr(
nullptr_t nullPointerLiteral,
DELETER deleter,
BloombergLP::bslma::Allocator* basicAllocator = 0);
» more...
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 CONVERTIBLE_TYPE,
class DELETER>
shared_ptr(
CONVERTIBLE_TYPE* ptr,
DELETER deleter,
BloombergLP::bslma::Allocator* basicAllocator = 0);
» more...
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 DELETER,
class ALLOCATOR>
shared_ptr(
nullptr_t nullPointerLiteral,
DELETER deleter,
ALLOCATOR basicAllocator,
ALLOCATOR::value_type* = 0);
» more...
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 CONVERTIBLE_TYPE,
class DELETER,
class ALLOCATOR>
shared_ptr(
CONVERTIBLE_TYPE* ptr,
DELETER deleter,
ALLOCATOR basicAllocator,
ALLOCATOR::value_type* = 0);
» more...