Topic: emplace-like function for std::unique_ptr


Author: Victor Dyachenko <victor.dyachenko@gmail.com>
Date: Wed, 16 Nov 2016 02:58:53 -0800 (PST)
Raw View
------=_Part_4205_1870238395.1479293933829
Content-Type: multipart/alternative;
 boundary="----=_Part_4206_2043819744.1479293933830"

------=_Part_4206_2043819744.1479293933830
Content-Type: text/plain; charset=UTF-8

Assume we have a variable like this:

std::unique_ptr<some_long_and_ugly_name> p;

If it is a local variable then it can be constructed as

auto p = std::make_unique<some_long_and_ugly_name>(...);

without duplication of template argument (some_long_and_ugly_name).

But if it is member variable, we can't avoid duplication:

class C
{
    std::unique_ptr<some_long_and_ugly_name> p;
    C()
    {
        p = std::make_unique<some_long_and_ugly_name>(...);
    }
};

If std::optional is used instead of std::unique_ptr then duplication can be
avoided using emplace() for object construction:

class C
{
    std::optional<some_long_and_ugly_name> p;
    C()
    {
        p.emplace(...); // <-- no template argument duplication here
    }
};

It would be nice to similar function for std::unique_ptr. The name
"emplace" is not appropriate here, ptr itself doesn't contain constructed
object. May be "create" or "new_"? And this function can provide strong
exception guarantee, so effect of its usage won't differ from make_unique
case.

class C
{
    std::unique_ptr<some_long_and_ugly_name> p;
    C()
    {
        p.new_(...);
    }
};

Any thoughts/comments/suggestions?

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/437f3bb8-6c04-4107-943c-32908b54d82e%40isocpp.org.

------=_Part_4206_2043819744.1479293933830
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Assume we have a variable like this:<br><br><div style=3D"=
background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); bor=
der-style: solid; border-width: 1px; overflow-wrap: break-word;" class=3D"p=
rettyprint"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">std</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">unique_ptr</span><span style=3D"colo=
r: #080;" class=3D"styled-by-prettify">&lt;some_long_and_ugly_name&gt;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> p</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><b=
r>If it is a local variable then it can be constructed as<br><br><div style=
=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187);=
 border-style: solid; border-width: 1px; overflow-wrap: break-word;" class=
=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subprettyprint">=
<span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> p </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">make_unique</span><span style=3D"color: #080;" cl=
ass=3D"styled-by-prettify">&lt;some_long_and_ugly_name&gt;</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">(...);</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><=
br>without duplication of template argument (<span style=3D"font-family: co=
urier new,monospace;">some_long_and_ugly_name</span>).<br><br>But if it is =
member variable, we can&#39;t avoid duplication:<br><br><div style=3D"backg=
round-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-s=
tyle: solid; border-width: 1px; overflow-wrap: break-word;" class=3D"pretty=
print"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">class</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> C<br></span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 std</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">unique_ptr</span><span style=3D"color: #08=
0;" class=3D"styled-by-prettify">&lt;some_long_and_ugly_name&gt;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> p</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 C</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 p </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">make_unique</span><span style=3D"c=
olor: #080;" class=3D"styled-by-prettify">&lt;some_long_and_ugly_name&gt;</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">(...);</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code></di=
v><br>If <span style=3D"font-family: courier new,monospace;">std::optional<=
/span> is used instead of <span style=3D"font-family: courier new,monospace=
;">std::unique_ptr</span> then duplication can be avoided using <span style=
=3D"font-family: courier new,monospace;">emplace()</span> for object constr=
uction:<br><br><div style=3D"background-color: rgb(250, 250, 250); border-c=
olor: rgb(187, 187, 187); border-style: solid; border-width: 1px; overflow-=
wrap: break-word;" class=3D"prettyprint"><code class=3D"prettyprint"><div c=
lass=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> C<br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">{<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0 std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">optional=
</span><span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;some_l=
ong_and_ugly_name&gt;</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> p</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 C</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 p</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">emplace</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">(...);</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">// &lt=
;-- no template argument duplication here</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br></span></div></code></div><br>It would be nice to simil=
ar function for <span style=3D"font-family: courier new,monospace;">std::un=
ique_ptr</span>. The name &quot;emplace&quot; is not appropriate here, ptr =
itself doesn&#39;t contain constructed object. May be &quot;create&quot; or=
 &quot;new_&quot;? And this function can provide strong exception guarantee=
, so effect of its usage won&#39;t differ from make_unique case.<br><br><di=
v style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187=
, 187); border-style: solid; border-width: 1px; overflow-wrap: break-word;"=
 class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subprettyp=
rint"><span style=3D"color: #008;" class=3D"styled-by-prettify">class</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> C<br></span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 std</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">unique_ptr</span><span st=
yle=3D"color: #080;" class=3D"styled-by-prettify">&lt;some_long_and_ugly_na=
me&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> p</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 C</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 p</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">new_</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">(...);</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0=
 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><b=
r>Any thoughts/comments/suggestions?<br></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/437f3bb8-6c04-4107-943c-32908b54d82e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/437f3bb8-6c04-4107-943c-32908b54d82e=
%40isocpp.org</a>.<br />

------=_Part_4206_2043819744.1479293933830--

------=_Part_4205_1870238395.1479293933829--

.


Author: "'Adam Foxman' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Wed, 16 Nov 2016 19:24:13 +0000
Raw View
--_000_CY1PR0301MB1596BCF64E01B0ABDEB503D9B3BE0CY1PR0301MB1596_
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Are the intended semantics similar to reset(), where an existing object is =
replaced?

From: Victor Dyachenko [mailto:victor.dyachenko@gmail.com]
Sent: Wednesday, November 16, 2016 2:59 AM
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Subject: [std-proposals] emplace-like function for std::unique_ptr

Assume we have a variable like this:
std::unique_ptr<some_long_and_ugly_name> p;

If it is a local variable then it can be constructed as
auto p =3D std::make_unique<some_long_and_ugly_name>(...);

without duplication of template argument (some_long_and_ugly_name).

But if it is member variable, we can't avoid duplication:
class C
{
    std::unique_ptr<some_long_and_ugly_name> p;
    C()
    {
        p =3D std::make_unique<some_long_and_ugly_name>(...);
    }
};

If std::optional is used instead of std::unique_ptr then duplication can be=
 avoided using emplace() for object construction:
class C
{
    std::optional<some_long_and_ugly_name> p;
    C()
    {
        p.emplace(...); // <-- no template argument duplication here
    }
};

It would be nice to similar function for std::unique_ptr. The name "emplace=
" is not appropriate here, ptr itself doesn't contain constructed object. M=
ay be "create" or "new_"? And this function can provide strong exception gu=
arantee, so effect of its usage won't differ from make_unique case.
class C
{
    std::unique_ptr<some_long_and_ugly_name> p;
    C()
    {
        p.new_(...);
    }
};

Any thoughts/comments/suggestions?
--
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org<mailto:std-proposals+unsubscri=
be@isocpp.org>.
To post to this group, send email to std-proposals@isocpp.org<mailto:std-pr=
oposals@isocpp.org>.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/437f3bb8-6c04-4107-943c-32908b54d82e%40isocpp.or=
g<https://na01.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fgroups=
..google.com%2Fa%2Fisocpp.org%2Fd%2Fmsgid%2Fstd-proposals%2F437f3bb8-6c04-41=
07-943c-32908b54d82e%2540isocpp.org%3Futm_medium%3Demail%26utm_source%3Dfoo=
ter&data=3D02%7C01%7Cafoxman%40microsoft.com%7Cc6c8d1194d3d4944d2a908d40e0f=
8fb9%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636148907381955307&sdata=
=3Dof%2F3RwR7IzM%2FjqrdjrfYFSuomVwVX0ZFlag6n2cfIe0%3D&reserved=3D0>.

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CY1PR0301MB1596BCF64E01B0ABDEB503D9B3BE0%40CY1PR=
0301MB1596.namprd03.prod.outlook.com.

--_000_CY1PR0301MB1596BCF64E01B0ABDEB503D9B3BE0CY1PR0301MB1596_
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8">
<meta name=3D"Generator" content=3D"Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
 {font-family:"Cambria Math";
 panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
 {font-family:Calibri;
 panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
 {margin:0in;
 margin-bottom:.0001pt;
 font-size:11.0pt;
 font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
 {mso-style-priority:99;
 color:blue;
 text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
 {mso-style-priority:99;
 color:purple;
 text-decoration:underline;}
code
 {mso-style-priority:99;
 font-family:"Courier New";}
p.msonormal0, li.msonormal0, div.msonormal0
 {mso-style-name:msonormal;
 mso-margin-top-alt:auto;
 margin-right:0in;
 mso-margin-bottom-alt:auto;
 margin-left:0in;
 font-size:11.0pt;
 font-family:"Calibri",sans-serif;}
span.styled-by-prettify
 {mso-style-name:styled-by-prettify;}
span.EmailStyle21
 {mso-style-type:personal-reply;
 font-family:"Calibri",sans-serif;
 color:windowtext;}
..MsoChpDefault
 {mso-style-type:export-only;
 font-family:"Calibri",sans-serif;}
@page WordSection1
 {size:8.5in 11.0in;
 margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
 {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=3D"EN-US" link=3D"blue" vlink=3D"purple">
<div class=3D"WordSection1">
<p class=3D"MsoNormal">Are the intended semantics similar to reset(), where=
 an existing object is replaced?<o:p></o:p></p>
<p class=3D"MsoNormal"><a name=3D"_MailEndCompose"><o:p>&nbsp;</o:p></a></p=
>
<span style=3D"mso-bookmark:_MailEndCompose"></span>
<p class=3D"MsoNormal"><b>From:</b> Victor Dyachenko [mailto:victor.dyachen=
ko@gmail.com]
<br>
<b>Sent:</b> Wednesday, November 16, 2016 2:59 AM<br>
<b>To:</b> ISO C&#43;&#43; Standard - Future Proposals &lt;std-proposals@is=
ocpp.org&gt;<br>
<b>Subject:</b> [std-proposals] emplace-like function for std::unique_ptr<o=
:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt">Assume we have a vari=
able like this:<o:p></o:p></p>
<div style=3D"border:solid #BBBBBB 1.0pt;padding:0in 0in 0in 0in;overflow-w=
rap: break-word">
<div>
<p class=3D"MsoNormal" style=3D"background:#FAFAFA"><span class=3D"styled-b=
y-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;Courier New&q=
uot;;color:black">std</span></span><span class=3D"styled-by-prettify"><span=
 style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#66660=
0">::</span></span><span class=3D"styled-by-prettify"><span style=3D"font-s=
ize:10.0pt;font-family:&quot;Courier New&quot;;color:black">unique_ptr</spa=
n></span><span class=3D"styled-by-prettify"><span style=3D"font-size:10.0pt=
;font-family:&quot;Courier New&quot;;color:#008800">&lt;some_long_and_ugly_=
name&gt;</span></span><span class=3D"styled-by-prettify"><span style=3D"fon=
t-size:10.0pt;font-family:&quot;Courier New&quot;;color:black">
 p</span></span><span class=3D"styled-by-prettify"><span style=3D"font-size=
:10.0pt;font-family:&quot;Courier New&quot;;color:#666600">;</span></span><=
span style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;"><o:p></=
o:p></span></p>
</div>
</div>
<p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt"><br>
If it is a local variable then it can be constructed as<o:p></o:p></p>
<div style=3D"border:solid #BBBBBB 1.0pt;padding:0in 0in 0in 0in;overflow-w=
rap: break-word">
<div>
<p class=3D"MsoNormal" style=3D"background:#FAFAFA"><span class=3D"styled-b=
y-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;Courier New&q=
uot;;color:#000088">auto</span></span><span class=3D"styled-by-prettify"><s=
pan style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:bla=
ck">
 p </span></span><span class=3D"styled-by-prettify"><span style=3D"font-siz=
e:10.0pt;font-family:&quot;Courier New&quot;;color:#666600">=3D</span></spa=
n><span class=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-f=
amily:&quot;Courier New&quot;;color:black"> std</span></span><span class=3D=
"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;Cour=
ier New&quot;;color:#666600">::</span></span><span class=3D"styled-by-prett=
ify"><span style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;co=
lor:black">make_unique</span></span><span class=3D"styled-by-prettify"><spa=
n style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#0088=
00">&lt;some_long_and_ugly_name&gt;</span></span><span class=3D"styled-by-p=
rettify"><span style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot=
;;color:#666600">(...);</span></span><span style=3D"font-size:10.0pt;font-f=
amily:&quot;Courier New&quot;"><o:p></o:p></span></p>
</div>
</div>
<p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt"><br>
without duplication of template argument (<span style=3D"font-family:&quot;=
Courier New&quot;">some_long_and_ugly_name</span>).<br>
<br>
But if it is member variable, we can't avoid duplication:<o:p></o:p></p>
<div style=3D"border:solid #BBBBBB 1.0pt;padding:0in 0in 0in 0in;overflow-w=
rap: break-word">
<div>
<p class=3D"MsoNormal" style=3D"background:#FAFAFA"><span class=3D"styled-b=
y-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;Courier New&q=
uot;;color:#000088">class</span></span><span class=3D"styled-by-prettify"><=
span style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:bl=
ack">
 C</span></span><span style=3D"font-size:10.0pt;font-family:&quot;Courier N=
ew&quot;;color:black"><br>
</span><span class=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;f=
ont-family:&quot;Courier New&quot;;color:#666600">{</span></span><span styl=
e=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black"><br>
<span class=3D"styled-by-prettify">&nbsp; &nbsp; std</span></span><span cla=
ss=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot=
;Courier New&quot;;color:#666600">::</span></span><span class=3D"styled-by-=
prettify"><span style=3D"font-size:10.0pt;font-family:&quot;Courier New&quo=
t;;color:black">unique_ptr</span></span><span class=3D"styled-by-prettify">=
<span style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#=
008800">&lt;some_long_and_ugly_name&gt;</span></span><span class=3D"styled-=
by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;Courier New&=
quot;;color:black">
 p</span></span><span class=3D"styled-by-prettify"><span style=3D"font-size=
:10.0pt;font-family:&quot;Courier New&quot;;color:#666600">;</span></span><=
span style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:bl=
ack"><br>
<span class=3D"styled-by-prettify">&nbsp; &nbsp; C</span></span><span class=
=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;C=
ourier New&quot;;color:#666600">()</span></span><span style=3D"font-size:10=
..0pt;font-family:&quot;Courier New&quot;;color:black"><br>
<span class=3D"styled-by-prettify">&nbsp; &nbsp; </span></span><span class=
=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;C=
ourier New&quot;;color:#666600">{</span></span><span style=3D"font-size:10.=
0pt;font-family:&quot;Courier New&quot;;color:black"><br>
<span class=3D"styled-by-prettify">&nbsp; &nbsp; &nbsp; &nbsp; p </span></s=
pan><span class=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font=
-family:&quot;Courier New&quot;;color:#666600">=3D</span></span><span class=
=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;C=
ourier New&quot;;color:black">
 std</span></span><span class=3D"styled-by-prettify"><span style=3D"font-si=
ze:10.0pt;font-family:&quot;Courier New&quot;;color:#666600">::</span></spa=
n><span class=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-f=
amily:&quot;Courier New&quot;;color:black">make_unique</span></span><span c=
lass=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&qu=
ot;Courier New&quot;;color:#008800">&lt;some_long_and_ugly_name&gt;</span><=
/span><span class=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;fo=
nt-family:&quot;Courier New&quot;;color:#666600">(...);</span></span><span =
style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black">=
<br>
<span class=3D"styled-by-prettify">&nbsp; &nbsp; </span></span><span class=
=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;C=
ourier New&quot;;color:#666600">}</span></span><span style=3D"font-size:10.=
0pt;font-family:&quot;Courier New&quot;;color:black"><br>
</span><span class=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;f=
ont-family:&quot;Courier New&quot;;color:#666600">};</span></span><span sty=
le=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></sp=
an></p>
</div>
</div>
<p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt"><br>
If <span style=3D"font-family:&quot;Courier New&quot;">std::optional</span>=
 is used instead of
<span style=3D"font-family:&quot;Courier New&quot;">std::unique_ptr</span> =
then duplication can be avoided using
<span style=3D"font-family:&quot;Courier New&quot;">emplace()</span> for ob=
ject construction:<o:p></o:p></p>
<div style=3D"border:solid #BBBBBB 1.0pt;padding:0in 0in 0in 0in;overflow-w=
rap: break-word">
<div>
<p class=3D"MsoNormal" style=3D"background:#FAFAFA"><span class=3D"styled-b=
y-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;Courier New&q=
uot;;color:#000088">class</span></span><span class=3D"styled-by-prettify"><=
span style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:bl=
ack">
 C</span></span><span style=3D"font-size:10.0pt;font-family:&quot;Courier N=
ew&quot;;color:black"><br>
</span><span class=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;f=
ont-family:&quot;Courier New&quot;;color:#666600">{</span></span><span styl=
e=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black"><br>
<span class=3D"styled-by-prettify">&nbsp; &nbsp; std</span></span><span cla=
ss=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot=
;Courier New&quot;;color:#666600">::</span></span><span class=3D"styled-by-=
prettify"><span style=3D"font-size:10.0pt;font-family:&quot;Courier New&quo=
t;;color:black">optional</span></span><span class=3D"styled-by-prettify"><s=
pan style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#00=
8800">&lt;some_long_and_ugly_name&gt;</span></span><span class=3D"styled-by=
-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;Courier New&qu=
ot;;color:black">
 p</span></span><span class=3D"styled-by-prettify"><span style=3D"font-size=
:10.0pt;font-family:&quot;Courier New&quot;;color:#666600">;</span></span><=
span style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:bl=
ack"><br>
<span class=3D"styled-by-prettify">&nbsp; &nbsp; C</span></span><span class=
=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;C=
ourier New&quot;;color:#666600">()</span></span><span style=3D"font-size:10=
..0pt;font-family:&quot;Courier New&quot;;color:black"><br>
<span class=3D"styled-by-prettify">&nbsp; &nbsp; </span></span><span class=
=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;C=
ourier New&quot;;color:#666600">{</span></span><span style=3D"font-size:10.=
0pt;font-family:&quot;Courier New&quot;;color:black"><br>
<span class=3D"styled-by-prettify">&nbsp; &nbsp; &nbsp; &nbsp; p</span></sp=
an><span class=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-=
family:&quot;Courier New&quot;;color:#666600">.</span></span><span class=3D=
"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;Cour=
ier New&quot;;color:black">emplace</span></span><span class=3D"styled-by-pr=
ettify"><span style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;=
;color:#666600">(...);</span></span><span class=3D"styled-by-prettify"><spa=
n style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black=
">
</span></span><span class=3D"styled-by-prettify"><span style=3D"font-size:1=
0.0pt;font-family:&quot;Courier New&quot;;color:#880000">// &lt;-- no templ=
ate argument duplication here</span></span><span style=3D"font-size:10.0pt;=
font-family:&quot;Courier New&quot;;color:black"><br>
<span class=3D"styled-by-prettify">&nbsp; &nbsp; </span></span><span class=
=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;C=
ourier New&quot;;color:#666600">}</span></span><span style=3D"font-size:10.=
0pt;font-family:&quot;Courier New&quot;;color:black"><br>
</span><span class=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;f=
ont-family:&quot;Courier New&quot;;color:#666600">};</span></span><span sty=
le=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></sp=
an></p>
</div>
</div>
<p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt"><br>
It would be nice to similar function for <span style=3D"font-family:&quot;C=
ourier New&quot;">
std::unique_ptr</span>. The name &quot;emplace&quot; is not appropriate her=
e, ptr itself doesn't contain constructed object. May be &quot;create&quot;=
 or &quot;new_&quot;? And this function can provide strong exception guaran=
tee, so effect of its usage won't differ from make_unique case.<o:p></o:p><=
/p>
<div style=3D"border:solid #BBBBBB 1.0pt;padding:0in 0in 0in 0in;overflow-w=
rap: break-word">
<div>
<p class=3D"MsoNormal" style=3D"background:#FAFAFA"><span class=3D"styled-b=
y-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;Courier New&q=
uot;;color:#000088">class</span></span><span class=3D"styled-by-prettify"><=
span style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:bl=
ack">
 C</span></span><span style=3D"font-size:10.0pt;font-family:&quot;Courier N=
ew&quot;;color:black"><br>
</span><span class=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;f=
ont-family:&quot;Courier New&quot;;color:#666600">{</span></span><span styl=
e=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black"><br>
<span class=3D"styled-by-prettify">&nbsp; &nbsp; std</span></span><span cla=
ss=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot=
;Courier New&quot;;color:#666600">::</span></span><span class=3D"styled-by-=
prettify"><span style=3D"font-size:10.0pt;font-family:&quot;Courier New&quo=
t;;color:black">unique_ptr</span></span><span class=3D"styled-by-prettify">=
<span style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#=
008800">&lt;some_long_and_ugly_name&gt;</span></span><span class=3D"styled-=
by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;Courier New&=
quot;;color:black">
 p</span></span><span class=3D"styled-by-prettify"><span style=3D"font-size=
:10.0pt;font-family:&quot;Courier New&quot;;color:#666600">;</span></span><=
span style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;color:bl=
ack"><br>
<span class=3D"styled-by-prettify">&nbsp; &nbsp; C</span></span><span class=
=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;C=
ourier New&quot;;color:#666600">()</span></span><span style=3D"font-size:10=
..0pt;font-family:&quot;Courier New&quot;;color:black"><br>
<span class=3D"styled-by-prettify">&nbsp; &nbsp; </span></span><span class=
=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;C=
ourier New&quot;;color:#666600">{</span></span><span style=3D"font-size:10.=
0pt;font-family:&quot;Courier New&quot;;color:black"><br>
<span class=3D"styled-by-prettify">&nbsp; &nbsp; &nbsp; &nbsp; p</span></sp=
an><span class=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-=
family:&quot;Courier New&quot;;color:#666600">.</span></span><span class=3D=
"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;Cour=
ier New&quot;;color:black">new_</span></span><span class=3D"styled-by-prett=
ify"><span style=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;;co=
lor:#666600">(...);</span></span><span style=3D"font-size:10.0pt;font-famil=
y:&quot;Courier New&quot;;color:black"><br>
<span class=3D"styled-by-prettify">&nbsp; &nbsp; </span></span><span class=
=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;font-family:&quot;C=
ourier New&quot;;color:#666600">}</span></span><span style=3D"font-size:10.=
0pt;font-family:&quot;Courier New&quot;;color:black"><br>
</span><span class=3D"styled-by-prettify"><span style=3D"font-size:10.0pt;f=
ont-family:&quot;Courier New&quot;;color:#666600">};</span></span><span sty=
le=3D"font-size:10.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></sp=
an></p>
</div>
</div>
<p class=3D"MsoNormal"><br>
Any thoughts/comments/suggestions?<o:p></o:p></p>
</div>
<p class=3D"MsoNormal">-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C&#43;&#43; Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to
<a href=3D"mailto:std-proposals&#43;unsubscribe@isocpp.org">std-proposals&#=
43;unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://na01.safelinks.=
protection.outlook.com/?url=3Dhttps%3A%2F%2Fgroups.google.com%2Fa%2Fisocpp.=
org%2Fd%2Fmsgid%2Fstd-proposals%2F437f3bb8-6c04-4107-943c-32908b54d82e%2540=
isocpp.org%3Futm_medium%3Demail%26utm_source%3Dfooter&amp;data=3D02%7C01%7C=
afoxman%40microsoft.com%7Cc6c8d1194d3d4944d2a908d40e0f8fb9%7C72f988bf86f141=
af91ab2d7cd011db47%7C1%7C0%7C636148907381955307&amp;sdata=3Dof%2F3RwR7IzM%2=
FjqrdjrfYFSuomVwVX0ZFlag6n2cfIe0%3D&amp;reserved=3D0">
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/437f3bb8-6c04-=
4107-943c-32908b54d82e%40isocpp.org</a>.<o:p></o:p></p>
</div>
</body>
</html>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CY1PR0301MB1596BCF64E01B0ABDEB503D9B3=
BE0%40CY1PR0301MB1596.namprd03.prod.outlook.com?utm_medium=3Demail&utm_sour=
ce=3Dfooter">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/C=
Y1PR0301MB1596BCF64E01B0ABDEB503D9B3BE0%40CY1PR0301MB1596.namprd03.prod.out=
look.com</a>.<br />

--_000_CY1PR0301MB1596BCF64E01B0ABDEB503D9B3BE0CY1PR0301MB1596_--

.


Author: joseph.thomson@gmail.com
Date: Wed, 16 Nov 2016 15:55:17 -0800 (PST)
Raw View
------=_Part_5217_1045456158.1479340517188
Content-Type: multipart/alternative;
 boundary="----=_Part_5218_1528311523.1479340517188"

------=_Part_5218_1528311523.1479340517188
Content-Type: text/plain; charset=UTF-8

On Wednesday, 16 November 2016 18:58:54 UTC+8, Victor Dyachenko wrote:
>
> Assume we have a variable like this:
>
> std::unique_ptr<some_long_and_ugly_name> p;
>
> If it is a local variable then it can be constructed as
>
> auto p = std::make_unique<some_long_and_ugly_name>(...);
>
> without duplication of template argument (some_long_and_ugly_name).
>
> But if it is member variable, we can't avoid duplication:
>
> class C
> {
>     std::unique_ptr<some_long_and_ugly_name> p;
>     C()
>     {
>         p = std::make_unique<some_long_and_ugly_name>(...);
>     }
> };
>
> If std::optional is used instead of std::unique_ptr then duplication can
> be avoided using emplace() for object construction:
>
> class C
> {
>     std::optional<some_long_and_ugly_name> p;
>     C()
>     {
>         p.emplace(...); // <-- no template argument duplication here
>     }
> };
>
> It would be nice to similar function for std::unique_ptr. The name
> "emplace" is not appropriate here, ptr itself doesn't contain constructed
> object. May be "create" or "new_"? And this function can provide strong
> exception guarantee, so effect of its usage won't differ from make_unique
> case.
>
> class C
> {
>     std::unique_ptr<some_long_and_ugly_name> p;
>     C()
>     {
>         p.new_(...);
>     }
> };
>
> Any thoughts/comments/suggestions?
>

How would such a function know how to create a new object for a unique_ptr
with a custom deleter?

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/3864ce6d-45ff-4b2f-a29e-6db9826b1433%40isocpp.org.

------=_Part_5218_1528311523.1479340517188
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Wednesday, 16 November 2016 18:58:54 UTC+8, Victor Dyac=
henko  wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">=
Assume we have a variable like this:<br><br><div style=3D"background-color:=
rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-wi=
dth:1px"><code><div><span style=3D"color:#000">std</span><span style=3D"col=
or:#660">::</span><span style=3D"color:#000">unique_ptr</span><span style=
=3D"color:#080">&lt;some_long_and_<wbr>ugly_name&gt;</span><span style=3D"c=
olor:#000"> p</span><span style=3D"color:#660">;</span><span style=3D"color=
:#000"><br></span></div></code></div><br>If it is a local variable then it =
can be constructed as<br><br><div style=3D"background-color:rgb(250,250,250=
);border-color:rgb(187,187,187);border-style:solid;border-width:1px"><code>=
<div><span style=3D"color:#008">auto</span><span style=3D"color:#000"> p </=
span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> std</=
span><span style=3D"color:#660">::</span><span style=3D"color:#000">make_un=
ique</span><span style=3D"color:#080">&lt;some_long_<wbr>and_ugly_name&gt;<=
/span><span style=3D"color:#660">(...);</span><span style=3D"color:#000"><b=
r></span></div></code></div><br>without duplication of template argument (<=
span style=3D"font-family:courier new,monospace">some_long_and_ugly_name</s=
pan>).<br><br>But if it is member variable, we can&#39;t avoid duplication:=
<br><br><div style=3D"background-color:rgb(250,250,250);border-color:rgb(18=
7,187,187);border-style:solid;border-width:1px"><code><div><span style=3D"c=
olor:#008">class</span><span style=3D"color:#000"> C<br></span><span style=
=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 std</s=
pan><span style=3D"color:#660">::</span><span style=3D"color:#000">unique_p=
tr</span><span style=3D"color:#080">&lt;some_long_and_<wbr>ugly_name&gt;</s=
pan><span style=3D"color:#000"> p</span><span style=3D"color:#660">;</span>=
<span style=3D"color:#000"><br>=C2=A0 =C2=A0 C</span><span style=3D"color:#=
660">()</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span sty=
le=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 p </span><span style=3D"color:#660">=3D</span><span style=3D"col=
or:#000"> std</span><span style=3D"color:#660">::</span><span style=3D"colo=
r:#000">make_unique</span><span style=3D"color:#080">&lt;some_long_<wbr>and=
_ugly_name&gt;</span><span style=3D"color:#660">(...);</span><span style=3D=
"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><s=
pan style=3D"color:#000"><br></span><span style=3D"color:#660">};</span><sp=
an style=3D"color:#000"><br></span></div></code></div><br>If <span style=3D=
"font-family:courier new,monospace">std::optional</span> is used instead of=
 <span style=3D"font-family:courier new,monospace">std::unique_ptr</span> t=
hen duplication can be avoided using <span style=3D"font-family:courier new=
,monospace">emplace()</span> for object construction:<br><br><div style=3D"=
background-color:rgb(250,250,250);border-color:rgb(187,187,187);border-styl=
e:solid;border-width:1px"><code><div><span style=3D"color:#008">class</span=
><span style=3D"color:#000"> C<br></span><span style=3D"color:#660">{</span=
><span style=3D"color:#000"><br>=C2=A0 =C2=A0 std</span><span style=3D"colo=
r:#660">::</span><span style=3D"color:#000">optional</span><span style=3D"c=
olor:#080">&lt;some_long_and_<wbr>ugly_name&gt;</span><span style=3D"color:=
#000"> p</span><span style=3D"color:#660">;</span><span style=3D"color:#000=
"><br>=C2=A0 =C2=A0 C</span><span style=3D"color:#660">()</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span=
><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 p</span><span s=
tyle=3D"color:#660">.</span><span style=3D"color:#000">emplace</span><span =
style=3D"color:#660">(...);</span><span style=3D"color:#000"> </span><span =
style=3D"color:#800">// &lt;-- no template argument duplication here</span>=
<span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#6=
60">}</span><span style=3D"color:#000"><br></span><span style=3D"color:#660=
">};</span><span style=3D"color:#000"><br></span></div></code></div><br>It =
would be nice to similar function for <span style=3D"font-family:courier ne=
w,monospace">std::unique_ptr</span>. The name &quot;emplace&quot; is not ap=
propriate here, ptr itself doesn&#39;t contain constructed object. May be &=
quot;create&quot; or &quot;new_&quot;? And this function can provide strong=
 exception guarantee, so effect of its usage won&#39;t differ from make_uni=
que case.<br><br><div style=3D"background-color:rgb(250,250,250);border-col=
or:rgb(187,187,187);border-style:solid;border-width:1px"><code><div><span s=
tyle=3D"color:#008">class</span><span style=3D"color:#000"> C<br></span><sp=
an style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=
=A0 std</span><span style=3D"color:#660">::</span><span style=3D"color:#000=
">unique_ptr</span><span style=3D"color:#080">&lt;some_long_and_<wbr>ugly_n=
ame&gt;</span><span style=3D"color:#000"> p</span><span style=3D"color:#660=
">;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 C</span><span style=
=3D"color:#660">()</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 p</span><span style=3D"color:#660">.</span><span style=
=3D"color:#000">new_</span><span style=3D"color:#660">(...);</span><span st=
yle=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</s=
pan><span style=3D"color:#000"><br></span><span style=3D"color:#660">};</sp=
an><span style=3D"color:#000"><br></span></div></code></div><br>Any thought=
s/comments/suggestions?<br></div></blockquote><div><br>How would such a fun=
ction know how to create a new object for a <span style=3D"font-family: cou=
rier new,monospace;">unique_ptr</span> with a custom deleter?<br></div></di=
v>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/3864ce6d-45ff-4b2f-a29e-6db9826b1433%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/3864ce6d-45ff-4b2f-a29e-6db9826b1433=
%40isocpp.org</a>.<br />

------=_Part_5218_1528311523.1479340517188--

------=_Part_5217_1045456158.1479340517188--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Wed, 16 Nov 2016 20:15:30 -0800 (PST)
Raw View
------=_Part_5144_729890808.1479356130725
Content-Type: multipart/alternative;
 boundary="----=_Part_5145_1759501113.1479356130725"

------=_Part_5145_1759501113.1479356130725
Content-Type: text/plain; charset=UTF-8



On Wednesday, November 16, 2016 at 6:55:17 PM UTC-5, joseph....@gmail.com
wrote:
>
> On Wednesday, 16 November 2016 18:58:54 UTC+8, Victor Dyachenko wrote:
>>
>> Assume we have a variable like this:
>>
>> std::unique_ptr<some_long_and_ugly_name> p;
>>
>> If it is a local variable then it can be constructed as
>>
>> auto p = std::make_unique<some_long_and_ugly_name>(...);
>>
>> without duplication of template argument (some_long_and_ugly_name).
>>
>> But if it is member variable, we can't avoid duplication:
>>
>> class C
>> {
>>     std::unique_ptr<some_long_and_ugly_name> p;
>>     C()
>>     {
>>         p = std::make_unique<some_long_and_ugly_name>(...);
>>     }
>> };
>>
>> If std::optional is used instead of std::unique_ptr then duplication can
>> be avoided using emplace() for object construction:
>>
>> class C
>> {
>>     std::optional<some_long_and_ugly_name> p;
>>     C()
>>     {
>>         p.emplace(...); // <-- no template argument duplication here
>>     }
>> };
>>
>> It would be nice to similar function for std::unique_ptr. The name
>> "emplace" is not appropriate here, ptr itself doesn't contain constructed
>> object. May be "create" or "new_"? And this function can provide strong
>> exception guarantee, so effect of its usage won't differ from make_unique
>> case.
>>
>> class C
>> {
>>     std::unique_ptr<some_long_and_ugly_name> p;
>>     C()
>>     {
>>         p.new_(...);
>>     }
>> };
>>
>> Any thoughts/comments/suggestions?
>>
>
> How would such a function know how to create a new object for a unique_ptr
> with a custom deleter?
>

The same way `unique_ptr::reset` does. In that it does not; it just uses
the existing deleter object. Indeed, `unique_ptr` has no methods to change
the deleter object after assigning to it.

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/6ea2e02f-8b07-43e6-ac9d-66c10f6e4777%40isocpp.org.

------=_Part_5145_1759501113.1479356130725
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Wednesday, November 16, 2016 at 6:55:17 PM UTC-=
5, joseph....@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">=
<div dir=3D"ltr">On Wednesday, 16 November 2016 18:58:54 UTC+8, Victor Dyac=
henko  wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-lef=
t:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Assum=
e we have a variable like this:<br><br><div style=3D"background-color:rgb(2=
50,250,250);border-color:rgb(187,187,187);border-style:solid;border-width:1=
px"><code><div><span style=3D"color:#000">std</span><span style=3D"color:#6=
60">::</span><span style=3D"color:#000">unique_ptr</span><span style=3D"col=
or:#080">&lt;some_long_and_<wbr>ugly_name&gt;</span><span style=3D"color:#0=
00"> p</span><span style=3D"color:#660">;</span><span style=3D"color:#000">=
<br></span></div></code></div><br>If it is a local variable then it can be =
constructed as<br><br><div style=3D"background-color:rgb(250,250,250);borde=
r-color:rgb(187,187,187);border-style:solid;border-width:1px"><code><div><s=
pan style=3D"color:#008">auto</span><span style=3D"color:#000"> p </span><s=
pan style=3D"color:#660">=3D</span><span style=3D"color:#000"> std</span><s=
pan style=3D"color:#660">::</span><span style=3D"color:#000">make_unique</s=
pan><span style=3D"color:#080">&lt;some_long_<wbr>and_ugly_name&gt;</span><=
span style=3D"color:#660">(...);</span><span style=3D"color:#000"><br></spa=
n></div></code></div><br>without duplication of template argument (<span st=
yle=3D"font-family:courier new,monospace">some_long_and_ugly_name</span>).<=
br><br>But if it is member variable, we can&#39;t avoid duplication:<br><br=
><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,1=
87);border-style:solid;border-width:1px"><code><div><span style=3D"color:#0=
08">class</span><span style=3D"color:#000"> C<br></span><span style=3D"colo=
r:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 std</span><spa=
n style=3D"color:#660">::</span><span style=3D"color:#000">unique_ptr</span=
><span style=3D"color:#080">&lt;some_long_and_<wbr>ugly_name&gt;</span><spa=
n style=3D"color:#000"> p</span><span style=3D"color:#660">;</span><span st=
yle=3D"color:#000"><br>=C2=A0 =C2=A0 C</span><span style=3D"color:#660">()<=
/span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"co=
lor:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 p </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000=
"> std</span><span style=3D"color:#660">::</span><span style=3D"color:#000"=
>make_unique</span><span style=3D"color:#080">&lt;some_long_<wbr>and_ugly_n=
ame&gt;</span><span style=3D"color:#660">(...);</span><span style=3D"color:=
#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span sty=
le=3D"color:#000"><br></span><span style=3D"color:#660">};</span><span styl=
e=3D"color:#000"><br></span></div></code></div><br>If <span style=3D"font-f=
amily:courier new,monospace">std::optional</span> is used instead of <span =
style=3D"font-family:courier new,monospace">std::unique_ptr</span> then dup=
lication can be avoided using <span style=3D"font-family:courier new,monosp=
ace">emplace()</span> for object construction:<br><br><div style=3D"backgro=
und-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid=
;border-width:1px"><code><div><span style=3D"color:#008">class</span><span =
style=3D"color:#000"> C<br></span><span style=3D"color:#660">{</span><span =
style=3D"color:#000"><br>=C2=A0 =C2=A0 std</span><span style=3D"color:#660"=
>::</span><span style=3D"color:#000">optional</span><span style=3D"color:#0=
80">&lt;some_long_and_<wbr>ugly_name&gt;</span><span style=3D"color:#000"> =
p</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 C</span><span style=3D"color:#660">()</span><span style=3D"co=
lor:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><span=
 style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 p</span><span style=
=3D"color:#660">.</span><span style=3D"color:#000">emplace</span><span styl=
e=3D"color:#660">(...);</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#800">// &lt;-- no template argument duplication here</span><spa=
n style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">=
}</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">};=
</span><span style=3D"color:#000"><br></span></div></code></div><br>It woul=
d be nice to similar function for <span style=3D"font-family:courier new,mo=
nospace">std::unique_ptr</span>. The name &quot;emplace&quot; is not approp=
riate here, ptr itself doesn&#39;t contain constructed object. May be &quot=
;create&quot; or &quot;new_&quot;? And this function can provide strong exc=
eption guarantee, so effect of its usage won&#39;t differ from make_unique =
case.<br><br><div style=3D"background-color:rgb(250,250,250);border-color:r=
gb(187,187,187);border-style:solid;border-width:1px"><code><div><span style=
=3D"color:#008">class</span><span style=3D"color:#000"> C<br></span><span s=
tyle=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 st=
d</span><span style=3D"color:#660">::</span><span style=3D"color:#000">uniq=
ue_ptr</span><span style=3D"color:#080">&lt;some_long_and_<wbr>ugly_name&gt=
;</span><span style=3D"color:#000"> p</span><span style=3D"color:#660">;</s=
pan><span style=3D"color:#000"><br>=C2=A0 =C2=A0 C</span><span style=3D"col=
or:#660">()</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span=
 style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 p</span><span style=3D"color:#660">.</span><span style=3D"col=
or:#000">new_</span><span style=3D"color:#660">(...);</span><span style=3D"=
color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><sp=
an style=3D"color:#000"><br></span><span style=3D"color:#660">};</span><spa=
n style=3D"color:#000"><br></span></div></code></div><br>Any thoughts/comme=
nts/suggestions?<br></div></blockquote><div><br>How would such a function k=
now how to create a new object for a <span style=3D"font-family:courier new=
,monospace">unique_ptr</span> with a custom deleter?<br></div></div></block=
quote><div><br>The same way `unique_ptr::reset` does. In that it does not; =
it just uses the existing deleter object. Indeed, `unique_ptr` has no metho=
ds to change the deleter object after assigning to it.<br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/6ea2e02f-8b07-43e6-ac9d-66c10f6e4777%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6ea2e02f-8b07-43e6-ac9d-66c10f6e4777=
%40isocpp.org</a>.<br />

------=_Part_5145_1759501113.1479356130725--

------=_Part_5144_729890808.1479356130725--

.


Author: Victor Dyachenko <victor.dyachenko@gmail.com>
Date: Wed, 16 Nov 2016 22:38:48 -0800 (PST)
Raw View
------=_Part_4798_890815882.1479364728305
Content-Type: multipart/alternative;
 boundary="----=_Part_4799_528695159.1479364728305"

------=_Part_4799_528695159.1479364728305
Content-Type: text/plain; charset=UTF-8

On Wednesday, November 16, 2016 at 10:24:19 PM UTC+3, Adam Foxman wrote:
>
> Are the intended semantics similar to reset(), where an existing object is
> replaced?
>

Intendent semantics is similar to std::optional::emplace(), so yes,
existing object is replaced.

But in this case there is no need to destroy the old object before
creation, so function can additionally provide strong exception safety
guarantee.

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/46cf0e08-47eb-4802-9c56-621b0abcabdb%40isocpp.org.

------=_Part_4799_528695159.1479364728305
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Wednesday, November 16, 2016 at 10:24:19 PM UTC+3, Adam=
 Foxman wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">





<div link=3D"blue" vlink=3D"purple" lang=3D"EN-US">
<div>
<p class=3D"MsoNormal">Are the intended semantics similar to reset(), where=
 an existing object is replaced?<a name=3D"CY1PR0301MB1596BCF64E01B0ABDEB50=
3D9B3BE0@CY1PR0301MB1596.namprd03.prod.outlook.com__MailEndCompose">=C2=A0<=
/a>
<span></span></p></div></div></blockquote><div>=C2=A0<br>Intendent semantic=
s is similar to <span style=3D"font-family: courier new,monospace;">std::op=
tional::emplace()</span>, so yes, existing object is replaced.<br><br>But i=
n this case there is no need to destroy the old object before creation, so =
function can additionally provide strong exception safety guarantee.<br></d=
iv></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/46cf0e08-47eb-4802-9c56-621b0abcabdb%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/46cf0e08-47eb-4802-9c56-621b0abcabdb=
%40isocpp.org</a>.<br />

------=_Part_4799_528695159.1479364728305--

------=_Part_4798_890815882.1479364728305--

.


Author: Victor Dyachenko <victor.dyachenko@gmail.com>
Date: Wed, 16 Nov 2016 22:51:46 -0800 (PST)
Raw View
------=_Part_1844_1327831429.1479365506457
Content-Type: multipart/alternative;
 boundary="----=_Part_1845_989733737.1479365506457"

------=_Part_1845_989733737.1479365506457
Content-Type: text/plain; charset=UTF-8

On Thursday, November 17, 2016 at 2:55:17 AM UTC+3, joseph....@gmail.com
wrote:
>
>
> How would such a function know how to create a new object for a unique_ptr
> with a custom deleter?
>

Yes... currently no other member functions create guarded object...
make_unique() is not member and handles special case with default_deleter.

May be it can be non-member fuction like this:

template<class T, class... Args>
void reallocate_unique(std::unique_ptr<T> &p, Args &&... args)
{
    p = std::make_unique<T>(std::forward<Args>(args)...);
}

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/59d4a595-e8d7-4073-85b2-cf2e12f0d405%40isocpp.org.

------=_Part_1845_989733737.1479365506457
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Thursday, November 17, 2016 at 2:55:17 AM UTC+3, joseph=
.....@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><br><div>How would such a function know how to create a new object=
 for a <span style=3D"font-family:courier new,monospace">unique_ptr</span> =
with a custom deleter?<br></div></div></blockquote><div><br>Yes... currentl=
y no other member functions create guarded object... <span style=3D"font-fa=
mily: courier new,monospace;">make_unique()</span> is not member and handle=
s special case with <span style=3D"font-family: courier new,monospace;">def=
ault_deleter</span>.<br><br>May be it can be non-member fuction like this:<=
br><br><div style=3D"background-color: rgb(250, 250, 250); border-color: rg=
b(187, 187, 187); border-style: solid; border-width: 1px; overflow-wrap: br=
eak-word;" class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"=
subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">t=
emplate</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt=
;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">class</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">...</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">Args</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">voi=
d</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> realloca=
te_unique</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">unique_ptr</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">p</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #606;" class=3D"styled-by-prettify">Args</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&amp;&amp;...</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> args</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 p </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify">make_unique</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
gt;(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">forward</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Args</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">&gt;(</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">args</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">)...);</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br></span></div></code></div><br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/59d4a595-e8d7-4073-85b2-cf2e12f0d405%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/59d4a595-e8d7-4073-85b2-cf2e12f0d405=
%40isocpp.org</a>.<br />

------=_Part_1845_989733737.1479365506457--

------=_Part_1844_1327831429.1479365506457--

.


Author: Tony V E <tvaneerd@gmail.com>
Date: Thu, 17 Nov 2016 01:54:12 -0500
Raw View
<html><head></head><body lang=3D"en-US" style=3D"background-color: rgb(255,=
 255, 255); line-height: initial;">                                        =
                                              <div style=3D"width: 100%; fo=
nt-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif=
; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, =
255, 255);">Would reset_new be a reasonable name?</div><div style=3D"width:=
 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, s=
ans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: =
rgb(255, 255, 255);"><br></div>                                            =
                                                                           =
              <div style=3D"width: 100%; font-size: initial; font-family: C=
alibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-=
align: initial; background-color: rgb(255, 255, 255);"><br style=3D"display=
:initial"></div>                                                           =
                                                                           =
                                                             <div style=3D"=
font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-ser=
if; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255=
, 255, 255);">Sent&nbsp;from&nbsp;my&nbsp;BlackBerry&nbsp;portable&nbsp;Bab=
bage&nbsp;Device</div>                                                     =
                                                                           =
                                                  <table width=3D"100%" sty=
le=3D"background-color:white;border-spacing:0px;"> <tbody><tr><td colspan=
=3D"2" style=3D"font-size: initial; text-align: initial; background-color: =
rgb(255, 255, 255);">                           <div style=3D"border-style:=
 solid none none; border-top-color: rgb(181, 196, 223); border-top-width: 1=
pt; padding: 3pt 0in 0in; font-family: Tahoma, 'BB Alpha Sans', 'Slate Pro'=
; font-size: 10pt;">  <div><b>From: </b>Victor Dyachenko</div><div><b>Sent:=
 </b>Thursday, November 17, 2016 1:51 AM</div><div><b>To: </b>ISO C++ Stand=
ard - Future Proposals</div><div><b>Reply To: </b>std-proposals@isocpp.org<=
/div><div><b>Cc: </b>joseph.thomson@gmail.com</div><div><b>Subject: </b>[st=
d-proposals] Re: emplace-like function for std::unique_ptr</div></div></td>=
</tr></tbody></table><div style=3D"border-style: solid none none; border-to=
p-color: rgb(186, 188, 209); border-top-width: 1pt; font-size: initial; tex=
t-align: initial; background-color: rgb(255, 255, 255);"></div><br><div id=
=3D"_originalContent" style=3D""><div dir=3D"ltr">On Thursday, November 17,=
 2016 at 2:55:17 AM UTC+3, joseph....@gmail.com wrote:<blockquote class=3D"=
gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc so=
lid;padding-left: 1ex;"><div dir=3D"ltr"><br><div>How would such a function=
 know how to create a new object for a <span style=3D"font-family:courier n=
ew,monospace">unique_ptr</span> with a custom deleter?<br></div></div></blo=
ckquote><div><br>Yes... currently no other member functions create guarded =
object... <span style=3D"font-family: courier new,monospace;">make_unique()=
</span> is not member and handles special case with <span style=3D"font-fam=
ily: courier new,monospace;">default_deleter</span>.<br><br>May be it can b=
e non-member fuction like this:<br><br><div style=3D"background-color: rgb(=
250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bord=
er-width: 1px; overflow-wrap: break-word;" class=3D"prettyprint"><code clas=
s=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;=
" class=3D"styled-by-prettify">template</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">class</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">...</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Args</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> reallocate_unique</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">unique_ptr</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">p</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Args</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&amp;&amp;...</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> args</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r></span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp;=
 p </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">make_unique</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&gt;(</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify">forward</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&lt;</span><span style=3D"color: #606;" class=3D"styled-by-pretti=
fy">Args</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&g=
t;(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">args</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">)...);</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><b=
r></div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/59d4a595-e8d7-4073-85b2-cf2e12f0d405%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter">https://groups.goo=
gle.com/a/isocpp.org/d/msgid/std-proposals/59d4a595-e8d7-4073-85b2-cf2e12f0=
d405%40isocpp.org</a>.<br>
<br><!--end of _originalContent --></div></body></html>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/20161117065412.4907088.24784.20279%40=
gmail.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com=
/a/isocpp.org/d/msgid/std-proposals/20161117065412.4907088.24784.20279%40gm=
ail.com</a>.<br />

.


Author: Victor Dyachenko <victor.dyachenko@gmail.com>
Date: Wed, 16 Nov 2016 23:11:41 -0800 (PST)
Raw View
------=_Part_4873_1026874470.1479366701116
Content-Type: multipart/alternative;
 boundary="----=_Part_4874_1436348266.1479366701117"

------=_Part_4874_1436348266.1479366701117
Content-Type: text/plain; charset=UTF-8

May be I'm initially wrong and "upgrading" unique_ptr is a bad idea?

My initial task is "late construction" of some members. std::optional is a
good solution in most cases, but when member is big and/or seldom used,
heap allocation is a better option. I use unique_ptr in such cases but
construction suffers from verbosity and, more important, violates DRY
principle.

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/94febd9f-8081-410b-ab2b-4dbefa402540%40isocpp.org.

------=_Part_4874_1436348266.1479366701117
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">May be I&#39;m initially wrong and &quot;upgrading&quot; u=
nique_ptr is a bad idea?<br><br>My initial task is &quot;late construction&=
quot; of some members. <span style=3D"font-family: courier new,monospace;">=
std::optional</span> is a good solution in most cases, but when member is b=
ig and/or seldom used, heap allocation is a better option. I use unique_ptr=
 in such cases but construction suffers from verbosity and, more important,=
 violates DRY principle.<br></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/94febd9f-8081-410b-ab2b-4dbefa402540%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/94febd9f-8081-410b-ab2b-4dbefa402540=
%40isocpp.org</a>.<br />

------=_Part_4874_1436348266.1479366701117--

------=_Part_4873_1026874470.1479366701116--

.


Author: joseph.thomson@gmail.com
Date: Wed, 16 Nov 2016 23:27:06 -0800 (PST)
Raw View
------=_Part_5483_556438860.1479367626798
Content-Type: multipart/alternative;
 boundary="----=_Part_5484_2003831538.1479367626798"

------=_Part_5484_2003831538.1479367626798
Content-Type: text/plain; charset=UTF-8

On Thursday, 17 November 2016 12:15:30 UTC+8, Nicol Bolas wrote:
>
>
>
> On Wednesday, November 16, 2016 at 6:55:17 PM UTC-5, joseph....@gmail.com
> wrote:
>>
>> On Wednesday, 16 November 2016 18:58:54 UTC+8, Victor Dyachenko wrote:
>>>
>>> Assume we have a variable like this:
>>>
>>> std::unique_ptr<some_long_and_ugly_name> p;
>>>
>>> If it is a local variable then it can be constructed as
>>>
>>> auto p = std::make_unique<some_long_and_ugly_name>(...);
>>>
>>> without duplication of template argument (some_long_and_ugly_name).
>>>
>>> But if it is member variable, we can't avoid duplication:
>>>
>>> class C
>>> {
>>>     std::unique_ptr<some_long_and_ugly_name> p;
>>>     C()
>>>     {
>>>         p = std::make_unique<some_long_and_ugly_name>(...);
>>>     }
>>> };
>>>
>>> If std::optional is used instead of std::unique_ptr then duplication
>>> can be avoided using emplace() for object construction:
>>>
>>> class C
>>> {
>>>     std::optional<some_long_and_ugly_name> p;
>>>     C()
>>>     {
>>>         p.emplace(...); // <-- no template argument duplication here
>>>     }
>>> };
>>>
>>> It would be nice to similar function for std::unique_ptr. The name
>>> "emplace" is not appropriate here, ptr itself doesn't contain constructed
>>> object. May be "create" or "new_"? And this function can provide strong
>>> exception guarantee, so effect of its usage won't differ from make_unique
>>> case.
>>>
>>> class C
>>> {
>>>     std::unique_ptr<some_long_and_ugly_name> p;
>>>     C()
>>>     {
>>>         p.new_(...);
>>>     }
>>> };
>>>
>>> Any thoughts/comments/suggestions?
>>>
>>
>> How would such a function know how to create a new object for a
>> unique_ptr with a custom deleter?
>>
>
> The same way `unique_ptr::reset` does. In that it does not; it just uses
> the existing deleter object. Indeed, `unique_ptr` has no methods to change
> the deleter object after assigning to it.
>

But unique_ptr::reset doesn't create anything; it just takes ownership of
an existing object. The proposed function necessarily creates an object
using operator new which is likely to be incorrect for a unique_ptr with a
custom deleter.

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/24dfab6c-b1c0-436e-8fea-dc62e9a3455c%40isocpp.org.

------=_Part_5484_2003831538.1479367626798
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Thursday, 17 November 2016 12:15:30 UTC+8, Nicol Bolas =
 wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><br><b=
r>On Wednesday, November 16, 2016 at 6:55:17 PM UTC-5, <a>joseph....@gmail.=
com</a> wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-le=
ft:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">On W=
ednesday, 16 November 2016 18:58:54 UTC+8, Victor Dyachenko  wrote:<blockqu=
ote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1=
px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Assume we have a variable =
like this:<br><br><div style=3D"background-color:rgb(250,250,250);border-co=
lor:rgb(187,187,187);border-style:solid;border-width:1px"><code><div><span =
style=3D"color:#000">std</span><span style=3D"color:#660">::</span><span st=
yle=3D"color:#000">unique_ptr</span><span style=3D"color:#080">&lt;some_lon=
g_and_<wbr>ugly_name&gt;</span><span style=3D"color:#000"> p</span><span st=
yle=3D"color:#660">;</span><span style=3D"color:#000"><br></span></div></co=
de></div><br>If it is a local variable then it can be constructed as<br><br=
><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,1=
87);border-style:solid;border-width:1px"><code><div><span style=3D"color:#0=
08">auto</span><span style=3D"color:#000"> p </span><span style=3D"color:#6=
60">=3D</span><span style=3D"color:#000"> std</span><span style=3D"color:#6=
60">::</span><span style=3D"color:#000">make_unique</span><span style=3D"co=
lor:#080">&lt;some_long_<wbr>and_ugly_name&gt;</span><span style=3D"color:#=
660">(...);</span><span style=3D"color:#000"><br></span></div></code></div>=
<br>without duplication of template argument (<span style=3D"font-family:co=
urier new,monospace">some_long_and_ugly_name</span>).<br><br>But if it is m=
ember variable, we can&#39;t avoid duplication:<br><br><div style=3D"backgr=
ound-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:soli=
d;border-width:1px"><code><div><span style=3D"color:#008">class</span><span=
 style=3D"color:#000"> C<br></span><span style=3D"color:#660">{</span><span=
 style=3D"color:#000"><br>=C2=A0 =C2=A0 std</span><span style=3D"color:#660=
">::</span><span style=3D"color:#000">unique_ptr</span><span style=3D"color=
:#080">&lt;some_long_and_<wbr>ugly_name&gt;</span><span style=3D"color:#000=
"> p</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><b=
r>=C2=A0 =C2=A0 C</span><span style=3D"color:#660">()</span><span style=3D"=
color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><sp=
an style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 p </span><span styl=
e=3D"color:#660">=3D</span><span style=3D"color:#000"> std</span><span styl=
e=3D"color:#660">::</span><span style=3D"color:#000">make_unique</span><spa=
n style=3D"color:#080">&lt;some_long_<wbr>and_ugly_name&gt;</span><span sty=
le=3D"color:#660">(...);</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0=
 </span><span style=3D"color:#660">}</span><span style=3D"color:#000"><br><=
/span><span style=3D"color:#660">};</span><span style=3D"color:#000"><br></=
span></div></code></div><br>If <span style=3D"font-family:courier new,monos=
pace">std::optional</span> is used instead of <span style=3D"font-family:co=
urier new,monospace">std::unique_ptr</span> then duplication can be avoided=
 using <span style=3D"font-family:courier new,monospace">emplace()</span> f=
or object construction:<br><br><div style=3D"background-color:rgb(250,250,2=
50);border-color:rgb(187,187,187);border-style:solid;border-width:1px"><cod=
e><div><span style=3D"color:#008">class</span><span style=3D"color:#000"> C=
<br></span><span style=3D"color:#660">{</span><span style=3D"color:#000"><b=
r>=C2=A0 =C2=A0 std</span><span style=3D"color:#660">::</span><span style=
=3D"color:#000">optional</span><span style=3D"color:#080">&lt;some_long_and=
_<wbr>ugly_name&gt;</span><span style=3D"color:#000"> p</span><span style=
=3D"color:#660">;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 C</spa=
n><span style=3D"color:#660">()</span><span style=3D"color:#000"><br>=C2=A0=
 =C2=A0 </span><span style=3D"color:#660">{</span><span style=3D"color:#000=
"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 p</span><span style=3D"color:#660">.</spa=
n><span style=3D"color:#000">emplace</span><span style=3D"color:#660">(...)=
;</span><span style=3D"color:#000"> </span><span style=3D"color:#800">// &l=
t;-- no template argument duplication here</span><span style=3D"color:#000"=
><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span style=3D=
"color:#000"><br></span><span style=3D"color:#660">};</span><span style=3D"=
color:#000"><br></span></div></code></div><br>It would be nice to similar f=
unction for <span style=3D"font-family:courier new,monospace">std::unique_p=
tr</span>. The name &quot;emplace&quot; is not appropriate here, ptr itself=
 doesn&#39;t contain constructed object. May be &quot;create&quot; or &quot=
;new_&quot;? And this function can provide strong exception guarantee, so e=
ffect of its usage won&#39;t differ from make_unique case.<br><br><div styl=
e=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);border=
-style:solid;border-width:1px"><code><div><span style=3D"color:#008">class<=
/span><span style=3D"color:#000"> C<br></span><span style=3D"color:#660">{<=
/span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 std</span><span style=3D=
"color:#660">::</span><span style=3D"color:#000">unique_ptr</span><span sty=
le=3D"color:#080">&lt;some_long_and_<wbr>ugly_name&gt;</span><span style=3D=
"color:#000"> p</span><span style=3D"color:#660">;</span><span style=3D"col=
or:#000"><br>=C2=A0 =C2=A0 C</span><span style=3D"color:#660">()</span><spa=
n style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">=
{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 p</span>=
<span style=3D"color:#660">.</span><span style=3D"color:#000">new_</span><s=
pan style=3D"color:#660">(...);</span><span style=3D"color:#000"><br>=C2=A0=
 =C2=A0 </span><span style=3D"color:#660">}</span><span style=3D"color:#000=
"><br></span><span style=3D"color:#660">};</span><span style=3D"color:#000"=
><br></span></div></code></div><br>Any thoughts/comments/suggestions?<br></=
div></blockquote><div><br>How would such a function know how to create a ne=
w object for a <span style=3D"font-family:courier new,monospace">unique_ptr=
</span> with a custom deleter?<br></div></div></blockquote><div><br>The sam=
e way `unique_ptr::reset` does. In that it does not; it just uses the exist=
ing deleter object. Indeed, `unique_ptr` has no methods to change the delet=
er object after assigning to it.<br></div></div></blockquote><div><br>But <=
span style=3D"font-family: courier new,monospace;">unique_ptr::reset</span>=
 doesn&#39;t create anything; it just takes ownership=20
of an existing object. The proposed function necessarily creates an object =
using <span style=3D"font-family: courier new,monospace;">operator new</spa=
n> which is likely to be incorrect for a <span style=3D"font-family: courie=
r new,monospace;">unique_ptr</span> with a custom deleter.<br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/24dfab6c-b1c0-436e-8fea-dc62e9a3455c%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/24dfab6c-b1c0-436e-8fea-dc62e9a3455c=
%40isocpp.org</a>.<br />

------=_Part_5484_2003831538.1479367626798--

------=_Part_5483_556438860.1479367626798--

.


Author: joseph.thomson@gmail.com
Date: Thu, 17 Nov 2016 00:21:02 -0800 (PST)
Raw View
------=_Part_5438_2038079715.1479370862109
Content-Type: multipart/alternative;
 boundary="----=_Part_5439_1795535786.1479370862110"

------=_Part_5439_1795535786.1479370862110
Content-Type: text/plain; charset=UTF-8

On Thursday, 17 November 2016 15:11:41 UTC+8, Victor Dyachenko wrote:
>
> May be I'm initially wrong and "upgrading" unique_ptr is a bad idea?
>
> My initial task is "late construction" of some members. std::optional is
> a good solution in most cases, but when member is big and/or seldom used,
> heap allocation is a better option. I use unique_ptr in such cases but
> construction suffers from verbosity and, more important, violates DRY
> principle.
>

Here's a stupidly over-engineered solution that removes the need to specify
the type:

#include <memory>
#include <tuple>
#include <type_traits>
#include <utility>

template <typename... Ts>
class make_unique_auto_proxy {
public:
    template<typename U>
    operator std::unique_ptr<U>() {
        return make<U>(std::make_index_sequence<sizeof...(Ts)>());
    }

private:
    std::tuple<Ts...> ts;

      template <typename... Us>
    make_unique_auto_proxy(Us&&... us) : ts(std::forward<Ts>(us)...) {
    }

      template <typename U, size_t... Is>
    std::unique_ptr<U> make(std::index_sequence<Is...>) {
        return std::make_unique<U>(std::move(std::get<Is>(ts))...);
    }

      template <typename... Us>
    friend make_unique_auto_proxy<Us...> make_unique_auto(Us&&...);
};

template<typename... Ts>
make_unique_auto_proxy<Ts...> make_unique_auto(Ts&&... ts) {
    return make_unique_auto_proxy<std::decay_t<Ts>...>(std::forward<Ts>(ts
)...);
}

int main() {
    auto u = std::make_unique<int>();
      u = make_unique_auto(42);
}

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4fe0e310-9062-4c3f-9886-6c0f9481b19b%40isocpp.org.

------=_Part_5439_1795535786.1479370862110
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Thursday, 17 November 2016 15:11:41 UTC+8, Victor Dyach=
enko  wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">M=
ay be I&#39;m initially wrong and &quot;upgrading&quot; unique_ptr is a bad=
 idea?<br><br>My initial task is &quot;late construction&quot; of some memb=
ers. <span style=3D"font-family:courier new,monospace">std::optional</span>=
 is a good solution in most cases, but when member is big and/or seldom use=
d, heap allocation is a better option. I use unique_ptr in such cases but c=
onstruction suffers from verbosity and, more important, violates DRY princi=
ple.<br></div></blockquote><div><br>Here&#39;s a stupidly over-engineered s=
olution that removes the need to specify the type:<br><br><div style=3D"bac=
kground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border=
-style: solid; border-width: 1px; overflow-wrap: break-word;" class=3D"pret=
typrint"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span st=
yle=3D"color: #800;" class=3D"styled-by-prettify">#include</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #080;" class=3D"styled-by-prettify">&lt;memory&gt;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color:=
 #800;" class=3D"styled-by-prettify">#include</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;" cla=
ss=3D"styled-by-prettify">&lt;tuple&gt;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br></span><span style=3D"color: #800;" class=
=3D"styled-by-prettify">#include</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"style=
d-by-prettify">&lt;type_traits&gt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #800;" class=3D"st=
yled-by-prettify">#include</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-pre=
ttify">&lt;utility&gt;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">template</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">typenam=
e</span><span style=3D"color: #660;" class=3D"styled-by-prettify">...</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #606;" class=3D"styled-by-prettify">Ts</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">class</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> make_unique_auto_proxy </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">public</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">template</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> U</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">operator</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">unique_ptr</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">U</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&gt;()</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">return</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> make</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">U</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&gt;(</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">make_index_sequence</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">sizeof</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">...(</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Ts<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">)&gt;());</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">private</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 std</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">tuple</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #606;" class=3D"styled-by-prettify">Ts</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">...&gt;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> ts</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">template</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">typename</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">...</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">=
Us</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 make_unique_auto_proxy</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">(</span><span style=3D"color: #606;" class=3D"styled-by-pre=
ttify">Us</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
amp;&amp;...</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> us</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> ts</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">forward</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&lt;</span><span style=3D"color: #606;" class=3D"styled-by-prettif=
y">Ts</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">us</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">)...)</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br><br>=C2=A0 =C2=A0 =C2=A0 </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">template</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> U</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> size_t</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">...</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Is<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0=
 std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">unique_ptr</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">U</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> make</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">index_sequence</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&lt;</span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">Is</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">...&gt;)</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">return</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">make_unique</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">U</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&gt;(</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">std</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">move</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">std</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">::</span><span style=3D"color: #008;" class=3D"styled-by-prettify">get=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span=
><span style=3D"color: #606;" class=3D"styled-by-prettify">Is</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&gt;(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">ts</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">))...);</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br>=C2=A0 <br>=C2=A0 =C2=A0 =C2=A0 </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">template</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">...</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" cla=
ss=3D"styled-by-prettify">Us</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">friend</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> make_unique_auto_proxy</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Us</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">...&gt;</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> make_unique_auto</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(</span><span style=3D"color: #606;" class=3D"styled-by=
-prettify">Us</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&amp;&amp;...);</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><b=
r></span><span style=3D"color: #008;" class=3D"styled-by-prettify">template=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">...</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #606;" class=3D"styled-by-prettify">Ts</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>make_unique_auto_proxy</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color:=
 #606;" class=3D"styled-by-prettify">Ts</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">...&gt;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> make_unique_auto</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">(</span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Ts</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&amp;&amp;...</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> ts</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">return=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> make_uniq=
ue_auto_proxy</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">decay_t</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span styl=
e=3D"color: #606;" class=3D"styled-by-prettify">Ts</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&gt;...&gt;(</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">std</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">forward</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span><span style=3D"color: #606;" class=3D"st=
yled-by-prettify">Ts</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&gt;(</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">ts</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)..=
..);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> main</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> u </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">make_uniqu=
e</span><span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;int&g=
t;</span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 =C2=A0 u </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> mak=
e_unique_auto</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #066;" class=3D"styled-by-prettify">42</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span></div></code></div><=
br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/4fe0e310-9062-4c3f-9886-6c0f9481b19b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4fe0e310-9062-4c3f-9886-6c0f9481b19b=
%40isocpp.org</a>.<br />

------=_Part_5439_1795535786.1479370862110--

------=_Part_5438_2038079715.1479370862109--

.


Author: joseph.thomson@gmail.com
Date: Thu, 17 Nov 2016 00:29:42 -0800 (PST)
Raw View
------=_Part_5708_1601999898.1479371382097
Content-Type: multipart/alternative;
 boundary="----=_Part_5709_1011531359.1479371382098"

------=_Part_5709_1011531359.1479371382098
Content-Type: text/plain; charset=UTF-8



On Thursday, 17 November 2016 16:21:02 UTC+8, joseph....@gmail.com wrote:
>
> On Thursday, 17 November 2016 15:11:41 UTC+8, Victor Dyachenko wrote:
>>
>> May be I'm initially wrong and "upgrading" unique_ptr is a bad idea?
>>
>> My initial task is "late construction" of some members. std::optional is
>> a good solution in most cases, but when member is big and/or seldom used,
>> heap allocation is a better option. I use unique_ptr in such cases but
>> construction suffers from verbosity and, more important, violates DRY
>> principle.
>>
>
> Here's a stupidly over-engineered solution that removes the need to
> specify the type:
>
> #include <memory>
> #include <tuple>
> #include <type_traits>
> #include <utility>
>
> template <typename... Ts>
> class make_unique_auto_proxy {
> public:
>     template<typename U>
>     operator std::unique_ptr<U>() {
>         return make<U>(std::make_index_sequence<sizeof...(Ts)>());
>     }
>
> private:
>     std::tuple<Ts...> ts;
>
>       template <typename... Us>
>     make_unique_auto_proxy(Us&&... us) : ts(std::forward<Ts>(us)...) {
>     }
>
>       template <typename U, size_t... Is>
>     std::unique_ptr<U> make(std::index_sequence<Is...>) {
>         return std::make_unique<U>(std::move(std::get<Is>(ts))...);
>     }
>
>       template <typename... Us>
>     friend make_unique_auto_proxy<Us...> make_unique_auto(Us&&...);
> };
>
> template<typename... Ts>
> make_unique_auto_proxy<Ts...> make_unique_auto(Ts&&... ts) {
>     return make_unique_auto_proxy<std::decay_t<Ts>...>(std::forward<Ts>(ts
> )...);
> }
>
> int main() {
>     auto u = std::make_unique<int>();
>       u = make_unique_auto(42);
> }
>
>
Stupid indentation. Here. I also changed the name to be a bit less verbose:

#include <memory>
#include <tuple>
#include <type_traits>
#include <utility>

template <typename... Ts>
class auto_unique_proxy {
public:
    template<typename U>
    operator std::unique_ptr<U>() {
        return make<U>(std::make_index_sequence<sizeof...(Ts)>());
    }

private:
    std::tuple<Ts...> ts;

    template <typename... Us>
    auto_unique_proxy(Us&&... us) : ts(std::forward<Ts>(us)...) {
    }

    template <typename U, size_t... Is>
    std::unique_ptr<U> make(std::index_sequence<Is...>) {
        return std::make_unique<U>(std::move(std::get<Is>(ts))...);
    }

    template <typename... Us>
    friend auto_unique_proxy<Us...> auto_unique(Us&&...);
};

template<typename... Ts>
auto_unique_proxy<Ts...> auto_unique(Ts&&... ts) {
    return auto_unique_proxy<std::decay_t<Ts>...>(std::forward<Ts>(ts)...);
}

int main() {
    using std::make_unique;

    auto u = make_unique<int>();
    u = auto_unique(42);
}




--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/ac0dc12f-c129-4128-abdc-f36b5456cb1f%40isocpp.org.

------=_Part_5709_1011531359.1479371382098
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Thursday, 17 November 2016 16:21:02 UTC+8, jose=
ph....@gmail.com  wrote:<blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div d=
ir=3D"ltr">On Thursday, 17 November 2016 15:11:41 UTC+8, Victor Dyachenko  =
wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex=
;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">May be I&#39=
;m initially wrong and &quot;upgrading&quot; unique_ptr is a bad idea?<br><=
br>My initial task is &quot;late construction&quot; of some members. <span =
style=3D"font-family:courier new,monospace">std::optional</span> is a good =
solution in most cases, but when member is big and/or seldom used, heap all=
ocation is a better option. I use unique_ptr in such cases but construction=
 suffers from verbosity and, more important, violates DRY principle.<br></d=
iv></blockquote><div><br>Here&#39;s a stupidly over-engineered solution tha=
t removes the need to specify the type:<br><br><div style=3D"background-col=
or:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border=
-width:1px"><code><div><span style=3D"color:#800">#include</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#080">&lt;memory&gt;</span><s=
pan style=3D"color:#000"><br></span><span style=3D"color:#800">#include</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#080">&lt;tuple&=
gt;</span><span style=3D"color:#000"><br></span><span style=3D"color:#800">=
#include</span><span style=3D"color:#000"> </span><span style=3D"color:#080=
">&lt;type_traits&gt;</span><span style=3D"color:#000"><br></span><span sty=
le=3D"color:#800">#include</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#080">&lt;utility&gt;</span><span style=3D"color:#000"><br><b=
r></span><span style=3D"color:#008">template</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#660">&lt;</span><span style=3D"color:#008"=
>typename</span><span style=3D"color:#660">...</span><span style=3D"color:#=
000"> </span><span style=3D"color:#606">Ts</span><span style=3D"color:#660"=
>&gt;</span><span style=3D"color:#000"><br></span><span style=3D"color:#008=
">class</span><span style=3D"color:#000"> make_unique_auto_proxy </span><sp=
an style=3D"color:#660">{</span><span style=3D"color:#000"><br></span><span=
 style=3D"color:#008">public</span><span style=3D"color:#660">:</span><span=
 style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">t=
emplate</span><span style=3D"color:#660">&lt;</span><span style=3D"color:#0=
08">typename</span><span style=3D"color:#000"> U</span><span style=3D"color=
:#660">&gt;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span=
 style=3D"color:#008">operator</span><span style=3D"color:#000"> std</span>=
<span style=3D"color:#660">::</span><span style=3D"color:#000">unique_ptr</=
span><span style=3D"color:#660">&lt;</span><span style=3D"color:#000">U</sp=
an><span style=3D"color:#660">&gt;()</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0=
 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span><span =
style=3D"color:#000"> make</span><span style=3D"color:#660">&lt;</span><spa=
n style=3D"color:#000">U</span><span style=3D"color:#660">&gt;(</span><span=
 style=3D"color:#000">std</span><span style=3D"color:#660">::</span><span s=
tyle=3D"color:#000">make_index_<wbr>sequence</span><span style=3D"color:#66=
0">&lt;</span><span style=3D"color:#008">sizeof</span><span style=3D"color:=
#660">...(</span><span style=3D"color:#606">Ts</span><span style=3D"color:#=
660">)&gt;());</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><s=
pan style=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span>=
<span style=3D"color:#008">private</span><span style=3D"color:#660">:</span=
><span style=3D"color:#000"><br>=C2=A0 =C2=A0 std</span><span style=3D"colo=
r:#660">::</span><span style=3D"color:#000">tuple</span><span style=3D"colo=
r:#660">&lt;</span><span style=3D"color:#606">Ts</span><span style=3D"color=
:#660">...&gt;</span><span style=3D"color:#000"> ts</span><span style=3D"co=
lor:#660">;</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 =C2=A0 <=
/span><span style=3D"color:#008">template</span><span style=3D"color:#000">=
 </span><span style=3D"color:#660">&lt;</span><span style=3D"color:#008">ty=
pename</span><span style=3D"color:#660">...</span><span style=3D"color:#000=
"> </span><span style=3D"color:#606">Us</span><span style=3D"color:#660">&g=
t;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 make_unique_auto_prox=
y</span><span style=3D"color:#660">(</span><span style=3D"color:#606">Us</s=
pan><span style=3D"color:#660">&amp;&amp;...</span><span style=3D"color:#00=
0"> us</span><span style=3D"color:#660">)</span><span style=3D"color:#000">=
 </span><span style=3D"color:#660">:</span><span style=3D"color:#000"> ts</=
span><span style=3D"color:#660">(</span><span style=3D"color:#000">std</spa=
n><span style=3D"color:#660">::</span><span style=3D"color:#000">forward</s=
pan><span style=3D"color:#660">&lt;</span><span style=3D"color:#606">Ts</sp=
an><span style=3D"color:#660">&gt;(</span><span style=3D"color:#000">us</sp=
an><span style=3D"color:#660">)...)</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:#660">}</span><span style=3D"color:#000"=
><br><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">template</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">&lt;</spa=
n><span style=3D"color:#008">typename</span><span style=3D"color:#000"> U</=
span><span style=3D"color:#660">,</span><span style=3D"color:#000"> size_t<=
/span><span style=3D"color:#660">...</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#606">Is</span><span style=3D"color:#660">&gt;</spa=
n><span style=3D"color:#000"><br>=C2=A0 =C2=A0 std</span><span style=3D"col=
or:#660">::</span><span style=3D"color:#000">unique_ptr</span><span style=
=3D"color:#660">&lt;</span><span style=3D"color:#000">U</span><span style=
=3D"color:#660">&gt;</span><span style=3D"color:#000"> make</span><span sty=
le=3D"color:#660">(</span><span style=3D"color:#000">std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">index_sequence</span><s=
pan style=3D"color:#660">&lt;</span><span style=3D"color:#606">Is</span><sp=
an style=3D"color:#660">...<wbr>&gt;)</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span><sp=
an style=3D"color:#000"> std</span><span style=3D"color:#660">::</span><spa=
n style=3D"color:#000">make_unique</span><span style=3D"color:#660">&lt;</s=
pan><span style=3D"color:#000">U</span><span style=3D"color:#660">&gt;(</sp=
an><span style=3D"color:#000">std</span><span style=3D"color:#660">::</span=
><span style=3D"color:#000">move</span><span style=3D"color:#660">(</span><=
span style=3D"color:#000"><wbr>std</span><span style=3D"color:#660">::</spa=
n><span style=3D"color:#008">get</span><span style=3D"color:#660">&lt;</spa=
n><span style=3D"color:#606">Is</span><span style=3D"color:#660">&gt;(</spa=
n><span style=3D"color:#000">ts</span><span style=3D"color:#660">))...);</s=
pan><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"colo=
r:#660">}</span><span style=3D"color:#000"><br>=C2=A0 <br>=C2=A0 =C2=A0 =C2=
=A0 </span><span style=3D"color:#008">template</span><span style=3D"color:#=
000"> </span><span style=3D"color:#660">&lt;</span><span style=3D"color:#00=
8">typename</span><span style=3D"color:#660">...</span><span style=3D"color=
:#000"> </span><span style=3D"color:#606">Us</span><span style=3D"color:#66=
0">&gt;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span sty=
le=3D"color:#008">friend</span><span style=3D"color:#000"> make_unique_auto=
_proxy</span><span style=3D"color:#660">&lt;</span><span style=3D"color:#60=
6">Us</span><span style=3D"color:#660">...&gt;</span><span style=3D"color:#=
000"> make_unique_auto</span><span style=3D"color:#660">(</span><span style=
=3D"color:#606">Us</span><span style=3D"color:#660">&amp;&amp;...);</span><=
span style=3D"color:#000"><br></span><span style=3D"color:#660">};</span><s=
pan style=3D"color:#000"><br><br></span><span style=3D"color:#008">template=
</span><span style=3D"color:#660">&lt;</span><span style=3D"color:#008">typ=
ename</span><span style=3D"color:#660">...</span><span style=3D"color:#000"=
> </span><span style=3D"color:#606">Ts</span><span style=3D"color:#660">&gt=
;</span><span style=3D"color:#000"><br>make_unique_auto_proxy</span><span s=
tyle=3D"color:#660">&lt;</span><span style=3D"color:#606">Ts</span><span st=
yle=3D"color:#660">...&gt;</span><span style=3D"color:#000"> make_unique_au=
to</span><span style=3D"color:#660">(</span><span style=3D"color:#606">Ts</=
span><span style=3D"color:#660">&amp;&amp;...</span><span style=3D"color:#0=
00"> ts</span><span style=3D"color:#660">)</span><span style=3D"color:#000"=
> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span><span style=3D=
"color:#000"> make_unique_auto_proxy</span><span style=3D"color:#660">&lt;<=
/span><span style=3D"color:#000">std</span><span style=3D"color:#660">::</s=
pan><span style=3D"color:#000">de<wbr>cay_t</span><span style=3D"color:#660=
">&lt;</span><span style=3D"color:#606">Ts</span><span style=3D"color:#660"=
>&gt;...&gt;(</span><span style=3D"color:#000">std</span><span style=3D"col=
or:#660">::</span><span style=3D"color:#000">forward</span><span style=3D"c=
olor:#660">&lt;</span><span style=3D"color:#606">Ts</span><span style=3D"co=
lor:#660">&gt;<wbr>(</span><span style=3D"color:#000">ts</span><span style=
=3D"color:#660">)...);</span><span style=3D"color:#000"><br></span><span st=
yle=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span><span =
style=3D"color:#008">int</span><span style=3D"color:#000"> main</span><span=
 style=3D"color:#660">()</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </sp=
an><span style=3D"color:#008">auto</span><span style=3D"color:#000"> u </sp=
an><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> std</sp=
an><span style=3D"color:#660">::</span><span style=3D"color:#000">make_uniq=
ue</span><span style=3D"color:#080">&lt;int&gt;</span><span style=3D"color:=
#660">();</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 u </spa=
n><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> make_uni=
que_auto</span><span style=3D"color:#660">(</span><span style=3D"color:#066=
">42</span><span style=3D"color:#660">);</span><span style=3D"color:#000"><=
br></span><span style=3D"color:#660">}</span></div></code></div><br></div><=
/div></blockquote><div><br>Stupid indentation. Here. I also changed the nam=
e to be a bit less verbose:<br><br><div style=3D"background-color: rgb(250,=
 250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-w=
idth: 1px; overflow-wrap: break-word;" class=3D"prettyprint"><code class=3D=
"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #800;" cl=
ass=3D"styled-by-prettify">#include</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"styl=
ed-by-prettify">&lt;memory&gt;</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br></span><span style=3D"color: #800;" class=3D"styled=
-by-prettify">#include</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-prettif=
y">&lt;tuple&gt;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">=
#include</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;type_tr=
aits&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r></span><span style=3D"color: #800;" class=3D"styled-by-prettify">#include=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #080;" class=3D"styled-by-prettify">&lt;utility&gt;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">template</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">...</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Ts</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
auto_unique_proxy </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">public<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">template</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> U</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">unique_ptr</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">U</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&gt;()</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> make</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">U</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">make_index_sequence</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">sizeof</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">...(</span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">Ts</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">)&gt;());</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">private</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>=C2=A0 =C2=A0 std</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">tuple</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&lt;</span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">Ts</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">...&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
ts</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=C2=A0 =
=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">tem=
plate</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">...</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">Us</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 auto_unique_proxy</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"col=
or: #606;" class=3D"styled-by-prettify">Us</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&amp;&amp;...</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> us</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> ts</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">forward</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">Ts</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">&gt;(</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">us</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">)...)</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><=
br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">template</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> U</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> size_t</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">...</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" c=
lass=3D"styled-by-prettify">Is</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br>=C2=A0 =C2=A0 std</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">unique_ptr</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">U</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> mak=
e</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">index_sequence</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #606;" class=3D"styled-by-prettify">Is</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">...&gt;)</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:=
 #008;" class=3D"styled-by-prettify">return</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">make_unique</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify">U</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">&gt;(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">move</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">std</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">get</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&lt;</span><span style=3D"color: #606;" class=3D"s=
tyled-by-prettify">Is</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">&gt;(</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">ts</span><span style=3D"color: #660;" class=3D"styled-by-prettify">))=
....);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><=
br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">template</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">...</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Us</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">friend</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> auto_unique_proxy</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #606;" class=3D"styled-by-prettify">Us</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">...&gt;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> auto_unique</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Us</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&amp;&amp;...);</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">template</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">typ=
ename</span><span style=3D"color: #660;" class=3D"styled-by-prettify">...</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #606;" class=3D"styled-by-prettify">Ts</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>auto_unique_proxy</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Ts</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">...&gt;</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> auto_unique</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #606;" =
class=3D"styled-by-prettify">Ts</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">&amp;&amp;...</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> ts</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0=
 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">re=
turn</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> auto_=
unique_proxy</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">decay_t</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Ts</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&gt;...&gt;(</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">std</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">forward</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span><span style=3D"color: #606;" class=3D"st=
yled-by-prettify">Ts</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&gt;(</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">ts</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)..=
..);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> main</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><code class=3D"prettyprint"><span style=3D"color: #008;" class=3D"=
styled-by-prettify">=C2=A0=C2=A0=C2=A0 using</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">make_unique</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-=
prettify"></span></code>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> u </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> make_unique</span><span style=3D"color: #080;" class=3D"styled-b=
y-prettify">&lt;int&gt;</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>=C2=A0 =C2=A0 u </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> auto_unique</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">(</span><span style=3D"color: #066;" class=3D"styled-by-prettify=
">42</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span></div></code>=
</div><br>=C2=A0<br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/ac0dc12f-c129-4128-abdc-f36b5456cb1f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ac0dc12f-c129-4128-abdc-f36b5456cb1f=
%40isocpp.org</a>.<br />

------=_Part_5709_1011531359.1479371382098--

------=_Part_5708_1601999898.1479371382097--

.


Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Fri, 18 Nov 2016 13:41:39 -0800 (PST)
Raw View
------=_Part_5299_763733846.1479505299930
Content-Type: multipart/alternative;
 boundary="----=_Part_5300_2142185370.1479505299931"

------=_Part_5300_2142185370.1479505299931
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Wednesday, November 16, 2016 at 10:51:46 PM UTC-8, Victor Dyachenko=20
wrote:
>
> On Thursday, November 17, 2016 at 2:55:17 AM UTC+3, joseph....@gmail.com=
=20
> wrote:
>>
>>
>> How would such a function know how to create a new object for a=20
>> unique_ptr with a custom deleter?
>>
>
> Yes... currently no other member functions create guarded object...=20
> make_unique() is not member and handles special case with default_deleter=
..
>
> May be it can be non-member fuction like this:
>
> template<class T, class... Args>
> void reallocate_unique(std::unique_ptr<T> &p, Args &&... args)
> {
>     p =3D std::make_unique<T>(std::forward<Args>(args)...);
> }
>

If that's the semantics you want, then yes, it should be a non-member=20
function, and you should just write it yourself. I don't think the standard=
=20
library needs to get involved here.
As a bonus, if you control the implementation of this function, you can=20
later decide that the semantics you *really* want are

template<class T, class... Args>
void reallocate_unique(std::unique_ptr<T>& p, Args&&... args)
{
    if (p) {
        *p =3D T(std::forward<Args>(args)...);
    } else {
        p =3D std::make_unique<T>(std::forward<Args>(args)...);
    }
}

since it's a little silly to constantly be churning memory when you might=
=20
have a perfectly good memory block already owned by p.
....And then you might change it back, because you suddenly have to deal=20
with Ts that aren't move-assignable.
....And then you might upgrade to C++17 and rewrite the whole thing using=20
if-constexpr so that it handles both kinds of Ts.

Anyway, you can do all this in your own codebase even if you're stuck with=
=20
C++11. I don't think there's any benefit to be had by trying to get this=20
function into the C++2w standard library.

=E2=80=93Arthur

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/ad2dd51a-e7d8-476e-9328-5fd30627f08e%40isocpp.or=
g.

------=_Part_5300_2142185370.1479505299931
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Wednesday, November 16, 2016 at 10:51:46 PM UTC-8, Vict=
or Dyachenko wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D=
"ltr">On Thursday, November 17, 2016 at 2:55:17 AM UTC+3, <a>joseph....@gma=
il.com</a> wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin=
-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><=
br><div>How would such a function know how to create a new object for a <sp=
an style=3D"font-family:courier new,monospace">unique_ptr</span> with a cus=
tom deleter?<br></div></div></blockquote><div><br>Yes... currently no other=
 member functions create guarded object... <span style=3D"font-family:couri=
er new,monospace">make_unique()</span> is not member and handles special ca=
se with <span style=3D"font-family:courier new,monospace">default_deleter</=
span>.<br><br>May be it can be non-member fuction like this:<br><br><div st=
yle=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);bord=
er-style:solid;border-width:1px"><code><div><span style=3D"color:#008">temp=
late</span><span style=3D"color:#660">&lt;</span><span style=3D"color:#008"=
>class</span><span style=3D"color:#000"> T</span><span style=3D"color:#660"=
>,</span><span style=3D"color:#000"> </span><span style=3D"color:#008">clas=
s</span><span style=3D"color:#660">...</span><span style=3D"color:#000"> </=
span><span style=3D"color:#606">Args</span><span style=3D"color:#660">&gt;<=
/span><span style=3D"color:#000"><br></span><span style=3D"color:#008">void=
</span><span style=3D"color:#000"> reallocate_unique</span><span style=3D"c=
olor:#660">(</span><span style=3D"color:#000">std</span><span style=3D"colo=
r:#660">::</span><span style=3D"color:#000">unique_<wbr>ptr</span><span sty=
le=3D"color:#660">&lt;</span><span style=3D"color:#000">T</span><span style=
=3D"color:#660">&gt;</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">&amp;</span><span style=3D"color:#000">p</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#606">Args</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">&amp;&amp;...</span><span style=3D"color:#000"> args</span><span s=
tyle=3D"color:#660">)</span><span style=3D"color:#000"><br></span><span sty=
le=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 p </=
span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> std</=
span><span style=3D"color:#660">::</span><span style=3D"color:#000">make_un=
ique</span><span style=3D"color:#660">&lt;</span><span style=3D"color:#000"=
>T</span><span style=3D"color:#660">&gt;(</span><span style=3D"color:#000">=
std</span><span style=3D"color:#660">::</span><span style=3D"color:#000">fo=
rwa<wbr>rd</span><span style=3D"color:#660">&lt;</span><span style=3D"color=
:#606">Args</span><span style=3D"color:#660">&gt;(</span><span style=3D"col=
or:#000">args</span><span style=3D"color:#660">)...);</span><span style=3D"=
color:#000"><br></span><span style=3D"color:#660">}</span></div></code></di=
v></div></div></blockquote><div><br></div><div>If that&#39;s the semantics =
you want, then yes, it should be a non-member function, and you should just=
 write it yourself. I don&#39;t think the standard library needs to get inv=
olved here.</div><div>As a bonus, if you control the implementation of this=
 function, you can later decide that the semantics you *really* want are</d=
iv><div><span style=3D"color: rgb(0, 0, 136);"><br></span></div><div class=
=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border: 1px=
 solid rgb(187, 187, 187); word-wrap: break-word;"><code class=3D"prettypri=
nt"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">template</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">class</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">class</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">...</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606=
;" class=3D"styled-by-prettify">Args</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> reallocate_unique</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">unique_p=
tr</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">T</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">&gt;&amp;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> p</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" clas=
s=3D"styled-by-prettify">Args</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">&amp;&amp;...</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> args</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">if</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">p</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify">p </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">forward</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span s=
tyle=3D"color: #606;" class=3D"styled-by-prettify">Args</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&gt;(</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">args</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">)...);</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">else</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 p </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">make_unique</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">forward</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #=
606;" class=3D"styled-by-prettify">Args</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&gt;(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">args</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">)...);</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br></span></div></code></div><div><br>since it&#39;s a little silly to con=
stantly be churning memory when you might have a perfectly good memory bloc=
k already owned by <font face=3D"courier new, monospace">p</font>.</div><di=
v>...And then you might change it back, because you suddenly have to deal w=
ith Ts that aren&#39;t move-assignable.</div><div>...And then you might upg=
rade to C++17 and rewrite the whole thing using if-constexpr so that it han=
dles both kinds of Ts.</div><div><br></div><div>Anyway, you can do all this=
 in your own codebase even if you&#39;re stuck with C++11. I don&#39;t thin=
k there&#39;s any benefit to be had by trying to get this function into the=
 C++2w standard library.</div><div><br></div><div>=E2=80=93Arthur</div></di=
v>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/ad2dd51a-e7d8-476e-9328-5fd30627f08e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ad2dd51a-e7d8-476e-9328-5fd30627f08e=
%40isocpp.org</a>.<br />

------=_Part_5300_2142185370.1479505299931--

------=_Part_5299_763733846.1479505299930--

.