[#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;_]#

Copy&hyphen;construct a `shared&lowbar;ptr` from `original`&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&lowbar;ptr` sharing ownership with a compatible `other`&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;_]#

Move&hyphen;construct a `shared&lowbar;ptr` from a compatible `other`&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] nullPointerLiteral) noexcept;
----

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

Move&hyphen;construct a `shared&lowbar;ptr` from `original`&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&lowbar;ptr` from a `weak&lowbar;ptr`, or empty if expired&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&lowbar;ptr` that manages the object at `ptr`&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;


[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&lowbar;ptr` from the specified arguments&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&lowbar;ptr` from the specified arguments&period;


[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&lowbar;ptr` by adopting ownership from a managed pointer&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&lowbar;ptr` from the specified arguments&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 an aliased `shared&lowbar;ptr` sharing ownership with `source`&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&lowbar;ptr` managing `ptr` using `basicAllocator`&period;


[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&lowbar;ptr` by adopting ownership from a unique pointer&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&lowbar;ptr` managing `ptr` with a custom deleter&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&lowbar;ptr` from the specified arguments&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] tag);
----

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

Create a `shared&lowbar;ptr` owning null with a deleter&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&lowbar;ptr` managing `ptr` with a deleter and allocator&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&lowbar;ptr` owning null with a deleter and allocator&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* sfinae = 0);
----

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

Create a `shared&lowbar;ptr` managing `ptr` with a custom deleter&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* sfinae = 0);
----

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

== Parameters

[cols="1,4"]
|===
| Name| Description
| *original*
| source object to copy or move from
| *other*
| other pointer to compare or share ownership with
| *nullPointerLiteral*
| null&hyphen;pointer literal (unused&semi; selects this overload)
| *ptr*
| pointer to the object to manage or refer to
| *basicAllocator*
| allocator used to supply memory
| *rep*
| shared&hyphen;pointer representation object
| *managedPtr*
| managed pointer whose ownership is transferred
| *source*
| source shared pointer that supplies ownership
| *object*
| object to refer to while sharing ownership with `source`
| *adoptee*
| unique pointer whose ownership is transferred
| *deleter*
| deleter invoked when the last shared reference is released
| *tag*
| tag selecting the existing&hyphen;representation constructor
| *sfinae*
| unused SFINAE discriminator
|===


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