[#bsl-shared_ptr-0a-2constructor-03f]
= xref:bsl.adoc[bsl]::xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr]::shared&lowbar;ptr
:relfileprefix: ../../
:mrdocs:

Constructors

== Synopses

Declared in `&lt;bslstl&lowbar;sharedptr&period;h&gt;`

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


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
xref:bsl/shared_ptr-0a/2constructor-08b.adoc[shared&lowbar;ptr]() noexcept;
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-08b.adoc[_» more&period;&period;&period;_]#

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&period; Note that if `original` is empty, then an empty shared pointer is created, which may still point to an un&hyphen;managed object if `original` were constructed through an aliasing constructor&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/shared_ptr-0a/2constructor-04.adoc[shared&lowbar;ptr](xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr] const& original) noexcept;
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-04.adoc[_» more&period;&period;&period;_]#

Create a shared pointer that manages the same modifiable object (if any) as the specified `other` shared pointer to the (template parameter) type `COMPATIBLE&lowbar;TYPE`, uses the same deleter as `other` to destroy the shared object, and refers to `(ELEMENT&lowbar;TYPE&ast;)other&period;get()`&period; If `COMPATIBLE&lowbar;TYPE &ast;` is not implicitly convertible to `ELEMENT&lowbar;TYPE &ast;`, then a compiler diagnostic will be emitted indicating the error&period; Note that if `other` is empty, then an empty shared pointer is created, which may still point to an un&hyphen;managed object if `other` were constructed through an aliasing constructor&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class COMPATIBLE&lowbar;TYPE&gt;
xref:bsl/shared_ptr-0a/2constructor-0b.adoc[shared&lowbar;ptr](xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr&lt;COMPATIBLE&lowbar;TYPE&gt;] const& other) noexcept;
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-0b.adoc[_» more&period;&period;&period;_]#

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&lowbar;TYPE`, using the same deleter as `other` to destroy the shared object, and refers to `(ELEMENT&lowbar;TYPE&ast;)other&period;get()`&period; If `COMPATIBLE&lowbar;TYPE &ast;` is not implicitly convertible to `ELEMENT&lowbar;TYPE &ast;`, then a compiler diagnostic will be emitted indicating the error&period; Note that if `other` is empty, then an empty shared pointer is created, which may still point to an un&hyphen;managed object if `other` were constructed through an aliasing constructor&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class COMPATIBLE&lowbar;TYPE&gt;
xref:bsl/shared_ptr-0a/2constructor-0731.adoc[shared&lowbar;ptr](xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr&lt;COMPATIBLE&lowbar;TYPE&gt;]&& other) noexcept;
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-0731.adoc[_» more&period;&period;&period;_]#

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


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
xref:bsl/shared_ptr-0a/2constructor-00f.adoc[shared&lowbar;ptr](xref:bsl/nullptr_t-08.adoc[bsl::nullptr&lowbar;t]) noexcept;
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-00f.adoc[_» more&period;&period;&period;_]#

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&period; Note that if `original` is empty, then an empty shared pointer is created, which may still point to an un&hyphen;managed object if `original` were constructed through an aliasing constructor&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/shared_ptr-0a/2constructor-077.adoc[shared&lowbar;ptr](xref:BloombergLP/bslmf/MovableRef.adoc[BloombergLP::bslmf::MovableRef&lt;shared&lowbar;ptr&gt;] original) noexcept;
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-077.adoc[_» more&period;&period;&period;_]#

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


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class COMPATIBLE&lowbar;TYPE&gt;
explicit
xref:bsl/shared_ptr-0a/2constructor-08d.adoc[shared&lowbar;ptr](xref:bsl/weak_ptr-0d.adoc[weak&lowbar;ptr&lt;COMPATIBLE&lowbar;TYPE&gt;] const& ptr);
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-08d.adoc[_» more&period;&period;&period;_]#

Create a shared pointer that manages a modifiable object of (template parameter) type `CONVERTIBLE&lowbar;TYPE` and refers to the specified `(ELEMENT&lowbar;TYPE &ast;)ptr`&period; The currently installed default allocator is used to allocate and deallocate the internal representation of the shared pointer&period; When all references have been released, the object pointed to by the managed pointer will be destroyed by a call to `delete ptr`&period; If `CONVERTIBLE&lowbar;TYPE &ast;` is not implicitly convertible to `ELEMENT&lowbar;TYPE &ast;`, then a compiler diagnostic will be emitted indicating the error&period; 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&period; If an exception is thrown allocating storage for the representation, then `delete ptr` will be called&period; Note that if `ptr` is a null&hyphen;pointer constant, the compiler will actually select the `shared&lowbar;ptr(bsl&colon;&colon;nullptr&lowbar;t)` constructor, resulting in an empty shared pointer&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class CONVERTIBLE&lowbar;TYPE&gt;
explicit
xref:bsl/shared_ptr-0a/2constructor-008.adoc[shared&lowbar;ptr](CONVERTIBLE&lowbar;TYPE* ptr);
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-008.adoc[_» more&period;&period;&period;_]#

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


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/shared_ptr-0a/2constructor-02.adoc[shared&lowbar;ptr](
    xref:bsl/nullptr_t-08.adoc[nullptr&lowbar;t] nullPointerLiteral,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator);
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-02.adoc[_» more&period;&period;&period;_]#

Create a shared pointer that takes over the management of the modifiable object of (template parameter) type `COMPATIBLE&lowbar;TYPE` previously managed by the auto pointer object that the specified `autoRef` refers to&semi; 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&period; Optionally specify a `basicAllocator` used to allocate and deallocate the internal representation of the shared pointer&period; If `basicAllocator` is 0, the currently installed default allocator is used&period; This function does not exist unless `COMPATIBLE&lowbar;TYPE &ast;` is convertible to `ELEMENT&lowbar;TYPE &ast;`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
explicit
xref:bsl/shared_ptr-0a/2constructor-01.adoc[shared&lowbar;ptr](
    std::auto&lowbar;ptr&lowbar;ref&lt;ELEMENT&lowbar;TYPE&gt; autoRef,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator = 0);
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-01.adoc[_» more&period;&period;&period;_]#

Create a shared pointer that takes ownership of the specified `rep` and refers to the modifiable object at the specified `ptr` address&period; The number of references to `rep` is _NOT_ incremented&period; Note that if `rep` is a pointer to a class derived from `BloombergLP&colon;&colon;bslma&colon;&colon;SharedPtrRep`, the compiler will actually select the following (more general) constructor that has the same behavior&colon; &grave; template &lt;class COMPATIBLE&lowbar;TYPE, class DELETER&gt; shared&lowbar;ptr(COMPATIBLE&lowbar;TYPE &ast;ptr, DELETER &ast; deleter)&semi; &grave;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/shared_ptr-0a/2constructor-0c.adoc[shared&lowbar;ptr](
    xref:bsl/shared_ptr-0a/element_type.adoc[element&lowbar;type]* ptr,
    xref:BloombergLP/bslma/SharedPtrRep.adoc[BloombergLP::bslma::SharedPtrRep]* rep);
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-0c.adoc[_» more&period;&period;&period;_]#

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&lowbar;TYPE`, and that refers to `(ELEMENT&lowbar;TYPE &ast;)managedPtr&period;ptr()`&period; The deleter used in the `managedPtr` will be used to destroy the shared object when all references have been released&period; Optionally specify a `basicAllocator` used to allocate and deallocate the internal representation of the shared pointer&period; If `basicAllocator` is 0, the currently installed default allocator is used&period; If `CONVERTIBLE&lowbar;TYPE &ast;` is not implicitly convertible to `ELEMENT&lowbar;TYPE &ast;`, then a compiler diagnostic will be emitted indicating the error&period; Note that if `managedPtr` is empty, then an empty shared pointer is created and `basicAllocator` is ignored&period; Also note that if `managedPtr` owns a reference to another shared object (due to a previous call to `shared&lowbar;ptr&lt;T&gt;&colon;&colon;managedPtr`) then no memory will be allocated, and this `shared&lowbar;ptr` will adopt the `ManagedPtr`s ownership of that shared object&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class CONVERTIBLE&lowbar;TYPE&gt;
xref:bsl/shared_ptr-0a/2constructor-09c.adoc[shared&lowbar;ptr](
    xref:BloombergLP/bslma/ManagedPtr-0fa.adoc[BloombergLP::bslma::ManagedPtr&lt;CONVERTIBLE&lowbar;TYPE&gt;] managedPtr,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator = 0);
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-09c.adoc[_» more&period;&period;&period;_]#

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&lowbar;TYPE`, and that refers to `(ELEMENT&lowbar;TYPE &ast;)autoPtr&period;get()`&period; `delete(autoPtr&period;release())` will be called to destroy the shared object when all references have been released&period; Optionally specify a `basicAllocator` used to allocate and deallocate the internal representation of the shared pointer&period; If `basicAllocator` is 0, the currently installed default allocator is used&period; If `CONVERTIBLE&lowbar;TYPE &ast;` is not implicitly convertible to `ELEMENT&lowbar;TYPE &ast;`, then a compiler diagnostic will be emitted indicating the error&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class CONVERTIBLE&lowbar;TYPE&gt;
explicit
xref:bsl/shared_ptr-0a/2constructor-0e.adoc[shared&lowbar;ptr](
    std::auto&lowbar;ptr&lt;CONVERTIBLE&lowbar;TYPE&gt;& autoPtr,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator = 0);
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-0e.adoc[_» more&period;&period;&period;_]#

Create a shared pointer that manages the same modifiable object (if any) as the specified `source` shared pointer to the (template parameter) type `ANY&lowbar;TYPE`, and that refers to the modifiable object at the specified `object` address&period; The resulting shared pointer is known as an &quot;alias&quot; of `source`&period; Note that typically the objects referred to by `source` and `object` have identical lifetimes (e&period;g&period;, 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&period; 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`)&period; Also note that if `object` is null and `source` is not empty, then a reference&hyphen;counted null pointer alias will be created&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class ANY&lowbar;TYPE&gt;
xref:bsl/shared_ptr-0a/2constructor-08c.adoc[shared&lowbar;ptr](
    xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr&lt;ANY&lowbar;TYPE&gt;] const& source,
    ELEMENT&lowbar;TYPE* object) noexcept;
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-08c.adoc[_» more&period;&period;&period;_]#

Create a shared pointer that manages a modifiable object of (template parameter) type `CONVERTIBLE&lowbar;TYPE` and refers to the specified `ptr` cast to a pointer to the (template parameter) type `ELEMENT&lowbar;TYPE`&period; 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&semi; otherwise, the currently installed default allocator is used&period; If `CONVERTIBLE&lowbar;TYPE &ast;` is not implicitly convertible to `ELEMENT&lowbar;TYPE &ast;`, then a compiler diagnostic will be emitted indicating the error&period; 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&period; Note that if `ptr` is a null&hyphen;pointer constant, the compiler will actually select the `shared&lowbar;ptr(bsl&colon;&colon;nullptr&lowbar;t, BloombergLP&colon;&colon;bslma&colon;&colon;Allocator &ast;)` constructor, resulting in an empty shared pointer&period; Note that if `basicAllocator` is a pointer to a class derived from `bslma&colon;&colon;Allocator`, the compiler will actually select the following (more general) constructor that has the same behavior&colon; &grave; template &lt;class CONVERTIBLE&lowbar;TYPE, class DELETER&gt; shared&lowbar;ptr(CONVERTIBLE&lowbar;TYPE &ast;ptr, DELETER &ast; deleter)&semi; &grave;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class CONVERTIBLE&lowbar;TYPE&gt;
xref:bsl/shared_ptr-0a/2constructor-093.adoc[shared&lowbar;ptr](
    CONVERTIBLE&lowbar;TYPE* ptr,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator);
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-093.adoc[_» more&period;&period;&period;_]#

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&lowbar;TYPE`, and that refers to `(ELEMENT&lowbar;TYPE &ast;)autoPtr&period;get()`&period; `delete(autoPtr&period;release())` will be called to destroy the shared object when all references have been released&period; Optionally specify a `basicAllocator` used to allocate and deallocate the internal representation of the shared pointer&period; If `basicAllocator` is 0, the currently installed default allocator is used&period; This function does not exist unless `unique&lowbar;ptr&lt;COMPATIBLE&lowbar;TYPE, DELETER&gt;&colon;&colon;pointer` is convertible to `ELEMENT&lowbar;TYPE &ast;`&period; Note that this function creates a `shared&lowbar;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&plus;&plus; standard&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class COMPATIBLE&lowbar;TYPE,
    class UNIQUE&lowbar;DELETER&gt;
requires is&lowbar;convertible&lt;
                      typename std&colon;&colon;unique&lowbar;ptr&lt;COMPATIBLE&lowbar;TYPE,
                                               UNIQUE&lowbar;DELETER&gt;&colon;&colon;pointer,
                      ELEMENT&lowbar;TYPE &ast;&gt;&colon;&colon;value
xref:bsl/shared_ptr-0a/2constructor-0735.adoc[shared&lowbar;ptr](
    std::unique&lowbar;ptr&lt;COMPATIBLE&lowbar;TYPE, UNIQUE&lowbar;DELETER&gt;&& adoptee,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator = 0);
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-0735.adoc[_» more&period;&period;&period;_]#

Create a shared pointer that manages a modifiable object of (template parameter) type `CONVERTIBLE&lowbar;TYPE`, refers to the specified `ptr` cast to a pointer to the (template parameter) type `ELEMENT&lowbar;TYPE`, and uses the specified `deleter` to delete the shared object when all references have been released&period; 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&colon;&colon;Allocator` or `bslma&colon;&colon;SharedPtrRep`&semi; if `DELETER` is a class derived from `bslma&colon;&colon;allocator`, create a shared pointer as if calling the constructor&colon; &grave; template &lt;class CONVERTIBLE&lowbar;TYPE&gt; shared&lowbar;ptr(CONVERTIBLE&lowbar;TYPE &ast;ptr, BloombergLP&colon;&colon;bslma&colon;&colon;Allocator &ast;basicAllocator)&semi; &grave; If `DELETER` is a class derived from `bslma&colon;&colon;SharedPtrRep`, create a shared pointer as if calling the constructor&colon; &grave; shared&lowbar;ptr(ELEMENT&lowbar;TYPE &ast;ptr, BloombergLP&colon;&colon;bslma&colon;&colon;SharedPtrRep &ast;rep)&semi; &grave; If `DELETER` does not derive from either `bslma&colon;&colon;Allocator` or `BloombergLP&colon;&colon;bslma&colon;&colon;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&period;e&period;, `deleter&hyphen;&gt;deleteObject(ptr)` will be called to delete the shared object)&period; (See the &quot;Deleters&quot; section in the component&hyphen;level documentation&period;) If `CONVERTIBLE&lowbar;TYPE &ast;` is not implicitly convertible to `ELEMENT&lowbar;TYPE &ast;`, then a compiler diagnostic will be emitted indicating the error&period; If `ptr` is 0, then the null pointer will be reference counted, and the deleter will be called when the last reference is destroyed&period; If an exception is thrown when allocating storage for the internal representation, then `deleter(ptr)` will be called&period; Note that this method is a BDE extension and not part of the C&plus;&plus; standard interface&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class CONVERTIBLE&lowbar;TYPE,
    class DELETER&gt;
xref:bsl/shared_ptr-0a/2constructor-0d5.adoc[shared&lowbar;ptr](
    CONVERTIBLE&lowbar;TYPE* ptr,
    DELETER* deleter);
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-0d5.adoc[_» more&period;&period;&period;_]#

Create a shared pointer that takes ownership of the specified `rep` and refers to the modifiable object at the specified `ptr` address&period; The number of references to `rep` is _NOT_ incremented&period; The behavior is undefined unless `rep` was previously obtained from an existing `shared&lowbar;ptr`, `rep&hyphen;&gt;disposeObject` has not been called, and `rep&hyphen;&gt;numReferences() &gt; 0`&period; Note that this constructor is intended for use by `weak&lowbar;ptr&colon;&colon;lock`, and it would be surprising to find another client&period; This solves an obscure problem that arises from unusual use of classes derived from `enable&lowbar;shared&lowbar;from&lowbar;this`&period; 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&lowbar;ptr` object releases the shared object from its management&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/shared_ptr-0a/2constructor-000.adoc[shared&lowbar;ptr](
    ELEMENT&lowbar;TYPE* ptr,
    xref:BloombergLP/bslma/SharedPtrRep.adoc[BloombergLP::bslma::SharedPtrRep]* rep,
    xref:BloombergLP/bslstl/SharedPtr_RepFromExistingSharedPtr.adoc[BloombergLP::bslstl::SharedPtr&lowbar;RepFromExistingSharedPtr]);
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-000.adoc[_» more&period;&period;&period;_]#

Create a shared pointer that reference&hyphen;counts the null pointer, and calls the specified `deleter` with a null pointer (i&period;e&period;, invokes `deleter((ELEMENT&lowbar;TYPE &ast;)0)`) when the last shared reference is destroyed&period; The specified `nullPointerLiteral` is not used&period; Optionally specify a `basicAllocator` to allocate and deallocate the internal representation of the shared pointer (including a copy of `deleter`)&period; If `basicAllocator` is 0, the currently installed default allocator is used&period; If an exception is thrown when allocating storage for the internal representation, then `deleter((ELEMENT&lowbar;TYPE &ast;)0)` will be called&period; 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&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class DELETER&gt;
xref:bsl/shared_ptr-0a/2constructor-088.adoc[shared&lowbar;ptr](
    xref:bsl/nullptr_t-08.adoc[nullptr&lowbar;t] nullPointerLiteral,
    DELETER deleter,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator = 0);
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-088.adoc[_» more&period;&period;&period;_]#

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


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class CONVERTIBLE&lowbar;TYPE,
    class DELETER&gt;
xref:bsl/shared_ptr-0a/2constructor-038.adoc[shared&lowbar;ptr](
    CONVERTIBLE&lowbar;TYPE* ptr,
    DELETER deleter,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator = 0);
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-038.adoc[_» more&period;&period;&period;_]#

Create a shared pointer that reference&hyphen;counts the null pointer, calls the specified `deleter` with a null pointer (i&period;e&period;, invokes `deleter((ELEMENT&lowbar;TYPE &ast;)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`)&period; The (template parameter) type `DELETER` shall be either a function pointer or a function&hyphen;like deleter (See the &quot;Deleters&quot; section in the component&hyphen; level documentation)&period; The (template parameter) type `ALLOCATOR` shall satisfy the Allocator requirements of the C&plus;&plus; standard (C&plus;&plus;11 17&period;6&period;3&period;5, &lsqb;allocator&period;requirements&rsqb;)&period; The specified `nullPointerLiteral` is not used&period; If an exception is thrown when allocating storage for the internal representation, then `deleter((ELEMENT&lowbar;TYPE &ast;)0)` will be called&period; 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&period; Note that the final dummy parameter is a simple SFINAE check that the `ALLOCATOR` type probably satisfies the standard allocator requirements&semi; in particular, it will not match pointer types, so any pointers to `bslma&colon;&colon;Allocator` derived classes will dispatch to the constructor above this, and not be greedily matched to a generic type parameter&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class DELETER,
    class ALLOCATOR&gt;
xref:bsl/shared_ptr-0a/2constructor-0a.adoc[shared&lowbar;ptr](
    xref:bsl/nullptr_t-08.adoc[nullptr&lowbar;t] nullPointerLiteral,
    DELETER deleter,
    ALLOCATOR basicAllocator,
    ALLOCATOR::value&lowbar;type* = 0);
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-0a.adoc[_» more&period;&period;&period;_]#

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


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class CONVERTIBLE&lowbar;TYPE,
    class DELETER,
    class ALLOCATOR&gt;
xref:bsl/shared_ptr-0a/2constructor-0dd.adoc[shared&lowbar;ptr](
    CONVERTIBLE&lowbar;TYPE* ptr,
    DELETER deleter,
    ALLOCATOR basicAllocator,
    ALLOCATOR::value&lowbar;type* = 0);
----

[.small]#xref:bsl/shared_ptr-0a/2constructor-0dd.adoc[_» more&period;&period;&period;_]#


[.small]#Created with https://www.mrdocs.com[MrDocs]#
