[#BloombergLP-bslma-ManagedPtr-0fa-2constructor-0c]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslma.adoc[bslma]::xref:BloombergLP/bslma/ManagedPtr-0fa.adoc[ManagedPtr]::ManagedPtr
:relfileprefix: ../../../
:mrdocs:

Constructors

== Synopses

Declared in `&lt;bslma&lowbar;managedptr&period;h&gt;`

Create an empty managed pointer&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-01f.adoc[ManagedPtr]();
----

[.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-01f.adoc[_» more&period;&period;&period;_]#

Create a managed pointer having the same target object as the specified `original`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-008.adoc[ManagedPtr](xref:BloombergLP/bslma/ManagedPtr-0fa.adoc[ManagedPtr]& original) noexcept;
----

[.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-008.adoc[_» more&period;&period;&period;_]#

Create an empty managed pointer from a null pointer literal&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-06.adoc[ManagedPtr](xref:bsl/nullptr_t-08.adoc[bsl::nullptr&lowbar;t]);
----

[.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-06.adoc[_» more&period;&period;&period;_]#

Create a managed pointer having the same target object as the managed pointer referenced by the specified `ref`, transfer ownership of the managed object owned by the managed pointer referenced by `ref`, and reset the managed pointer referenced by `ref` to empty&period; This constructor is used to create a managed pointer from a managed pointer rvalue, or from a managed pointer to a &quot;compatible&quot; type, where &quot;compatible&quot; means a built&hyphen;in conversion from `COMPATIBLE&lowbar;TYPE &ast;` to `TARGET&lowbar;TYPE &ast;` is defined, e&period;g&period;, `derived &ast;` to `base &ast;`, `T &ast;` to `const T &ast;`, or `T &ast;` to `void &ast;`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0b.adoc[ManagedPtr](xref:BloombergLP/bslma/ManagedPtr_Ref.adoc[ManagedPtr&lowbar;Ref&lt;TARGET&lowbar;TYPE&gt;] ref) noexcept;
----

[.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0b.adoc[_» more&period;&period;&period;_]#

Create a managed pointer having the same target object as the specified `original`, transfer ownership of the object managed by `original` (if any) to this managed pointer, and reset `original` to empty&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-052c.adoc[ManagedPtr](xref:BloombergLP/bslmf/MovableRef.adoc[bslmf::MovableRef&lt;ManagedPtr&gt;] original) noexcept;
----

[.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-052c.adoc[_» more&period;&period;&period;_]#

Create a managed pointer having a target object referenced by the specified `ptr`, owning the managed object `&ast;ptr`, and having a deleter that will call `delete ptr` to destroy the managed object when invoked (e&period;g&period;, when this managed pointer object is destroyed), unless `0 &equals;&equals; ptr`, in which case create an empty managed pointer&period; The deleter will invoke the destructor of `MANAGED&lowbar;TYPE` rather than the destructor of `TARGET&lowbar;TYPE`&period; This constructor will not compile unless `MANAGED&lowbar;TYPE &ast;` is convertible to `TARGET&lowbar;TYPE &ast;`&period; Note that this behavior allows `ManagedPtr` to be defined for `void` pointers, and to call the correct destructor for the managed object, even if the destructor for `TARGET&lowbar;TYPE` is not declared as `virtual`&period; The behavior is undefined unless the managed object (if any) can be destroyed by `delete`, or if the lifetime of the managed object is already managed by another object&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class MANAGED&lowbar;TYPE&gt;
explicit
xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-083.adoc[ManagedPtr](MANAGED&lowbar;TYPE* ptr);
----

[.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-083.adoc[_» more&period;&period;&period;_]#

Create an empty managed pointer&period; Note that this constructor is necessary to match null&hyphen;pointer literal arguments, in order to break ambiguities and provide valid type deduction with the other constructor templates in this class&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
explicit
xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-012.adoc[ManagedPtr](
    xref:bsl/nullptr_t-08.adoc[bsl::nullptr&lowbar;t],
    xref:bsl/nullptr_t-08.adoc[bsl::nullptr&lowbar;t]);
----

[.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-012.adoc[_» more&period;&period;&period;_]#

Create an empty managed pointer&period; Note that the specified `factory` is ignored, as an empty managed pointer does not call its deleter&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class FACTORY&lowbar;TYPE&gt;
xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0a.adoc[ManagedPtr](
    xref:bsl/nullptr_t-08.adoc[bsl::nullptr&lowbar;t],
    FACTORY&lowbar;TYPE* factory);
----

[.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0a.adoc[_» more&period;&period;&period;_]#

Create a managed pointer that takes ownership of the object managed by the specified `alias`, but which uses the specified `ptr` to refer to its target object, unless `0 &equals;&equals; ptr`, in which case create an empty managed pointer&period; Reset `alias` to empty if ownership of its managed object is transferred&period; The behavior is undefined if `alias` is empty, but `0 !&equals; ptr`&period; Note that destroying or re&hyphen;assigning a managed pointer created with this constructor will destroy the object originally managed by `alias` (unless `release` is called first)&semi; the destructor for `&ast;ptr` is not called directly&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class ALIASED&lowbar;TYPE&gt;
xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0524.adoc[ManagedPtr](
    xref:BloombergLP/bslma/ManagedPtr-0fa.adoc[ManagedPtr&lt;ALIASED&lowbar;TYPE&gt;]& alias,
    TARGET&lowbar;TYPE* ptr);
----

[.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0524.adoc[_» more&period;&period;&period;_]#

Move&hyphen;construct an aliasing managed pointer from the specified `alias` and `ptr`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class ALIASED&lowbar;TYPE&gt;
xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0d3.adoc[ManagedPtr](
    xref:BloombergLP/bslma/ManagedPtr-0fa.adoc[ManagedPtr&lt;ALIASED&lowbar;TYPE&gt;]&& alias,
    TARGET&lowbar;TYPE* ptr);
----

[.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0d3.adoc[_» more&period;&period;&period;_]#

Move&hyphen;construct from a compatible managed pointer, transferring ownership from `original`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class BDE&lowbar;OTHER&lowbar;TYPE&gt;
xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-09.adoc[ManagedPtr](
    xref:BloombergLP/bslma/ManagedPtr-0fa.adoc[ManagedPtr&lt;BDE&lowbar;OTHER&lowbar;TYPE&gt;]&& original,
    xref:BloombergLP/bslma/ManagedPtr_TraitConstraint.adoc[ManagedPtr&lowbar;TraitConstraint] = ManagedPtr&lowbar;TraitConstraint()) noexcept
requires bsl&colon;&colon;is&lowbar;convertible&lt;BDE&lowbar;OTHER&lowbar;TYPE &ast;, TARGET&lowbar;TYPE &ast;&gt;&colon;&colon;value;
----

[.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-09.adoc[_» more&period;&period;&period;_]#

Create a managed pointer having a target object referenced by the specified `ptr`, owning the managed object `&ast;ptr`, and having a deleter that will call `factory&hyphen;&gt;deleteObject(ptr)` to destroy the managed object when invoked (e&period;g&period;, when this managed pointer object is destroyed), unless `0 &equals;&equals; ptr`, in which case create an empty managed pointer&period; The deleter will invoke the destructor of `MANAGED&lowbar;TYPE` rather than the destructor of `TARGET&lowbar;TYPE`&period; This constructor will not compile unless `MANAGED&lowbar;TYPE &ast;` is convertible to `TARGET&lowbar;TYPE &ast;`&period; The behavior is undefined unless the managed object (if any) can be destroyed by the specified `factory`, or if `0 &equals;&equals; factory &amp;&amp; 0 !&equals; ptr`, or if the lifetime of the managed object is already managed by another object&period; Note that `bslma&colon;&colon;Allocator`, and any class publicly and unambiguously derived from `bslma&colon;&colon;Allocator`, meets the requirements for `FACTORY&lowbar;TYPE`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class MANAGED&lowbar;TYPE,
    class FACTORY&lowbar;TYPE&gt;
xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-07.adoc[ManagedPtr](
    MANAGED&lowbar;TYPE* ptr,
    FACTORY&lowbar;TYPE* factory);
----

[.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-07.adoc[_» more&period;&period;&period;_]#

Create a managed pointer having a target object referenced by the specified `ptr`, owning the managed object `&ast;ptr`, and having a deleter that will invoke the specified `deleter` with the address of the currently managed object, and with the specified `cookie` (that the deleter can use for its own purposes), unless `0 &equals;&equals; ptr`, in which case create an empty managed pointer&period; The behavior is undefined if `ptr` is already managed by another object, or if `0 &equals;&equals; deleter &amp;&amp; 0 !&equals; ptr`&period; Note that this constructor is required only because the deprecated overloads cause an ambiguity in its absence&semi; it should be removed when the deprecated overloads are removed&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0e.adoc[ManagedPtr](
    TARGET&lowbar;TYPE* ptr,
    void* cookie,
    xref:BloombergLP/bslma/ManagedPtr-0fa/DeleterFunc.adoc[DeleterFunc] deleter);
----

[.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0e.adoc[_» more&period;&period;&period;_]#

Create a managed pointer having a target object referenced by the specified `ptr`, owning the managed object `&ast;ptr`, and having a deleter that will invoke the specified `deleter` with the address of the currently managed object, and with the specified `cookie` (that the deleter can use for its own purposes), unless `0 &equals;&equals; ptr`, in which case create an empty managed pointer&period; This constructor will not compile unless `MANAGED&lowbar;TYPE &ast;` is convertible to `TARGET&lowbar;TYPE &ast;`&period; The deleter will invoke the destructor of `MANAGED&lowbar;TYPE` rather than the destructor of `TARGET&lowbar;TYPE`&period; The behavior is undefined if `ptr` is already managed by another object, or if `0 &equals;&equals; deleter &amp;&amp; 0 !&equals; ptr`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class MANAGED&lowbar;TYPE&gt;
xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-006.adoc[ManagedPtr](
    MANAGED&lowbar;TYPE* ptr,
    void* cookie,
    xref:BloombergLP/bslma/ManagedPtr-0fa/DeleterFunc.adoc[DeleterFunc] deleter);
----

[.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-006.adoc[_» more&period;&period;&period;_]#

Create a managed pointer having a target object referenced by the specified `ptr`, owning the managed object `&ast;ptr`, and having a deleter that will invoke the specified `deleter` with the address of the currently managed object, and with the specified `cookie` (that the deleter can use for its own purposes), unless `0 &equals;&equals; ptr`, in which case create an empty managed pointer&period; This constructor will not compile unless `MANAGED&lowbar;TYPE &ast;` is convertible to `TARGET&lowbar;TYPE &ast;`, and `MANAGED&lowbar;TYPE &ast;` is convertible to `MANAGED&lowbar;BASE &ast;`&period; The deleter will invoke the destructor of `MANAGED&lowbar;TYPE` rather than the destructor of `TARGET&lowbar;TYPE`&period; The behavior is undefined if `ptr` is already managed by another object, or if `0 &equals;&equals; deleter &amp;&amp; 0 !&equals; ptr`&period; Note that this constructor is needed only to avoid ambiguous type deductions when passing a null pointer literal as the `cookie` when the user passes a deleter taking a type other than `void &ast;` for its object type&period; Also note that this function is _deprecated_ as it relies on undefined compiler behavior for its implementation (that luckily performs as required on every platform supported by BDE)&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class MANAGED&lowbar;TYPE,
    class MANAGED&lowbar;BASE&gt;
xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-086.adoc[ManagedPtr](
    MANAGED&lowbar;TYPE* ptr,
    void* cookie,
    void(* deleter)(MANAGED&lowbar;BASE*, void*));
----

[.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-086.adoc[_» more&period;&period;&period;_]#

Create a managed pointer having a target object referenced by the specified `ptr`, owning the managed object `&ast;ptr`, and having a deleter that will invoke the specified `deleter` with the address of the currently managed object, and with the specified `cookie` (that the deleter can use for its own purposes), unless `0 &equals;&equals; ptr`, in which case create an empty managed pointer&period; This constructor will not compile unless `MANAGED&lowbar;TYPE &ast;` is convertible to `TARGET&lowbar;TYPE &ast;`, and `MANAGED&lowbar;TYPE &ast;` is convertible to `MANAGED&lowbar;BASE &ast;`&period; The deleter will invoke the destructor of `MANAGED&lowbar;TYPE` rather than the destructor of `TARGET&lowbar;TYPE`&period; The behavior is undefined if `ptr` is already managed by another object, or if `0 &equals;&equals; deleter &amp;&amp; 0 !&equals; ptr`&period; Note that this function is _deprecated_ as it relies on undefined compiler behavior for its implementation (that luckily performs as required on every platform supported by BDE)&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class MANAGED&lowbar;TYPE,
    class MANAGED&lowbar;BASE,
    class COOKIE&lowbar;TYPE,
    class COOKIE&lowbar;BASE&gt;
xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0d9.adoc[ManagedPtr](
    MANAGED&lowbar;TYPE* ptr,
    COOKIE&lowbar;TYPE* cookie,
    void(* deleter)(MANAGED&lowbar;BASE*, COOKIE&lowbar;BASE*));
----

[.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0d9.adoc[_» more&period;&period;&period;_]#


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