[#absl-ShareUniquePtr]
= xref:absl.adoc[absl]::ShareUniquePtr
:relfileprefix: ../
:mrdocs:

Convert a `std&colon;&colon;unique&lowbar;ptr` into a `std&colon;&colon;shared&lowbar;ptr`&period;

== Synopsis

Declared in `&lt;absl&sol;memory&sol;memory&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    typename T,
    typename D&gt;
std::shared&lowbar;ptr&lt;T&gt;
ShareUniquePtr(std::unique&lowbar;ptr&lt;T, D&gt;&& ptr);
----

== Description

Adopts a `std&colon;&colon;unique&lowbar;ptr` rvalue and returns a `std&colon;&colon;shared&lowbar;ptr` of deduced type&period; Ownership (if any) of the held value is transferred to the returned shared pointer&period;

Example&colon;

auto up &equals; std&colon;&colon;make&lowbar;unique&lt;int&gt;(10)&semi; auto sp &equals; absl&colon;&colon;ShareUniquePtr(std&colon;&colon;move(up))&semi; &sol;&sol; shared&lowbar;ptr&lt;int&gt; CHECK&lowbar;EQ(&ast;sp, 10)&semi; CHECK(up &equals;&equals; nullptr)&semi;

Note that this conversion is correct even when T is an array type, and more generally it works for _any_ deleter of the `unique&lowbar;ptr` (single&hyphen;object deleter, array deleter, or any custom deleter), since the deleter is adopted by the shared pointer as well&period; The deleter is copied (unless it is a reference)&period;

Implements the resolution of http://wg21.link/lwg2415[LWG 2415], by which a null shared pointer does not attempt to call the deleter&period;

== Return Value

A `std&colon;&colon;shared&lowbar;ptr` adopting the value held by `ptr`&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *ptr*
| The unique pointer to convert&semi; its ownership is transferred&period;
|===


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