Topic: Choosing the way of initialization in make_<something>


Author: d.n.izvolov@gmail.com
Date: Sun, 26 Feb 2017 03:03:02 -0800 (PST)
Raw View
------=_Part_619_801373.1488106982824
Content-Type: multipart/alternative;
 boundary="----=_Part_620_1766500776.1488106982825"

------=_Part_620_1766500776.1488106982825
Content-Type: text/plain; charset=UTF-8

The essense of the problem may be shown by the std::make_from_tuple
function.

*Case 1: trivial type*

struct trivial
{
    int x;
    double y;
};

make_from_tuple<trivial>(make_tuple(1, 3.14)); // Compilation error.

The example shows that this case is simply not covered by the current
version of the standard library. Trivial type can't be created from a tuple
by std::make_from_tuple function.

*Case 2: the existence of several variants of the constructor*

make_from_tuple<vector<size_t>>(make_tuple(5, 1));
// Which vector should be created?
// [1, 1, 1, 1, 1] or [5, 1]?

In the current edition we'll get "five ones". Ant there is no possibility
to get "five and one".

*Proposed solution*

The main idea is *tag dispatching*.
We create two structs, each of which will signal about the need to call
either round or curly brackets (names are rough):

template <typename T>
struct parens_t {};

template <typename T>
constexpr auto parens = parens_t<T>{};

template <typename T>
struct braces_t {};

template <typename T>
constexpr auto braces = braces_t<T>{};

Usage:

auto a = make_unique(parens<A>, 1, 3); // A(1, 3)
auto b = make_unique(braces<A>, 1, 3); // A{1, 3}

auto c = make_from_tuple(parens<A>, make_tuple(100, 3.14)); // A(100, 3.14)
auto d = make_from_tuple(braces<A>, make_tuple(100, 3.14)); // A{100, 3.14}
// Finally we can call the curly brackets. Yay!

Also note that when using this tag, the object type is inferred from the
tag, that is, it is not necessary to specify it explicitly:

// Then:
auto a = make_shared<very_very_very_long_type_name>(
very_very_very_long_type_name{1, 3});

// Now:
auto b = make_shared(braces<very_very_very_long_type_name>, 1, 3);

The old overloads, of course, remain. The difference is that now we can
explicitly choose the way of initialization.
Similarly it would work with functions that accept a set of parameters to
pass to the constructor, for example, emplace_back.

*Example to follow*

This approach is not new for the standard library. A similar scheme is used
with the tag std::in_place_type, for example, in the constructor of the
std::variant class. This tag indicates that we need to call the constructor
of the emplaced class. But in our case we go a little further. We provide
the opportunity not just to signal that we need to call the constructor,
but to tell which exactly constructor it's supposed to be.

*Summary*

The main point is to give user an opportunity to choose between the
direct-initialization and the direct-list-initialization explicitly. There
are many cases when it matters.

Given solution:

   1. Simplifies programmer's life and enhances the functionality of the
   standard library.
   2. Maintains full backward compatibility. Nothing is broken.
   3. Is quite general. It works with make_shared, make_unique, make_any,
   make_from_tuple, emplace and more.
   4. Seamlessly fits into the standard library and is pretty convenient to
   use.


--
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/ac58c722-5995-4300-b31d-bb508d6fc8e0%40isocpp.org.

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

<div dir=3D"ltr">The essense of the problem may be shown by the <font face=
=3D"courier new, monospace">std::make_from_tuple</font> function.<div><br><=
/div><div><b>Case 1: trivial type</b></div><div><br></div><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">struct</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> trivial<br></span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> x</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">do=
uble</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> y</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><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br><br>make_from_tuple</span><span =
style=3D"color: #080;" class=3D"styled-by-prettify">&lt;trivial&gt;</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">make_tuple</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"colo=
r: #066;" class=3D"styled-by-prettify">1</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: #066;" class=3D"styled-b=
y-prettify">3.14</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: #800;" class=3D"styled-by-prettify">// Compila=
tion error.</span></div></code></div><div><br></div></div><div>The example =
shows that=C2=A0this case is simply not covered by the current version of t=
he standard library. Trivial type can&#39;t be created from a tuple by <fon=
t face=3D"courier new, monospace">std::make_from_tuple</font> function.</di=
v><div><br></div><div><b>Case 2: the existence of several variants of the c=
onstructor</b></div><div><br></div><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"prettyprint"><div class=3D"subpret=
typrint"><span style=3D"color: #000;" class=3D"styled-by-prettify">make_fro=
m_tuple</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">vector</s=
pan><span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;size_t&gt=
;</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">make_tuple</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span =
style=3D"color: #066;" class=3D"styled-by-prettify">5</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: #066;" clas=
s=3D"styled-by-prettify">1</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">));</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span><span style=3D"color: #800;" class=3D"styled-by-prettif=
y">// Which vector should be created?</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br></span><span style=3D"color: #800;" class=3D=
"styled-by-prettify">// [1, 1, 1, 1, 1] or [5, 1]?</span></div></code></div=
><div><br></div></div><div>In the current edition we&#39;ll get &quot;five =
ones&quot;. Ant there is no possibility to get &quot;five and one&quot;.</d=
iv><div><br></div><div><b>Proposed solution</b></div><div><br></div><div>Th=
e main idea is <i>tag dispatching</i>.</div><div>We create two structs, eac=
h of which will signal about the need to call either round or curly bracket=
s (names are rough):</div><div><br></div><div><div class=3D"prettyprint" st=
yle=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187=
, 187); word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"s=
ubprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">te=
mplate</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><spa=
n 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"co=
lor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">struct</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> parens_t </span><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 style=3D"color: #008;" 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"style=
d-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> parens </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> parens_t</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">T</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&gt;{};</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">template</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">typename</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 T</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></span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> braces_t </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">{};</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">template</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> T</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">constexpr</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> braces </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> braces_t</span><span=
 style=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></div></code></div><div=
><br></div></div><div>Usage:</div><div><br></div><div><div class=3D"prettyp=
rint" style=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(=
187, 187, 187); word-wrap: break-word;"><code class=3D"prettyprint"><div cl=
ass=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 a </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> make_unique</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">parens</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">A</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: #066;" class=3D=
"styled-by-prettify">1</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: #066;" class=3D"styled-by-prettify">3</spa=
n><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: #800;" class=3D"styled-by-prettify">// A(1, 3)</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color:=
 #008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> b </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> make_unique</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">braces</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
A</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;,</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #066;" class=3D"styled-by-prettify">1</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: #066;" clas=
s=3D"styled-by-prettify">3</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">/=
/ A{1, 3}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">aut=
o</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> c </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> make_from_tuple</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">parens</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">A</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&gt;,</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> make_tuple</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">(</span><span style=3D"color: #066;" class=3D"s=
tyled-by-prettify">100</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: #066;" class=3D"styled-by-prettify">3.14</=
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: #800;" class=3D"styled-by-prettify">// A(100, 3.14)</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> d </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"> make_from_tuple</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">braces</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify">A</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">&gt;,</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 make_tuple</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>(</span><span style=3D"color: #066;" class=3D"styled-by-prettify">100</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #066;" class=3D"styled-by-prettify">3.14</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: #800;" class=3D"=
styled-by-prettify">// A{100, 3.14}</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span><span style=3D"color: #800;" class=3D"s=
tyled-by-prettify">// Finally we can call the curly brackets. Yay!</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></=
code></div></div><div><br></div><div>Also note that when using this tag, th=
e object type is inferred from the tag, that is, it is not necessary to spe=
cify it explicitly:<br></div><div><br></div><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"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #800;" class=3D"styled-by-prettif=
y">// Then:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> a </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> make_shared</span><span =
style=3D"color: #080;" class=3D"styled-by-prettify">&lt;very_very_very_long=
_type_name&gt;</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">very_=
very_very_long_type_name</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">{</span><span style=3D"color: #066;" class=3D"styled-by-prett=
ify">1</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: #066;" class=3D"styled-by-prettify">3</span><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 style=3D"color: #=
800;" class=3D"styled-by-prettify">// Now:</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> b </span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> make_shared</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">b=
races</span><span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;v=
ery_very_very_long_type_name&gt;</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pret=
tify">1</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: #066;" class=3D"styled-by-prettify">3</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">);</span></div></code></div>=
<div><br></div></div><div>The old overloads, of course, remain. The differe=
nce is that now we can explicitly choose the way of initialization.</div><d=
iv>Similarly it would work with functions that accept a set of parameters t=
o pass to the constructor, for example, <font face=3D"courier new, monospac=
e">emplace_back</font>.</div><div><br></div><div><b>Example to follow</b></=
div><div><br></div><div>This approach is not new for the standard library. =
A similar scheme is used with the tag <font face=3D"courier new, monospace"=
>std::in_place_type</font>, for example, in the constructor of the <font fa=
ce=3D"courier new, monospace">std::variant</font> class. This tag indicates=
 that we need to call the constructor of the emplaced class. But in our cas=
e we go a little further. We provide the opportunity not just to signal tha=
t we need to call the constructor, but to tell which exactly constructor it=
&#39;s supposed to be.</div><div><br></div><div><div><b>Summary</b></div><d=
iv><br></div><div>The main point is to give user an opportunity to choose b=
etween the direct-initialization and the direct-list-initialization explici=
tly. There are many cases when it matters.<br></div><div><br></div><div>Giv=
en solution:</div><div><ol><li>Simplifies programmer&#39;s life and enhance=
s the functionality of the standard library.</li><li>Maintains full backwar=
d compatibility. Nothing is broken.</li><li>Is quite general. It works with=
=C2=A0<font face=3D"courier new, monospace">make_shared</font>,=C2=A0<font =
face=3D"courier new, monospace">make_unique</font>,=C2=A0<font face=3D"cour=
ier new, monospace">make_any</font>,=C2=A0<font face=3D"courier new, monosp=
ace">make_from_tuple</font>, <font face=3D"courier new, monospace">emplace<=
/font> and more.</li><li>Seamlessly fits into the standard library and is p=
retty convenient to use.<br></li></ol></div><div><br></div></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/ac58c722-5995-4300-b31d-bb508d6fc8e0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ac58c722-5995-4300-b31d-bb508d6fc8e0=
%40isocpp.org</a>.<br />

------=_Part_620_1766500776.1488106982825--

------=_Part_619_801373.1488106982824--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sun, 26 Feb 2017 16:00:21 +0100
Raw View
This is a multi-part message in MIME format.
--------------90D7166B4A7869F062C811F3
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 26/02/2017 =C3=A0 12:03, d.n.izvolov@gmail.com a =C3=A9crit :
> The essense of the problem may be shown by the std::make_from_tuple=20
> function.
>
> *Case 1: trivial type*
>
> |
> structtrivial
> {
> intx;
> doubley;
> };
>
> make_from_tuple<trivial>(make_tuple(1,3.14));// Compilation error.
> |
>
> The example shows that this case is simply not covered by the current=20
> version of the standard library. Trivial type can't be created from a=20
> tuple by std::make_from_tuple function.
>
> *Case 2: the existence of several variants of the constructor*
>
> |
> make_from_tuple<vector<size_t>>(make_tuple(5,1));
> // Which vector should be created?
> // [1, 1, 1, 1, 1] or [5, 1]?
> |
>
> In the current edition we'll get "five ones". Ant there is no=20
> possibility to get "five and one".
>
> *Proposed solution*
>
> The main idea is /tag dispatching/.
> We create two structs, each of which will signal about the need to=20
> call either round or curly brackets (names are rough):
>
> |
> template<typenameT>
> structparens_t {};
>
> template<typenameT>
> constexprautoparens =3Dparens_t<T>{};
>
> template<typenameT>
> structbraces_t {};
>
> template<typenameT>
> constexprautobraces =3Dbraces_t<T>{};
> |
>
> Usage:
>
> |
> autoa =3Dmake_unique(parens<A>,1,3);// A(1, 3)
> autob =3Dmake_unique(braces<A>,1,3);// A{1, 3}
>
> autoc =3Dmake_from_tuple(parens<A>,make_tuple(100,3.14));// A(100, 3.14)
> autod =3Dmake_from_tuple(braces<A>,make_tuple(100,3.14));// A{100, 3.14}
> // Finally we can call the curly brackets. Yay!
> |
>
> Also note that when using this tag, the object type is inferred from=20
> the tag, that is, it is not necessary to specify it explicitly:
>
> |
> // Then:
> autoa=20
> =3Dmake_shared<very_very_very_long_type_name>(very_very_very_long_type_na=
me{1,3});
>
> // Now:
> autob =3Dmake_shared(braces<very_very_very_long_type_name>,1,3);
> |
>
> The old overloads, of course, remain. The difference is that now we=20
> can explicitly choose the way of initialization.
> Similarly it would work with functions that accept a set of parameters=20
> to pass to the constructor, for example, emplace_back.
>
> *Example to follow*
>
> This approach is not new for the standard library. A similar scheme is=20
> used with the tag std::in_place_type, for example, in the constructor=20
> of the std::variant class. This tag indicates that we need to call the=20
> constructor of the emplaced class. But in our case we go a little=20
> further. We provide the opportunity not just to signal that we need to=20
> call the constructor, but to tell which exactly constructor it's=20
> supposed to be.
>
> *Summary*
>
> The main point is to give user an opportunity to choose between the=20
> direct-initialization and the direct-list-initialization explicitly.=20
> There are many cases when it matters.
>
> Given solution:
>
>  1. Simplifies programmer's life and enhances the functionality of the
>     standard library.
>  2. Maintains full backward compatibility. Nothing is broken.
>  3. Is quite general. It works with make_shared, make_unique,
>     make_any, make_from_tuple, emplace and more.
>  4. Seamlessly fits into the standard library and is pretty convenient
>     to use.
>
>
I like the idea. Instead of parens/braces we would need something better.

What about considering other kind of constructions as e.g. default=20
initialization, no parens, no braces?

Vicente

--=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/b34f956c-0cca-c50c-bb03-4b1db291b21c%40wanadoo.f=
r.

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

<html>
  <head>
    <meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
  </head>
  <body bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div class=3D"moz-cite-prefix">Le 26/02/2017 =C3=A0 12:03,
      <a class=3D"moz-txt-link-abbreviated" href=3D"mailto:d.n.izvolov@gmai=
l.com">d.n.izvolov@gmail.com</a> a =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote
      cite=3D"mid:ac58c722-5995-4300-b31d-bb508d6fc8e0@isocpp.org"
      type=3D"cite">
      <div dir=3D"ltr">The essense of the problem may be shown by the <font
          face=3D"courier new, monospace">std::make_from_tuple</font>
        function.
        <div><br>
        </div>
        <div><b>Case 1: trivial type</b></div>
        <div><br>
        </div>
        <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"prettyprint">
              <div class=3D"subprettyprint"><span style=3D"color: #008;"
                  class=3D"styled-by-prettify">struct</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">
                  trivial<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 </span><span style=3D"color: #008;"
                  class=3D"styled-by-prettify">int</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> x</s=
pan><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">;</sp=
an><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">double</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> y</s=
pan><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">;</sp=
an><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>
                  <br>
                  make_from_tuple</span><span style=3D"color: #080;"
                  class=3D"styled-by-prettify">&lt;trivial&gt;</span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">make_=
tuple</span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">1</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">3.14<=
/span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">));</=
span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #800;" class=3D"styled-by-prettify">//
                  Compilation error.</span></div>
            </code></div>
          <div><br>
          </div>
        </div>
        <div>The example shows that=C2=A0this case is simply not covered by
          the current version of the standard library. Trivial type
          can't be created from a tuple by <font face=3D"courier new,
            monospace">std::make_from_tuple</font> function.</div>
        <div><br>
        </div>
        <div><b>Case 2: the existence of several variants of the
            constructor</b></div>
        <div><br>
        </div>
        <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"prettyprint">
              <div class=3D"subprettyprint"><span style=3D"color: #000;"
                  class=3D"styled-by-prettify">make_from_tuple</span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">&lt;<=
/span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">vecto=
r</span><span
                  style=3D"color: #080;" class=3D"styled-by-prettify">&lt;s=
ize_t&gt;</span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(=
</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">make_=
tuple</span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">5</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">1</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: #800;"
                  class=3D"styled-by-prettify">// Which vector should be
                  created?</span><span style=3D"color: #000;"
                  class=3D"styled-by-prettify"><br>
                </span><span style=3D"color: #800;"
                  class=3D"styled-by-prettify">// [1, 1, 1, 1, 1] or [5,
                  1]?</span></div>
            </code></div>
          <div><br>
          </div>
        </div>
        <div>In the current edition we'll get "five ones". Ant there is
          no possibility to get "five and one".</div>
        <div><br>
        </div>
        <div><b>Proposed solution</b></div>
        <div><br>
        </div>
        <div>The main idea is <i>tag dispatching</i>.</div>
        <div>We create two structs, each of which will signal about the
          need to call either round or curly brackets (names are rough):</d=
iv>
        <div><br>
        </div>
        <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"prettyprint">
              <div class=3D"subprettyprint"><span style=3D"color: #008;"
                  class=3D"styled-by-prettify">template</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><span
                  style=3D"color: #008;" class=3D"styled-by-prettify">typen=
ame</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> T</s=
pan><span
                  style=3D"color: #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">struct</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">
                  parens_t </span><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 style=3D"color: #008;"
                  class=3D"styled-by-prettify">template</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><span
                  style=3D"color: #008;" class=3D"styled-by-prettify">typen=
ame</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> T</s=
pan><span
                  style=3D"color: #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">constexpr</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #008;" class=3D"styled-by-prettify">auto<=
/span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">
                  parens </span><span style=3D"color: #660;"
                  class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or:
                  #000;" class=3D"styled-by-prettify"> parens_t</span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">&lt;<=
/span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">T</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">&gt;{=
};</span><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"> </sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">&lt;<=
/span><span
                  style=3D"color: #008;" class=3D"styled-by-prettify">typen=
ame</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> T</s=
pan><span
                  style=3D"color: #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">struct</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">
                  braces_t </span><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 style=3D"color: #008;"
                  class=3D"styled-by-prettify">template</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><span
                  style=3D"color: #008;" class=3D"styled-by-prettify">typen=
ame</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> T</s=
pan><span
                  style=3D"color: #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">constexpr</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #008;" class=3D"styled-by-prettify">auto<=
/span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">
                  braces </span><span style=3D"color: #660;"
                  class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or:
                  #000;" class=3D"styled-by-prettify"> braces_t</span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">&lt;<=
/span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">T</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">&gt;{=
};</span></div>
            </code></div>
          <div><br>
          </div>
        </div>
        <div>Usage:</div>
        <div><br>
        </div>
        <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"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"> a </=
span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">=3D</=
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-by-prettify">parens</span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">&lt;<=
/span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">A</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">&gt;,=
</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">1</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">3</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">);</s=
pan><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #800;" class=3D"styled-by-prettify">//
                  A(1, 3)</span><span style=3D"color: #000;"
                  class=3D"styled-by-prettify"><br>
                </span><span style=3D"color: #008;"
                  class=3D"styled-by-prettify">auto</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> b </=
span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">=3D</=
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-by-prettify">braces</span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">&lt;<=
/span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">A</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">&gt;,=
</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">1</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">3</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">);</s=
pan><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #800;" class=3D"styled-by-prettify">//
                  A{1, 3}</span><span style=3D"color: #000;"
                  class=3D"styled-by-prettify"><br>
                  <br>
                </span><span style=3D"color: #008;"
                  class=3D"styled-by-prettify">auto</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> c </=
span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">=3D</=
span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">
                  make_from_tuple</span><span style=3D"color: #660;"
                  class=3D"styled-by-prettify">(</span><span style=3D"color=
:
                  #000;" class=3D"styled-by-prettify">parens</span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">&lt;<=
/span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">A</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">&gt;,=
</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">
                  make_tuple</span><span style=3D"color: #660;"
                  class=3D"styled-by-prettify">(</span><span style=3D"color=
:
                  #066;" class=3D"styled-by-prettify">100</span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">3.14<=
/span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">));</=
span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #800;" class=3D"styled-by-prettify">//
                  A(100, 3.14)</span><span style=3D"color: #000;"
                  class=3D"styled-by-prettify"><br>
                </span><span style=3D"color: #008;"
                  class=3D"styled-by-prettify">auto</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> d </=
span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">=3D</=
span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">
                  make_from_tuple</span><span style=3D"color: #660;"
                  class=3D"styled-by-prettify">(</span><span style=3D"color=
:
                  #000;" class=3D"styled-by-prettify">braces</span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">&lt;<=
/span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">A</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">&gt;,=
</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">
                  make_tuple</span><span style=3D"color: #660;"
                  class=3D"styled-by-prettify">(</span><span style=3D"color=
:
                  #066;" class=3D"styled-by-prettify">100</span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">3.14<=
/span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">));</=
span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #800;" class=3D"styled-by-prettify">//
                  A{100, 3.14}</span><span style=3D"color: #000;"
                  class=3D"styled-by-prettify"><br>
                </span><span style=3D"color: #800;"
                  class=3D"styled-by-prettify">// Finally we can call the
                  curly brackets. Yay!</span><span style=3D"color: #000;"
                  class=3D"styled-by-prettify"><br>
                </span></div>
            </code></div>
        </div>
        <div><br>
        </div>
        <div>Also note that when using this tag, the object type is
          inferred from the tag, that is, it is not necessary to specify
          it explicitly:<br>
        </div>
        <div><br>
        </div>
        <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"prettyprint">
              <div class=3D"subprettyprint"><span style=3D"color: #800;"
                  class=3D"styled-by-prettify">// Then:</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"><br>
                </span><span style=3D"color: #008;"
                  class=3D"styled-by-prettify">auto</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> a </=
span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">=3D</=
span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">
                  make_shared</span><span style=3D"color: #080;"
                  class=3D"styled-by-prettify">&lt;very_very_very_long_type=
_name&gt;</span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">very_=
very_very_long_type_name</span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">{</sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">1</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">3</sp=
an><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 style=3D"color: #800;"
                  class=3D"styled-by-prettify">// Now:</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"><br>
                </span><span style=3D"color: #008;"
                  class=3D"styled-by-prettify">auto</span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> b </=
span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">=3D</=
span><span
                  style=3D"color: #000;" class=3D"styled-by-prettify">
                  make_shared</span><span style=3D"color: #660;"
                  class=3D"styled-by-prettify">(</span><span style=3D"color=
:
                  #000;" class=3D"styled-by-prettify">braces</span><span
                  style=3D"color: #080;" class=3D"styled-by-prettify">&lt;v=
ery_very_very_long_type_name&gt;</span><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">1</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span
                  style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
                  style=3D"color: #066;" class=3D"styled-by-prettify">3</sp=
an><span
                  style=3D"color: #660;" class=3D"styled-by-prettify">);</s=
pan></div>
            </code></div>
          <div><br>
          </div>
        </div>
        <div>The old overloads, of course, remain. The difference is
          that now we can explicitly choose the way of initialization.</div=
>
        <div>Similarly it would work with functions that accept a set of
          parameters to pass to the constructor, for example, <font
            face=3D"courier new, monospace">emplace_back</font>.</div>
        <div><br>
        </div>
        <div><b>Example to follow</b></div>
        <div><br>
        </div>
        <div>This approach is not new for the standard library. A
          similar scheme is used with the tag <font face=3D"courier new,
            monospace">std::in_place_type</font>, for example, in the
          constructor of the <font face=3D"courier new, monospace">std::var=
iant</font>
          class. This tag indicates that we need to call the constructor
          of the emplaced class. But in our case we go a little further.
          We provide the opportunity not just to signal that we need to
          call the constructor, but to tell which exactly constructor
          it's supposed to be.</div>
        <div><br>
        </div>
        <div>
          <div><b>Summary</b></div>
          <div><br>
          </div>
          <div>The main point is to give user an opportunity to choose
            between the direct-initialization and the
            direct-list-initialization explicitly. There are many cases
            when it matters.<br>
          </div>
          <div><br>
          </div>
          <div>Given solution:</div>
          <div>
            <ol>
              <li>Simplifies programmer's life and enhances the
                functionality of the standard library.</li>
              <li>Maintains full backward compatibility. Nothing is
                broken.</li>
              <li>Is quite general. It works with=C2=A0<font face=3D"courie=
r
                  new, monospace">make_shared</font>,=C2=A0<font
                  face=3D"courier new, monospace">make_unique</font>,=C2=A0=
<font
                  face=3D"courier new, monospace">make_any</font>,=C2=A0<fo=
nt
                  face=3D"courier new, monospace">make_from_tuple</font>,
                <font face=3D"courier new, monospace">emplace</font> and
                more.</li>
              <li>Seamlessly fits into the standard library and is
                pretty convenient to use.<br>
              </li>
            </ol>
          </div>
          <div><br>
          </div>
        </div>
      </div>
    </blockquote>
    I like the idea. Instead of parens/braces we would need something
    better.<br>
    <br>
    What about considering other kind of constructions as e.g. default
    initialization, no parens, no braces?<br>
    <br>
    Vicente<br>
  </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/b34f956c-0cca-c50c-bb03-4b1db291b21c%=
40wanadoo.fr?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/b34f956c-0cca-c50c-bb03-4b1db291b21c=
%40wanadoo.fr</a>.<br />

--------------90D7166B4A7869F062C811F3--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 26 Feb 2017 07:03:15 -0800 (PST)
Raw View
------=_Part_634_1509073911.1488121395510
Content-Type: multipart/alternative;
 boundary="----=_Part_635_1495197059.1488121395511"

------=_Part_635_1495197059.1488121395511
Content-Type: text/plain; charset=UTF-8

On Sunday, February 26, 2017 at 6:03:03 AM UTC-5, d.n.i...@gmail.com wrote:
>
> The essense of the problem may be shown by the std::make_from_tuple
> function.
>
> *Case 1: trivial type*
>
> struct trivial
> {
>     int x;
>     double y;
> };
>
> make_from_tuple<trivial>(make_tuple(1, 3.14)); // Compilation error.
>
> The example shows that this case is simply not covered by the current
> version of the standard library. Trivial type can't be created from a tuple
> by std::make_from_tuple function.
>

See LWG 2089 <http://cplusplus.github.io/LWG/lwg-active.html#2089>.


>
> *Case 2: the existence of several variants of the constructor*
>
> make_from_tuple<vector<size_t>>(make_tuple(5, 1));
> // Which vector should be created?
> // [1, 1, 1, 1, 1] or [5, 1]?
>
> In the current edition we'll get "five ones". Ant there is no possibility
> to get "five and one".
>

Why would you want to? If you wanted "five and one", you would pass an
`initializer_list`. Yes, it's longer, but so be it.

*Proposed solution*
>
> The main idea is *tag dispatching*.
> We create two structs, each of which will signal about the need to call
> either round or curly brackets (names are rough):
>
> template <typename T>
> struct parens_t {};
>
> template <typename T>
> constexpr auto parens = parens_t<T>{};
>
> template <typename T>
> struct braces_t {};
>
> template <typename T>
> constexpr auto braces = braces_t<T>{};
>
> Usage:
>
> auto a = make_unique(parens<A>, 1, 3); // A(1, 3)
> auto b = make_unique(braces<A>, 1, 3); // A{1, 3}
>
> auto c = make_from_tuple(parens<A>, make_tuple(100, 3.14)); // A(100,
> 3.14)
> auto d = make_from_tuple(braces<A>, make_tuple(100, 3.14)); // A{100,
> 3.14}
> // Finally we can call the curly brackets. Yay!
>
> Also note that when using this tag, the object type is inferred from the
> tag, that is, it is not necessary to specify it explicitly:
>
> // Then:
> auto a = make_shared<very_very_very_long_type_name>(
> very_very_very_long_type_name{1, 3});
>
> // Now:
> auto b = make_shared(braces<very_very_very_long_type_name>, 1, 3);
>
> The old overloads, of course, remain. The difference is that now we can
> explicitly choose the way of initialization.
> Similarly it would work with functions that accept a set of parameters to
> pass to the constructor, for example, emplace_back.
>
> *Example to follow*
>
> This approach is not new for the standard library. A similar scheme is
> used with the tag std::in_place_type, for example, in the constructor of
> the std::variant class. This tag indicates that we need to call the
> constructor of the emplaced class. But in our case we go a little further.
> We provide the opportunity not just to signal that we need to call the
> constructor, but to tell which exactly constructor it's supposed to be.
>
> *Summary*
>
> The main point is to give user an opportunity to choose between the
> direct-initialization and the direct-list-initialization explicitly. There
> are many cases when it matters.
>
> Given solution:
>
>    1. Simplifies programmer's life and enhances the functionality of the
>    standard library.
>    2. Maintains full backward compatibility. Nothing is broken.
>    3. Is quite general. It works with make_shared, make_unique, make_any,
>    make_from_tuple, emplace and more.
>    4. Seamlessly fits into the standard library and is pretty convenient
>    to use.
>
> The principle downside of this is that it enhances *only* "the
functionality of the standard library". Which means that if someone writes
their own types with such indirect initialization capabilities, they would
have to manually provide such functionality. Every time. And existing
functions would have to be updated as well.

If you're going to try to establish such a convention through the library,
then you need lower-level support. I would strongly encourage you to add a
`std::initialize<T>` function to the library which would do the low-level
dispatching work. This probably won't get used by novices, but at least
experts will be able to easily write functions that adhere to the standard
library's conventions on this sort of thing.

Also, I advise you to remove the `T` to be constructed from the tag's
typename. The reason being that there are several indirect initialization
cases where `T` is well-defined. `vector<int>::emplace` cannot emplace a
`float` or a `SomeType`; it will only initialize an `int`. So why do we
have to say it again? For the `make/allocate_` style functions, you're
going to have to specify the type anyway. So why is it better on the tag
than the function call? The only place where putting it on the tag would be
a win would be with `variant`/`any`'s `in_place_type` tagged initialization.

template<typename T, typename ...Args>
T initialize(Args &&...args)
{
  return T(std::forward<Args>(args)...);
}

template<typename T, typename ...Args>
T initialize(std::construct_t, Args &&...args)
{
  return T(std::forward<Args>(args)...);
}

template<typename T, typename ...Args>
T initialize(std::list_init_t, Args &&...args)
{
  return T{std::forward<Args>(args)...};
}

I changed the names to match standard terminology. But you get the general
idea.

In any case, I maintain a list of various fixes for this initialization
problem
<https://github.com/NicolBolas/Proposal-Ideas/blob/master/Towards%20a%20Fix%20For%20LWG%202089.md>.
This one is already on that list.

--
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/6d4d25f7-275e-48d0-976e-3d9c4deb4fbd%40isocpp.org.

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

<div dir=3D"ltr">On Sunday, February 26, 2017 at 6:03:03 AM UTC-5, d.n.i...=
@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr">The essense of the problem may be shown by the <font face=3D"courier ne=
w, monospace">std::make_from_tuple</font> function.<div><br></div><div><b>C=
ase 1: trivial type</b></div><div><br></div><div><div style=3D"background-c=
olor:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:break-wor=
d"><code><div><span style=3D"color:#008">struct</span><span style=3D"color:=
#000"> trivial<br></span><span style=3D"color:#660">{</span><span style=3D"=
color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">int</span><=
span style=3D"color:#000"> x</span><span style=3D"color:#660">;</span><span=
 style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">d=
ouble</span><span style=3D"color:#000"> y</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><br>make_from_tuple</span><span style=
=3D"color:#080">&lt;trivial&gt;</span><span style=3D"color:#660">(</span><s=
pan style=3D"color:#000">make_<wbr>tuple</span><span style=3D"color:#660">(=
</span><span style=3D"color:#066">1</span><span style=3D"color:#660">,</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#066">3.14</span>=
<span style=3D"color:#660">));</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#800">// Compilation error.</span></div></code></div><div=
><br></div></div><div>The example shows that=C2=A0this case is simply not c=
overed by the current version of the standard library. Trivial type can&#39=
;t be created from a tuple by <font face=3D"courier new, monospace">std::ma=
ke_from_tuple</font> function.</div></div></blockquote><div><br>See <a href=
=3D"http://cplusplus.github.io/LWG/lwg-active.html#2089">LWG 2089</a>.<br>=
=C2=A0</div><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"><=
div><br></div><div><b>Case 2: the existence of several variants of the cons=
tructor</b></div><div><br></div><div><div style=3D"background-color:rgb(250=
,250,250);border:1px solid rgb(187,187,187);word-wrap:break-word"><code><di=
v><span style=3D"color:#000">make_from_tuple</span><span style=3D"color:#66=
0">&lt;</span><span style=3D"color:#000">vector</span><span style=3D"color:=
#080">&lt;size_t&gt;</span><span style=3D"color:#660"><wbr>&gt;(</span><spa=
n style=3D"color:#000">make_tuple</span><span style=3D"color:#660">(</span>=
<span style=3D"color:#066">5</span><span style=3D"color:#660">,</span><span=
 style=3D"color:#000"> </span><span style=3D"color:#066">1</span><span styl=
e=3D"color:#660">));</span><span style=3D"color:#000"><br></span><span styl=
e=3D"color:#800">// Which vector should be created?</span><span style=3D"co=
lor:#000"><br></span><span style=3D"color:#800">// [1, 1, 1, 1, 1] or [5, 1=
]?</span></div></code></div><div><br></div></div><div>In the current editio=
n we&#39;ll get &quot;five ones&quot;. Ant there is no possibility to get &=
quot;five and one&quot;.</div></div></blockquote><div><br>Why would you wan=
t to? If you wanted &quot;five and one&quot;, you would pass an `initialize=
r_list`. Yes, it&#39;s longer, but so be it.<br><br></div><blockquote class=
=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #cc=
c solid;padding-left: 1ex;"><div dir=3D"ltr"><div><b>Proposed solution</b><=
/div><div><br></div><div>The main idea is <i>tag dispatching</i>.</div><div=
>We create two structs, each of which will signal about the need to call ei=
ther round or curly brackets (names are rough):</div><div><br></div><div><d=
iv style=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,187,=
187);word-wrap:break-word"><code><div><span style=3D"color:#008">template</=
span><span style=3D"color:#000"> </span><span style=3D"color:#660">&lt;</sp=
an><span style=3D"color:#008">typename</span><span style=3D"color:#000"> T<=
/span><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"><br>=
</span><span style=3D"color:#008">struct</span><span style=3D"color:#000"> =
parens_t </span><span style=3D"color:#660">{};</span><span style=3D"color:#=
000"><br><br></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">typename</span><span style=3D"color:#000"> T</span><span st=
yle=3D"color:#660">&gt;</span><span style=3D"color:#000"><br></span><span s=
tyle=3D"color:#008">constexpr</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#008">auto</span><span style=3D"color:#000"> parens </span=
><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> parens_t<=
/span><span style=3D"color:#660">&lt;</span><span style=3D"color:#000">T</s=
pan><span style=3D"color:#660">&gt;{};</span><span style=3D"color:#000"><br=
><br></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:#0=
08">typename</span><span style=3D"color:#000"> T</span><span style=3D"color=
:#660">&gt;</span><span style=3D"color:#000"><br></span><span style=3D"colo=
r:#008">struct</span><span style=3D"color:#000"> braces_t </span><span styl=
e=3D"color:#660">{};</span><span style=3D"color:#000"><br><br></span><span =
style=3D"color:#008">template</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">&lt;</span><span style=3D"color:#008">typename</span=
><span style=3D"color:#000"> T</span><span style=3D"color:#660">&gt;</span>=
<span style=3D"color:#000"><br></span><span style=3D"color:#008">constexpr<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#008">auto</s=
pan><span style=3D"color:#000"> braces </span><span style=3D"color:#660">=
=3D</span><span style=3D"color:#000"> braces_t</span><span style=3D"color:#=
660">&lt;</span><span style=3D"color:#000">T</span><span style=3D"color:#66=
0">&gt;{};</span></div></code></div><div><br></div></div><div>Usage:</div><=
div><br></div><div><div style=3D"background-color:rgb(250,250,250);border:1=
px solid rgb(187,187,187);word-wrap:break-word"><code><div><span style=3D"c=
olor:#008">auto</span><span style=3D"color:#000"> a </span><span style=3D"c=
olor:#660">=3D</span><span style=3D"color:#000"> make_unique</span><span st=
yle=3D"color:#660">(</span><span style=3D"color:#000">parens</span><span st=
yle=3D"color:#660">&lt;</span><span style=3D"color:#000">A</span><span styl=
e=3D"color:#660">&gt;,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#066">1</span><span style=3D"color:#660">,</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#066">3</span><span style=3D"color:=
#660">);</span><span style=3D"color:#000"> </span><span style=3D"color:#800=
">// A(1, 3)</span><span style=3D"color:#000"><br></span><span style=3D"col=
or:#008">auto</span><span style=3D"color:#000"> b </span><span style=3D"col=
or:#660">=3D</span><span style=3D"color:#000"> make_unique</span><span styl=
e=3D"color:#660">(</span><span style=3D"color:#000">braces</span><span styl=
e=3D"color:#660">&lt;</span><span style=3D"color:#000">A</span><span style=
=3D"color:#660">&gt;,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#066">1</span><span style=3D"color:#660">,</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#066">3</span><span style=3D"color:=
#660">);</span><span style=3D"color:#000"> </span><span style=3D"color:#800=
">// A{1, 3}</span><span style=3D"color:#000"><br><br></span><span style=3D=
"color:#008">auto</span><span style=3D"color:#000"> c </span><span style=3D=
"color:#660">=3D</span><span style=3D"color:#000"> make_from_tuple</span><s=
pan style=3D"color:#660">(</span><span style=3D"color:#000">parens</span><s=
pan style=3D"color:#660">&lt;</span><span style=3D"color:#000">A</span><spa=
n style=3D"color:#660">&gt;,</span><span style=3D"color:#000"> make_tuple</=
span><span style=3D"color:#660">(</span><span style=3D"color:#066">100</spa=
n><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#066">3.14</span><span style=3D"color:#660">));</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#800">// A(100, 3.14)<=
/span><span style=3D"color:#000"><br></span><span style=3D"color:#008">auto=
</span><span style=3D"color:#000"> d </span><span style=3D"color:#660">=3D<=
/span><span style=3D"color:#000"> make_from_tuple</span><span style=3D"colo=
r:#660">(</span><span style=3D"color:#000">braces</span><span style=3D"colo=
r:#660">&lt;</span><span style=3D"color:#000">A</span><span style=3D"color:=
#660">&gt;,</span><span style=3D"color:#000"> make_tuple</span><span style=
=3D"color:#660">(</span><span style=3D"color:#066">100</span><span style=3D=
"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#066">3.14</span><span style=3D"color:#660">));</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#800">// A{100, 3.14}</span><span styl=
e=3D"color:#000"><br></span><span style=3D"color:#800">// Finally we can ca=
ll the curly brackets. Yay!</span><span style=3D"color:#000"><br></span></d=
iv></code></div></div><div><br></div><div>Also note that when using this ta=
g, the object type is inferred from the tag, that is, it is not necessary t=
o specify it explicitly:<br></div><div><br></div><div><div style=3D"backgro=
und-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:brea=
k-word"><code><div><span style=3D"color:#800">// Then:</span><span style=3D=
"color:#000"><br></span><span style=3D"color:#008">auto</span><span style=
=3D"color:#000"> a </span><span style=3D"color:#660">=3D</span><span style=
=3D"color:#000"> make_shared</span><span style=3D"color:#080">&lt;very_very=
_very_<wbr>long_type_name&gt;</span><span style=3D"color:#660">(</span><spa=
n style=3D"color:#000">very_very_<wbr>very_long_type_name</span><span style=
=3D"color:#660">{</span><span style=3D"color:#066">1</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:=
#066">3</span><span style=3D"color:#660">});</span><span style=3D"color:#00=
0"><br><br></span><span style=3D"color:#800">// Now:</span><span style=3D"c=
olor:#000"><br></span><span style=3D"color:#008">auto</span><span style=3D"=
color:#000"> b </span><span style=3D"color:#660">=3D</span><span style=3D"c=
olor:#000"> make_shared</span><span style=3D"color:#660">(</span><span styl=
e=3D"color:#000">braces</span><span style=3D"color:#080">&lt;very_very_<wbr=
>very_long_type_name&gt;</span><span style=3D"color:#660">,</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#066">1</span><span style=3D=
"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#066">3</span><span style=3D"color:#660">);</span></div></code></div><div=
><br></div></div><div>The old overloads, of course, remain. The difference =
is that now we can explicitly choose the way of initialization.</div><div>S=
imilarly it would work with functions that accept a set of parameters to pa=
ss to the constructor, for example, <font face=3D"courier new, monospace">e=
mplace_back</font>.</div><div><br></div><div><b>Example to follow</b></div>=
<div><br></div><div>This approach is not new for the standard library. A si=
milar scheme is used with the tag <font face=3D"courier new, monospace">std=
::in_place_type</font>, for example, in the constructor of the <font face=
=3D"courier new, monospace">std::variant</font> class. This tag indicates t=
hat we need to call the constructor of the emplaced class. But in our case =
we go a little further. We provide the opportunity not just to signal that =
we need to call the constructor, but to tell which exactly constructor it&#=
39;s supposed to be.</div><div><br></div><div><div><b>Summary</b></div><div=
><br></div><div>The main point is to give user an opportunity to choose bet=
ween the direct-initialization and the direct-list-initialization explicitl=
y. There are many cases when it matters.<br></div><div><br></div><div>Given=
 solution:</div><div><ol><li>Simplifies programmer&#39;s life and enhances =
the functionality of the standard library.</li><li>Maintains full backward =
compatibility. Nothing is broken.</li><li>Is quite general. It works with=
=C2=A0<font face=3D"courier new, monospace">make_shared</font>,=C2=A0<font =
face=3D"courier new, monospace">make_unique</font>,<wbr>=C2=A0<font face=3D=
"courier new, monospace">make_any</font>,=C2=A0<font face=3D"courier new, m=
onospace">make_from_tuple</font>, <font face=3D"courier new, monospace">emp=
lace</font> and more.</li><li>Seamlessly fits into the standard library and=
 is pretty convenient to use.<br></li></ol></div></div></div></blockquote><=
div>The principle downside of this is that it enhances <i>only</i> &quot;th=
e functionality of the standard library&quot;. Which means that if someone =
writes their own types with such indirect initialization capabilities, they=
 would have to manually provide such functionality. Every time. And existin=
g functions would have to be updated as well.<br><br>If you&#39;re going to=
 try to establish such a convention through the library, then you need lowe=
r-level support. I would strongly encourage you to add a `std::initialize&l=
t;T&gt;` function to the library which would do the low-level dispatching w=
ork. This probably won&#39;t get used by novices, but at least experts will=
 be able to easily write functions that adhere to the standard library&#39;=
s conventions on this sort of thing.<br><br>Also, I advise you to remove th=
e `T` to be constructed from the tag&#39;s typename. The reason being that =
there are several indirect initialization cases where `T` is well-defined. =
`vector&lt;int&gt;::emplace` cannot emplace a `float` or a `SomeType`; it w=
ill only initialize an `int`. So why do we have to say it again? For the `m=
ake/allocate_` style functions, you&#39;re going to have to specify the typ=
e anyway. So why is it better on the tag than the function call? The only p=
lace where putting it on the tag would be a win would be with `variant`/`an=
y`&#39;s `in_place_type` tagged initialization.<br><br><div style=3D"backgr=
ound-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-st=
yle: solid; border-width: 1px; overflow-wrap: break-word;" class=3D"prettyp=
rint"><code class=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"co=
lor: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"colo=
r: #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"style=
d-by-prettify">typename</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">...</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Arg=
s</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>T initializ=
e</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><=
span style=3D"color: #606;" class=3D"styled-by-prettify">Args</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&amp;&amp;...</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">args</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></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 </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(</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><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span styl=
e=3D"color: #606;" class=3D"styled-by-prettify">Args</span><span style=3D"c=
olor: #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;" cl=
ass=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-b=
y-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">template</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">typename</span><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 sty=
le=3D"color: #008;" class=3D"styled-by-prettify">typename</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: #606;=
" class=3D"styled-by-prettify">Args</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>T initialize</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>construct_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;" class=3D"styled-by-prettify">Args</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">&amp;&amp;...</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">args</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></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 </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(</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><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span styl=
e=3D"color: #606;" class=3D"styled-by-prettify">Args</span><span style=3D"c=
olor: #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;" cl=
ass=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-b=
y-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">template</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">typename</span><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 sty=
le=3D"color: #008;" class=3D"styled-by-prettify">typename</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: #606;=
" class=3D"styled-by-prettify">Args</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>T initialize</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>list_init_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;" class=3D"styled-by-prettify">Args</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">&amp;&amp;...</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">args</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></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 </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">{</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><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span styl=
e=3D"color: #606;" class=3D"styled-by-prettify">Args</span><span style=3D"c=
olor: #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;" cl=
ass=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">}</span></div></code></div><br>I changed the names to =
match standard terminology. But you get the general idea.<br><br>In any cas=
e, I maintain a <a href=3D"https://github.com/NicolBolas/Proposal-Ideas/blo=
b/master/Towards%20a%20Fix%20For%20LWG%202089.md">list of various fixes for=
 this initialization problem</a>. This one is already on that list.<br></di=
v></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/6d4d25f7-275e-48d0-976e-3d9c4deb4fbd%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6d4d25f7-275e-48d0-976e-3d9c4deb4fbd=
%40isocpp.org</a>.<br />

------=_Part_635_1495197059.1488121395511--

------=_Part_634_1509073911.1488121395510--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 26 Feb 2017 07:24:39 -0800 (PST)
Raw View
------=_Part_2610_1196478496.1488122679734
Content-Type: multipart/alternative;
 boundary="----=_Part_2611_2116360653.1488122679735"

------=_Part_2611_2116360653.1488122679735
Content-Type: text/plain; charset=UTF-8

On Sunday, February 26, 2017 at 10:00:26 AM UTC-5, Vicente J. Botet Escriba
wrote:
>
> I like the idea. Instead of parens/braces we would need something better.
>
> What about considering other kind of constructions as e.g. default
> initialization, no parens, no braces?
>

Default initialization has to be a language feature. There's really no way
for a function to return a default initialized object while simultaneously
taking advantage of guaranteed elision. Oh, you can do `T t; return t`, but
that requires that `T` be copy/moveable.

To do this properly, especially if you want to expose this for other users
to use, it has to be a language feature of some kind, something that would
allow you to return a default initialized temporary.

--
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/9f34b0ff-86f5-4b1d-a5a4-17b244a095a6%40isocpp.org.

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

<div dir=3D"ltr">On Sunday, February 26, 2017 at 10:00:26 AM UTC-5, Vicente=
 J. Botet Escriba wrote:<blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
 =20
   =20
 =20
  <div bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div>
    </div>
   =20
    I like the idea. Instead of parens/braces we would need something
    better.<br>
    <br>
    What about considering other kind of constructions as e.g. default
    initialization, no parens, no braces?<br></div></blockquote><div><br>De=
fault initialization has to be a language feature. There&#39;s really no wa=
y for a function to return a default initialized object while simultaneousl=
y taking advantage of guaranteed elision. Oh, you can do `T t; return t`, b=
ut that requires that `T` be copy/moveable.<br><br>To do this properly, esp=
ecially if you want to expose this for other users to use, it has to be a l=
anguage feature of some kind, something that would allow you to return a de=
fault initialized temporary.<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/9f34b0ff-86f5-4b1d-a5a4-17b244a095a6%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/9f34b0ff-86f5-4b1d-a5a4-17b244a095a6=
%40isocpp.org</a>.<br />

------=_Part_2611_2116360653.1488122679735--

------=_Part_2610_1196478496.1488122679734--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sun, 26 Feb 2017 17:27:05 +0100
Raw View
This is a multi-part message in MIME format.
--------------9A389E135A84DA13063A702A
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 26/02/2017 =C3=A0 16:24, Nicol Bolas a =C3=A9crit :
> On Sunday, February 26, 2017 at 10:00:26 AM UTC-5, Vicente J. Botet=20
> Escriba wrote:
>
>     I like the idea. Instead of parens/braces we would need something
>     better.
>
>     What about considering other kind of constructions as e.g. default
>     initialization, no parens, no braces?
>
>
> Default initialization has to be a language feature. There's really no=20
> way for a function to return a default initialized object while=20
> simultaneously taking advantage of guaranteed elision. Oh, you can do=20
> `T t; return t`, but that requires that `T` be copy/moveable.
>
> To do this properly, especially if you want to expose this for other=20
> users to use, it has to be a language feature of some kind, something=20
> that would allow you to return a default initialized temporary.

I can want to create e.g. a unique_ptr<POD> with the POD uninitialized,=20
isn't it?

|autoa =3Dmake_unique(uninitialized<POD>);// as if new POD
|
or  zero initialized

|autoa =3Dmake_unique(zero_initialized<POD>);// as if new POD{}
|

Am I missing surely something important.

Vicente

--=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/7754ea9b-f018-7185-4e58-266b5406abb1%40wanadoo.f=
r.

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

<html>
  <head>
    <meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
  </head>
  <body bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div class=3D"moz-cite-prefix">Le 26/02/2017 =C3=A0 16:24, Nicol Bolas =
a
      =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote
      cite=3D"mid:9f34b0ff-86f5-4b1d-a5a4-17b244a095a6@isocpp.org"
      type=3D"cite">
      <div dir=3D"ltr">On Sunday, February 26, 2017 at 10:00:26 AM UTC-5,
        Vicente J. Botet Escriba wrote:
        <blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:
          0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
          <div bgcolor=3D"#FFFFFF" text=3D"#000000">
            <div> </div>
            I like the idea. Instead of parens/braces we would need
            something better.<br>
            <br>
            What about considering other kind of constructions as e.g.
            default initialization, no parens, no braces?<br>
          </div>
        </blockquote>
        <div><br>
          Default initialization has to be a language feature. There's
          really no way for a function to return a default initialized
          object while simultaneously taking advantage of guaranteed
          elision. Oh, you can do `T t; return t`, but that requires
          that `T` be copy/moveable.<br>
          <br>
          To do this properly, especially if you want to expose this for
          other users to use, it has to be a language feature of some
          kind, something that would allow you to return a default
          initialized temporary.<br>
        </div>
      </div>
    </blockquote>
    <br>
    I can want to create e.g. a unique_ptr&lt;POD&gt; with the POD
    uninitialized, isn't it?<br>
    <br>
    <code class=3D"prettyprint"><span style=3D"color: #008;"
        class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;=
"
        class=3D"styled-by-prettify"> a </span><span style=3D"color: #660;"
        class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;"
        class=3D"styled-by-prettify"> make_unique</span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">(uninitialized<=
/span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><spa=
n
        style=3D"color: #000;" class=3D"styled-by-prettify">POD</span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><spa=
n
        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: #800;" class=3D"styled-by-prettify">// as if new PO=
D</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify"><br>
      </span></code><br>
    or=C2=A0 zero initialized <br>
    <br>
    <code class=3D"prettyprint"><span style=3D"color: #008;"
        class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;=
"
        class=3D"styled-by-prettify"> a </span><span style=3D"color: #660;"
        class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;"
        class=3D"styled-by-prettify"> make_unique</span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">(zero_initializ=
ed</span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><spa=
n
        style=3D"color: #000;" class=3D"styled-by-prettify">POD</span><span
        style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><spa=
n
        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: #800;" class=3D"styled-by-prettify">// as if new PO=
D</span><span
        style=3D"color: #000;" class=3D"styled-by-prettify">{}<br>
      </span></code><br>
    <br>
    Am I missing surely something important.<br>
    <br>
    Vicente<br>
  </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/7754ea9b-f018-7185-4e58-266b5406abb1%=
40wanadoo.fr?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/7754ea9b-f018-7185-4e58-266b5406abb1=
%40wanadoo.fr</a>.<br />

--------------9A389E135A84DA13063A702A--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 26 Feb 2017 08:38:31 -0800 (PST)
Raw View
------=_Part_4262_1527893998.1488127111767
Content-Type: multipart/alternative;
 boundary="----=_Part_4263_807304114.1488127111767"

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

On Sunday, February 26, 2017 at 11:27:08 AM UTC-5, Vicente J. Botet Escriba=
=20
wrote:
>
> Le 26/02/2017 =C3=A0 16:24, Nicol Bolas a =C3=A9crit :
>
> On Sunday, February 26, 2017 at 10:00:26 AM UTC-5, Vicente J. Botet=20
> Escriba wrote:=20
>>
>> I like the idea. Instead of parens/braces we would need something better=
..
>>
>> What about considering other kind of constructions as e.g. default=20
>> initialization, no parens, no braces?
>>
>
> Default initialization has to be a language feature. There's really no wa=
y=20
> for a function to return a default initialized object while simultaneousl=
y=20
> taking advantage of guaranteed elision. Oh, you can do `T t; return t`, b=
ut=20
> that requires that `T` be copy/moveable.
>
> To do this properly, especially if you want to expose this for other user=
s=20
> to use, it has to be a language feature of some kind, something that woul=
d=20
> allow you to return a default initialized temporary.
>
>
> I can want to create e.g. a unique_ptr<POD> with the POD uninitialized,=
=20
> isn't it?
>
> auto a =3D make_unique(uninitialized<POD>); // as if new POD
>
> or  zero initialized=20
>
> auto a =3D make_unique(zero_initialized<POD>); // as if new POD{}
>
>
First, that's not zero initialization; that's value initialization. Yes,=20
value initialization can *cause* zero initialization, but the syntax itself=
=20
invokes value initialization.

More importantly, how does that get *implemented*? How does it get=20
implemented for each form of indirect initialization? Because it's going to=
=20
have to be different if its a library feature, since container `emplace`=20
logic forwards all construction to `allocator`/`traits` classes.

--=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/8b4dba14-af1f-4780-bb7f-79e73efaa140%40isocpp.or=
g.

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

<div dir=3D"ltr">On Sunday, February 26, 2017 at 11:27:08 AM UTC-5, Vicente=
 J. Botet Escriba wrote:<blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
 =20
   =20
 =20
  <div bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div>Le 26/02/2017 =C3=A0 16:24, Nicol Bolas a
      =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote type=3D"cite">
      <div dir=3D"ltr">On Sunday, February 26, 2017 at 10:00:26 AM UTC-5,
        Vicente J. Botet Escriba wrote:
        <blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8=
ex;border-left:1px #ccc solid;padding-left:1ex">
          <div bgcolor=3D"#FFFFFF" text=3D"#000000">
            <div> </div>
            I like the idea. Instead of parens/braces we would need
            something better.<br>
            <br>
            What about considering other kind of constructions as e.g.
            default initialization, no parens, no braces?<br>
          </div>
        </blockquote>
        <div><br>
          Default initialization has to be a language feature. There&#39;s
          really no way for a function to return a default initialized
          object while simultaneously taking advantage of guaranteed
          elision. Oh, you can do `T t; return t`, but that requires
          that `T` be copy/moveable.<br>
          <br>
          To do this properly, especially if you want to expose this for
          other users to use, it has to be a language feature of some
          kind, something that would allow you to return a default
          initialized temporary.<br>
        </div>
      </div>
    </blockquote>
    <br>
    I can want to create e.g. a unique_ptr&lt;POD&gt; with the POD
    uninitialized, isn&#39;t it?<br>
    <br>
    <code><span style=3D"color:#008">auto</span><span style=3D"color:#000">=
 a </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> =
make_unique</span><span style=3D"color:#660">(uninitialized</span><span sty=
le=3D"color:#660">&lt;</span><span style=3D"color:#000">POD</span><span sty=
le=3D"color:#660">&gt;</span><span style=3D"color:#660"><wbr>);</span><span=
 style=3D"color:#000"> </span><span style=3D"color:#800">// as if new POD</=
span><span style=3D"color:#000"><br>
      </span></code><br>
    or=C2=A0 zero initialized <br>
    <br>
    <code><span style=3D"color:#008">auto</span><span style=3D"color:#000">=
 a </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> =
make_unique</span><span style=3D"color:#660">(zero_initialized</span><span =
style=3D"color:#660">&lt;</span><span style=3D"color:#000">P<wbr>OD</span><=
span style=3D"color:#660">&gt;</span><span style=3D"color:#660">);</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#800">// as if new PO=
D</span><span style=3D"color:#000">{}<br>
      </span></code><br></div></blockquote><div><br>First, that&#39;s not z=
ero initialization; that&#39;s value initialization. Yes, value initializat=
ion can <i>cause</i> zero initialization, but the syntax itself invokes val=
ue initialization.<br></div><div><br>More importantly, how does that get <i=
>implemented</i>? How does it get implemented for each form of indirect ini=
tialization? Because it&#39;s going to have to be different if its a librar=
y feature, since container `emplace` logic forwards all construction to `al=
locator`/`traits` classes.</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/8b4dba14-af1f-4780-bb7f-79e73efaa140%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/8b4dba14-af1f-4780-bb7f-79e73efaa140=
%40isocpp.org</a>.<br />

------=_Part_4263_807304114.1488127111767--

------=_Part_4262_1527893998.1488127111767--

.


Author: d.n.izvolov@gmail.com
Date: Mon, 27 Feb 2017 10:04:06 -0800 (PST)
Raw View
------=_Part_386_2103137071.1488218646343
Content-Type: multipart/alternative;
 boundary="----=_Part_387_931340026.1488218646345"

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

The "initialize" thing is good.

But there is a case it does not cover:

struct A
{
    A (A &&) =3D delete;

    A (std::initializer_list<int>) {}

    A (int, int) {}
};

int main()
{
    auto a =3D make_unique<A>(A{17, 3}); // error: call to deleted=20
constructor of 'A'
}

Is there a way to direct-list-initialize such a non-movable object?

=D0=B2=D0=BE=D1=81=D0=BA=D1=80=D0=B5=D1=81=D0=B5=D0=BD=D1=8C=D0=B5, 26 =D1=
=84=D0=B5=D0=B2=D1=80=D0=B0=D0=BB=D1=8F 2017 =D0=B3., 18:03:15 UTC+3 =D0=BF=
=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C Nicol Bo=
las=20
=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
>
> On Sunday, February 26, 2017 at 6:03:03 AM UTC-5, d.n.i...@gmail.com=20
> wrote:
>>
>> The essense of the problem may be shown by the std::make_from_tuple=20
>> function.
>>
>> *Case 1: trivial type*
>>
>> struct trivial
>> {
>>     int x;
>>     double y;
>> };
>>
>> make_from_tuple<trivial>(make_tuple(1, 3.14)); // Compilation error.
>>
>> The example shows that this case is simply not covered by the current=20
>> version of the standard library. Trivial type can't be created from a tu=
ple=20
>> by std::make_from_tuple function.
>>
>
> See LWG 2089 <http://cplusplus.github.io/LWG/lwg-active.html#2089>.
> =20
>
>>
>> *Case 2: the existence of several variants of the constructor*
>>
>> make_from_tuple<vector<size_t>>(make_tuple(5, 1));
>> // Which vector should be created?
>> // [1, 1, 1, 1, 1] or [5, 1]?
>>
>> In the current edition we'll get "five ones". Ant there is no possibilit=
y=20
>> to get "five and one".
>>
>
> Why would you want to? If you wanted "five and one", you would pass an=20
> `initializer_list`. Yes, it's longer, but so be it.
>
> *Proposed solution*
>>
>> The main idea is *tag dispatching*.
>> We create two structs, each of which will signal about the need to call=
=20
>> either round or curly brackets (names are rough):
>>
>> template <typename T>
>> struct parens_t {};
>>
>> template <typename T>
>> constexpr auto parens =3D parens_t<T>{};
>>
>> template <typename T>
>> struct braces_t {};
>>
>> template <typename T>
>> constexpr auto braces =3D braces_t<T>{};
>>
>> Usage:
>>
>> auto a =3D make_unique(parens<A>, 1, 3); // A(1, 3)
>> auto b =3D make_unique(braces<A>, 1, 3); // A{1, 3}
>>
>> auto c =3D make_from_tuple(parens<A>, make_tuple(100, 3.14)); // A(100,=
=20
>> 3.14)
>> auto d =3D make_from_tuple(braces<A>, make_tuple(100, 3.14)); // A{100,=
=20
>> 3.14}
>> // Finally we can call the curly brackets. Yay!
>>
>> Also note that when using this tag, the object type is inferred from the=
=20
>> tag, that is, it is not necessary to specify it explicitly:
>>
>> // Then:
>> auto a =3D make_shared<very_very_very_long_type_name>(
>> very_very_very_long_type_name{1, 3});
>>
>> // Now:
>> auto b =3D make_shared(braces<very_very_very_long_type_name>, 1, 3);
>>
>> The old overloads, of course, remain. The difference is that now we can=
=20
>> explicitly choose the way of initialization.
>> Similarly it would work with functions that accept a set of parameters t=
o=20
>> pass to the constructor, for example, emplace_back.
>>
>> *Example to follow*
>>
>> This approach is not new for the standard library. A similar scheme is=
=20
>> used with the tag std::in_place_type, for example, in the constructor of=
=20
>> the std::variant class. This tag indicates that we need to call the=20
>> constructor of the emplaced class. But in our case we go a little furthe=
r.=20
>> We provide the opportunity not just to signal that we need to call the=
=20
>> constructor, but to tell which exactly constructor it's supposed to be.
>>
>> *Summary*
>>
>> The main point is to give user an opportunity to choose between the=20
>> direct-initialization and the direct-list-initialization explicitly. The=
re=20
>> are many cases when it matters.
>>
>> Given solution:
>>
>>    1. Simplifies programmer's life and enhances the functionality of the=
=20
>>    standard library.
>>    2. Maintains full backward compatibility. Nothing is broken.
>>    3. Is quite general. It works with make_shared, make_unique, make_any
>>    , make_from_tuple, emplace and more.
>>    4. Seamlessly fits into the standard library and is pretty convenient=
=20
>>    to use.
>>   =20
>> The principle downside of this is that it enhances *only* "the=20
> functionality of the standard library". Which means that if someone write=
s=20
> their own types with such indirect initialization capabilities, they woul=
d=20
> have to manually provide such functionality. Every time. And existing=20
> functions would have to be updated as well.
>
> If you're going to try to establish such a convention through the library=
,=20
> then you need lower-level support. I would strongly encourage you to add =
a=20
> `std::initialize<T>` function to the library which would do the low-level=
=20
> dispatching work. This probably won't get used by novices, but at least=
=20
> experts will be able to easily write functions that adhere to the standar=
d=20
> library's conventions on this sort of thing.
>
> Also, I advise you to remove the `T` to be constructed from the tag's=20
> typename. The reason being that there are several indirect initialization=
=20
> cases where `T` is well-defined. `vector<int>::emplace` cannot emplace a=
=20
> `float` or a `SomeType`; it will only initialize an `int`. So why do we=
=20
> have to say it again? For the `make/allocate_` style functions, you're=20
> going to have to specify the type anyway. So why is it better on the tag=
=20
> than the function call? The only place where putting it on the tag would =
be=20
> a win would be with `variant`/`any`'s `in_place_type` tagged initializati=
on.
>
> template<typename T, typename ...Args>
> T initialize(Args &&...args)
> {
>   return T(std::forward<Args>(args)...);
> }
>
> template<typename T, typename ...Args>
> T initialize(std::construct_t, Args &&...args)
> {
>   return T(std::forward<Args>(args)...);
> }
>
> template<typename T, typename ...Args>
> T initialize(std::list_init_t, Args &&...args)
> {
>   return T{std::forward<Args>(args)...};
> }
>
> I changed the names to match standard terminology. But you get the genera=
l=20
> idea.
>
> In any case, I maintain a list of various fixes for this initialization=
=20
> problem=20
> <https://github.com/NicolBolas/Proposal-Ideas/blob/master/Towards%20a%20F=
ix%20For%20LWG%202089.md>.=20
> This one is already on that list.
>

--=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/1d0872f1-56dd-4796-a95a-abff2a608432%40isocpp.or=
g.

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

<div dir=3D"ltr">The &quot;initialize&quot; thing is good.<div><br></div><d=
iv>But there is a case it does not cover:</div><div><br></div><div><div cla=
ss=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border: 1=
px solid rgb(187, 187, 187); word-wrap: break-word;"><code class=3D"prettyp=
rint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">struct</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> A<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 A </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">A </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;=
&amp;)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </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"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">delete</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br><br>=C2=A0 =C2=A0 A </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"colo=
r: #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">initializer_list</span><span style=3D"color: #080;"=
 class=3D"styled-by-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-prettify"> </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>=C2=A0 =C2=A0 A </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">int</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><sp=
an 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: #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><br></span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> main</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><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> a </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"c=
olor: #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-prettify">A</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&gt;(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">A</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #066;" class=3D"styled-by-pret=
tify">17</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #066;" class=3D"styled-by-prettify">3</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">});</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #800;=
" class=3D"styled-by-prettify">// error: call to deleted constructor of &#3=
9;A&#39;</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>=
</div></code></div><div><br></div><div>Is there a way to direct-list-initia=
lize such a non-movable object?</div><br>=D0=B2=D0=BE=D1=81=D0=BA=D1=80=D0=
=B5=D1=81=D0=B5=D0=BD=D1=8C=D0=B5, 26 =D1=84=D0=B5=D0=B2=D1=80=D0=B0=D0=BB=
=D1=8F 2017 =D0=B3., 18:03:15 UTC+3 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=
=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C Nicol Bolas =D0=BD=D0=B0=D0=BF=D0=B8=D1=
=81=D0=B0=D0=BB:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"lt=
r">On Sunday, February 26, 2017 at 6:03:03 AM UTC-5, <a>d.n.i...@gmail.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">The esse=
nse of the problem may be shown by the <font face=3D"courier new, monospace=
">std::make_from_tuple</font> function.<div><br></div><div><b>Case 1: trivi=
al type</b></div><div><br></div><div><div style=3D"background-color:rgb(250=
,250,250);border:1px solid rgb(187,187,187);word-wrap:break-word"><code><di=
v><span style=3D"color:#008">struct</span><span style=3D"color:#000"> trivi=
al<br></span><span style=3D"color:#660">{</span><span style=3D"color:#000">=
<br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">int</span><span style=
=3D"color:#000"> x</span><span style=3D"color:#660">;</span><span style=3D"=
color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">double</spa=
n><span style=3D"color:#000"> y</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><br>make_from_tuple</span><span style=3D"color:=
#080">&lt;trivial&gt;</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">make_<wbr>tuple</span><span style=3D"color:#660">(</span><s=
pan style=3D"color:#066">1</span><span style=3D"color:#660">,</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#066">3.14</span><span sty=
le=3D"color:#660">));</span><span style=3D"color:#000"> </span><span style=
=3D"color:#800">// Compilation error.</span></div></code></div><div><br></d=
iv></div><div>The example shows that=C2=A0this case is simply not covered b=
y the current version of the standard library. Trivial type can&#39;t be cr=
eated from a tuple by <font face=3D"courier new, monospace">std::make_from_=
tuple</font> function.</div></div></blockquote><div><br>See <a href=3D"http=
://cplusplus.github.io/LWG/lwg-active.html#2089" target=3D"_blank" rel=3D"n=
ofollow" onmousedown=3D"this.href=3D&#39;http://www.google.com/url?q\x3dhtt=
p%3A%2F%2Fcplusplus.github.io%2FLWG%2Flwg-active.html%232089\x26sa\x3dD\x26=
sntz\x3d1\x26usg\x3dAFQjCNHfYo86LETvfuC9SJHAfCohX1GL6g&#39;;return true;" o=
nclick=3D"this.href=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fcplu=
splus.github.io%2FLWG%2Flwg-active.html%232089\x26sa\x3dD\x26sntz\x3d1\x26u=
sg\x3dAFQjCNHfYo86LETvfuC9SJHAfCohX1GL6g&#39;;return true;">LWG 2089</a>.<b=
r>=C2=A0</div><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"><div=
><br></div><div><b>Case 2: the existence of several variants of the constru=
ctor</b></div><div><br></div><div><div style=3D"background-color:rgb(250,25=
0,250);border:1px solid rgb(187,187,187);word-wrap:break-word"><code><div><=
span style=3D"color:#000">make_from_tuple</span><span style=3D"color:#660">=
&lt;</span><span style=3D"color:#000">vector</span><span style=3D"color:#08=
0">&lt;size_t&gt;</span><span style=3D"color:#660"><wbr>&gt;(</span><span s=
tyle=3D"color:#000">make_tuple</span><span style=3D"color:#660">(</span><sp=
an style=3D"color:#066">5</span><span style=3D"color:#660">,</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#066">1</span><span style=
=3D"color:#660">));</span><span style=3D"color:#000"><br></span><span style=
=3D"color:#800">// Which vector should be created?</span><span style=3D"col=
or:#000"><br></span><span style=3D"color:#800">// [1, 1, 1, 1, 1] or [5, 1]=
?</span></div></code></div><div><br></div></div><div>In the current edition=
 we&#39;ll get &quot;five ones&quot;. Ant there is no possibility to get &q=
uot;five and one&quot;.</div></div></blockquote><div><br>Why would you want=
 to? If you wanted &quot;five and one&quot;, you would pass an `initializer=
_list`. Yes, it&#39;s longer, but so be it.<br><br></div><blockquote class=
=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr"><div><b>Proposed solution</b></div>=
<div><br></div><div>The main idea is <i>tag dispatching</i>.</div><div>We c=
reate two structs, each of which will signal about the need to call either =
round or curly brackets (names are rough):</div><div><br></div><div><div st=
yle=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,187,187);=
word-wrap:break-word"><code><div><span style=3D"color:#008">template</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#660">&lt;</span><s=
pan style=3D"color:#008">typename</span><span style=3D"color:#000"> T</span=
><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"><br></spa=
n><span style=3D"color:#008">struct</span><span style=3D"color:#000"> paren=
s_t </span><span style=3D"color:#660">{};</span><span style=3D"color:#000">=
<br><br></span><span style=3D"color:#008">template</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#660">&lt;</span><span style=3D"color=
:#008">typename</span><span style=3D"color:#000"> T</span><span style=3D"co=
lor:#660">&gt;</span><span style=3D"color:#000"><br></span><span style=3D"c=
olor:#008">constexpr</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">auto</span><span style=3D"color:#000"> parens </span><span =
style=3D"color:#660">=3D</span><span style=3D"color:#000"> parens_t</span><=
span style=3D"color:#660">&lt;</span><span style=3D"color:#000">T</span><sp=
an style=3D"color:#660">&gt;{};</span><span style=3D"color:#000"><br><br></=
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">typ=
ename</span><span style=3D"color:#000"> T</span><span style=3D"color:#660">=
&gt;</span><span style=3D"color:#000"><br></span><span style=3D"color:#008"=
>struct</span><span style=3D"color:#000"> braces_t </span><span style=3D"co=
lor:#660">{};</span><span style=3D"color:#000"><br><br></span><span style=
=3D"color:#008">template</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">&lt;</span><span style=3D"color:#008">typename</span><spa=
n style=3D"color:#000"> T</span><span style=3D"color:#660">&gt;</span><span=
 style=3D"color:#000"><br></span><span style=3D"color:#008">constexpr</span=
><span style=3D"color:#000"> </span><span style=3D"color:#008">auto</span><=
span style=3D"color:#000"> braces </span><span style=3D"color:#660">=3D</sp=
an><span style=3D"color:#000"> braces_t</span><span style=3D"color:#660">&l=
t;</span><span style=3D"color:#000">T</span><span style=3D"color:#660">&gt;=
{};</span></div></code></div><div><br></div></div><div>Usage:</div><div><br=
></div><div><div style=3D"background-color:rgb(250,250,250);border:1px soli=
d rgb(187,187,187);word-wrap:break-word"><code><div><span style=3D"color:#0=
08">auto</span><span style=3D"color:#000"> a </span><span style=3D"color:#6=
60">=3D</span><span style=3D"color:#000"> make_unique</span><span style=3D"=
color:#660">(</span><span style=3D"color:#000">parens</span><span style=3D"=
color:#660">&lt;</span><span style=3D"color:#000">A</span><span style=3D"co=
lor:#660">&gt;,</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#066">1</span><span style=3D"color:#660">,</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#066">3</span><span style=3D"color:#660">)=
;</span><span style=3D"color:#000"> </span><span style=3D"color:#800">// A(=
1, 3)</span><span style=3D"color:#000"><br></span><span style=3D"color:#008=
">auto</span><span style=3D"color:#000"> b </span><span style=3D"color:#660=
">=3D</span><span style=3D"color:#000"> make_unique</span><span style=3D"co=
lor:#660">(</span><span style=3D"color:#000">braces</span><span style=3D"co=
lor:#660">&lt;</span><span style=3D"color:#000">A</span><span style=3D"colo=
r:#660">&gt;,</span><span style=3D"color:#000"> </span><span style=3D"color=
:#066">1</span><span style=3D"color:#660">,</span><span style=3D"color:#000=
"> </span><span style=3D"color:#066">3</span><span style=3D"color:#660">);<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#800">// A{1,=
 3}</span><span style=3D"color:#000"><br><br></span><span style=3D"color:#0=
08">auto</span><span style=3D"color:#000"> c </span><span style=3D"color:#6=
60">=3D</span><span style=3D"color:#000"> make_from_tuple</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">parens</span><span style=
=3D"color:#660">&lt;</span><span style=3D"color:#000">A</span><span style=
=3D"color:#660">&gt;,</span><span style=3D"color:#000"> make_tuple</span><s=
pan style=3D"color:#660">(</span><span style=3D"color:#066">100</span><span=
 style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#066">3.14</span><span style=3D"color:#660">));</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#800">// A(100, 3.14)</span><=
span style=3D"color:#000"><br></span><span style=3D"color:#008">auto</span>=
<span style=3D"color:#000"> d </span><span style=3D"color:#660">=3D</span><=
span style=3D"color:#000"> make_from_tuple</span><span style=3D"color:#660"=
>(</span><span style=3D"color:#000">braces</span><span style=3D"color:#660"=
>&lt;</span><span style=3D"color:#000">A</span><span style=3D"color:#660">&=
gt;,</span><span style=3D"color:#000"> make_tuple</span><span style=3D"colo=
r:#660">(</span><span style=3D"color:#066">100</span><span style=3D"color:#=
660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#066">=
3.14</span><span style=3D"color:#660">));</span><span style=3D"color:#000">=
 </span><span style=3D"color:#800">// A{100, 3.14}</span><span style=3D"col=
or:#000"><br></span><span style=3D"color:#800">// Finally we can call the c=
urly brackets. Yay!</span><span style=3D"color:#000"><br></span></div></cod=
e></div></div><div><br></div><div>Also note that when using this tag, the o=
bject type is inferred from the tag, that is, it is not necessary to specif=
y it explicitly:<br></div><div><br></div><div><div style=3D"background-colo=
r:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:break-word">=
<code><div><span style=3D"color:#800">// Then:</span><span style=3D"color:#=
000"><br></span><span style=3D"color:#008">auto</span><span style=3D"color:=
#000"> a </span><span style=3D"color:#660">=3D</span><span style=3D"color:#=
000"> make_shared</span><span style=3D"color:#080">&lt;very_very_very_<wbr>=
long_type_name&gt;</span><span style=3D"color:#660">(</span><span style=3D"=
color:#000">very_very_<wbr>very_long_type_name</span><span style=3D"color:#=
660">{</span><span style=3D"color:#066">1</span><span style=3D"color:#660">=
,</span><span style=3D"color:#000"> </span><span style=3D"color:#066">3</sp=
an><span style=3D"color:#660">});</span><span style=3D"color:#000"><br><br>=
</span><span style=3D"color:#800">// Now:</span><span style=3D"color:#000">=
<br></span><span style=3D"color:#008">auto</span><span style=3D"color:#000"=
> b </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000">=
 make_shared</span><span style=3D"color:#660">(</span><span style=3D"color:=
#000">braces</span><span style=3D"color:#080">&lt;very_very_<wbr>very_long_=
type_name&gt;</span><span style=3D"color:#660">,</span><span style=3D"color=
:#000"> </span><span style=3D"color:#066">1</span><span style=3D"color:#660=
">,</span><span style=3D"color:#000"> </span><span style=3D"color:#066">3</=
span><span style=3D"color:#660">);</span></div></code></div><div><br></div>=
</div><div>The old overloads, of course, remain. The difference is that now=
 we can explicitly choose the way of initialization.</div><div>Similarly it=
 would work with functions that accept a set of parameters to pass to the c=
onstructor, for example, <font face=3D"courier new, monospace">emplace_back=
</font>.</div><div><br></div><div><b>Example to follow</b></div><div><br></=
div><div>This approach is not new for the standard library. A similar schem=
e is used with the tag <font face=3D"courier new, monospace">std::in_place_=
type</font>, for example, in the constructor of the <font face=3D"courier n=
ew, monospace">std::variant</font> class. This tag indicates that we need t=
o call the constructor of the emplaced class. But in our case we go a littl=
e further. We provide the opportunity not just to signal that we need to ca=
ll the constructor, but to tell which exactly constructor it&#39;s supposed=
 to be.</div><div><br></div><div><div><b>Summary</b></div><div><br></div><d=
iv>The main point is to give user an opportunity to choose between the dire=
ct-initialization and the direct-list-initialization explicitly. There are =
many cases when it matters.<br></div><div><br></div><div>Given solution:</d=
iv><div><ol><li>Simplifies programmer&#39;s life and enhances the functiona=
lity of the standard library.</li><li>Maintains full backward compatibility=
.. Nothing is broken.</li><li>Is quite general. It works with=C2=A0<font fac=
e=3D"courier new, monospace">make_shared</font>,=C2=A0<font face=3D"courier=
 new, monospace">make_unique</font>,<wbr>=C2=A0<font face=3D"courier new, m=
onospace">make_any</font>,=C2=A0<font face=3D"courier new, monospace">make_=
from_tuple</font>, <font face=3D"courier new, monospace">emplace</font> and=
 more.</li><li>Seamlessly fits into the standard library and is pretty conv=
enient to use.<br></li></ol></div></div></div></blockquote><div>The princip=
le downside of this is that it enhances <i>only</i> &quot;the functionality=
 of the standard library&quot;. Which means that if someone writes their ow=
n types with such indirect initialization capabilities, they would have to =
manually provide such functionality. Every time. And existing functions wou=
ld have to be updated as well.<br><br>If you&#39;re going to try to establi=
sh such a convention through the library, then you need lower-level support=
.. I would strongly encourage you to add a `std::initialize&lt;T&gt;` functi=
on to the library which would do the low-level dispatching work. This proba=
bly won&#39;t get used by novices, but at least experts will be able to eas=
ily write functions that adhere to the standard library&#39;s conventions o=
n this sort of thing.<br><br>Also, I advise you to remove the `T` to be con=
structed from the tag&#39;s typename. The reason being that there are sever=
al indirect initialization cases where `T` is well-defined. `vector&lt;int&=
gt;::emplace` cannot emplace a `float` or a `SomeType`; it will only initia=
lize an `int`. So why do we have to say it again? For the `make/allocate_` =
style functions, you&#39;re going to have to specify the type anyway. So wh=
y is it better on the tag than the function call? The only place where putt=
ing it on the tag would be a win would be with `variant`/`any`&#39;s `in_pl=
ace_type` tagged initialization.<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">template</span><span style=3D"co=
lor:#660">&lt;</span><span style=3D"color:#008">typename</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">typename</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">...</span><span style=3D=
"color:#606">Args</span><span style=3D"color:#660">&gt;</span><span style=
=3D"color:#000"><br>T initialize</span><span style=3D"color:#660">(</span><=
span style=3D"color:#606">Args</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#660">&amp;&amp;...</span><span style=3D"color:#000">args=
</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>=C2=
=A0 </span><span style=3D"color:#008">return</span><span style=3D"color:#00=
0"> T</span><span style=3D"color:#660">(</span><span style=3D"color:#000">s=
td</span><span style=3D"color:#660">::</span><span style=3D"color:#000">for=
ward</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"color:#00=
0">args</span><span style=3D"color:#660">)...)<wbr>;</span><span style=3D"c=
olor:#000"><br></span><span style=3D"color:#660">}</span><span style=3D"col=
or:#000"><br><br></span><span style=3D"color:#008">template</span><span sty=
le=3D"color:#660">&lt;</span><span style=3D"color:#008">typename</span><spa=
n style=3D"color:#000"> T</span><span style=3D"color:#660">,</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#008">typename</span><span =
style=3D"color:#000"> </span><span style=3D"color:#660">...</span><span sty=
le=3D"color:#606">Args</span><span style=3D"color:#660">&gt;</span><span st=
yle=3D"color:#000"><br>T initialize</span><span style=3D"color:#660">(</spa=
n><span style=3D"color:#000">std</span><span style=3D"color:#660">::</span>=
<span style=3D"color:#000">construct_t</span><span style=3D"color:#660">,</=
span><span style=3D"color:#000"> </span><span style=3D"color:#606">Args</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#660">&amp;&amp;=
....</span><span style=3D"color:#000">args</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>=C2=A0 </span><span style=3D"color:#00=
8">return</span><span style=3D"color:#000"> T</span><span style=3D"color:#6=
60">(</span><span style=3D"color:#000">std</span><span style=3D"color:#660"=
>::</span><span style=3D"color:#000">forward</span><span style=3D"color:#66=
0">&lt;</span><span style=3D"color:#606">Args</span><span style=3D"color:#6=
60">&gt;(</span><span style=3D"color:#000">args</span><span style=3D"color:=
#660">)...)<wbr>;</span><span style=3D"color:#000"><br></span><span style=
=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span><span sty=
le=3D"color:#008">template</span><span style=3D"color:#660">&lt;</span><spa=
n style=3D"color:#008">typename</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">typename</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">...</span><span style=3D"color:#606">Args</span><spa=
n style=3D"color:#660">&gt;</span><span style=3D"color:#000"><br>T initiali=
ze</span><span style=3D"color:#660">(</span><span style=3D"color:#000">std<=
/span><span style=3D"color:#660">::</span><span style=3D"color:#000">list_i=
nit_t</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
</span><span style=3D"color:#606">Args</span><span style=3D"color:#000"> </=
span><span style=3D"color:#660">&amp;&amp;...</span><span style=3D"color:#0=
00">args</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>=C2=A0 </span><span style=3D"color:#008">return</span><span style=3D"co=
lor:#000"> T</span><span style=3D"color:#660">{</span><span style=3D"color:=
#000">std</span><span style=3D"color:#660">::</span><span style=3D"color:#0=
00">forward</span><span style=3D"color:#660">&lt;</span><span style=3D"colo=
r:#606">Args</span><span style=3D"color:#660">&gt;(</span><span style=3D"co=
lor:#000">args</span><span style=3D"color:#660">)...}<wbr>;</span><span sty=
le=3D"color:#000"><br></span><span style=3D"color:#660">}</span></div></cod=
e></div><br>I changed the names to match standard terminology. But you get =
the general idea.<br><br>In any case, I maintain a <a href=3D"https://githu=
b.com/NicolBolas/Proposal-Ideas/blob/master/Towards%20a%20Fix%20For%20LWG%2=
02089.md" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#3=
9;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2FNicolBolas%2FP=
roposal-Ideas%2Fblob%2Fmaster%2FTowards%2520a%2520Fix%2520For%2520LWG%25202=
089.md\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGSOJF53UOo1xtfQ31GsY2oTBy39g=
&#39;;return true;" onclick=3D"this.href=3D&#39;https://www.google.com/url?=
q\x3dhttps%3A%2F%2Fgithub.com%2FNicolBolas%2FProposal-Ideas%2Fblob%2Fmaster=
%2FTowards%2520a%2520Fix%2520For%2520LWG%25202089.md\x26sa\x3dD\x26sntz\x3d=
1\x26usg\x3dAFQjCNGSOJF53UOo1xtfQ31GsY2oTBy39g&#39;;return true;">list of v=
arious fixes for this initialization problem</a>. This one is already on th=
at list.<br></div></div></blockquote></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/1d0872f1-56dd-4796-a95a-abff2a608432%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1d0872f1-56dd-4796-a95a-abff2a608432=
%40isocpp.org</a>.<br />

------=_Part_387_931340026.1488218646345--

------=_Part_386_2103137071.1488218646343--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Mon, 27 Feb 2017 10:41:03 -0800 (PST)
Raw View
------=_Part_4910_1440357972.1488220863077
Content-Type: multipart/alternative;
 boundary="----=_Part_4911_1571689279.1488220863077"

------=_Part_4911_1571689279.1488220863077
Content-Type: text/plain; charset=UTF-8

On Monday, February 27, 2017 at 1:04:06 PM UTC-5, d.n.i...@gmail.com wrote:
>
> The "initialize" thing is good.
>
> But there is a case it does not cover:
>
> struct A
> {
>     A (A &&) = delete;
>
>     A (std::initializer_list<int>) {}
>
>     A (int, int) {}
> };
>
> int main()
> {
>     auto a = make_unique<A>(A{17, 3}); // error: call to deleted
> constructor of 'A'
> }
>
> Is there a way to direct-list-initialize such a non-movable object?
>

Yes. That's what we're talking about. If `make_unique` uses
`std::initialize` as I have defined it, you would do this:

make_unique<A>(std::list_init, 17, 3);

You would implement `make_unique` like this:

template<typename T, typename ...Args)
unique_ptr<T> make_unique(Args &&...args)
{
  return unique_ptr<T>(new auto(std::initialize<T>(std::forward<Args>(args
)...)));
}

Guaranteed elision allows this to work no matter what constructors `T` does
or does not have. Well, so long as it can be constructed with the given
arguments.

--
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/8a546773-4d5c-41d2-8513-4a87a6a7a12f%40isocpp.org.

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

<div dir=3D"ltr">On Monday, February 27, 2017 at 1:04:06 PM UTC-5, d.n.i...=
@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr">The &quot;initialize&quot; thing is good.<div><br></div><div>But there =
is a case it does not cover:</div><div><br></div><div><div style=3D"backgro=
und-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:brea=
k-word"><code><div><span style=3D"color:#008">struct</span><span style=3D"c=
olor:#000"> A<br></span><span style=3D"color:#660">{</span><span style=3D"c=
olor:#000"><br>=C2=A0 =C2=A0 A </span><span style=3D"color:#660">(</span><s=
pan style=3D"color:#000">A </span><span style=3D"color:#660">&amp;&amp;)</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">=3D</span=
><span style=3D"color:#000"> </span><span style=3D"color:#008">delete</span=
><span style=3D"color:#660">;</span><span style=3D"color:#000"><br><br>=C2=
=A0 =C2=A0 A </span><span style=3D"color:#660">(</span><span style=3D"color=
:#000">std</span><span style=3D"color:#660">::</span><span style=3D"color:#=
000">initializer_list</span><span style=3D"color:#080">&lt;int&gt;</span><s=
pan style=3D"color:#660">)</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#660">{}</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=
=A0 A </span><span style=3D"color:#660">(</span><span style=3D"color:#008">=
int</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> </=
span><span style=3D"color:#008">int</span><span style=3D"color:#660">)</spa=
n><span style=3D"color:#000"> </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><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"><br></span><span style=3D"color:#660">{</span><=
span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#00=
8">auto</span><span style=3D"color:#000"> a </span><span style=3D"color:#66=
0">=3D</span><span style=3D"color:#000"> make_unique</span><span style=3D"c=
olor:#660">&lt;</span><span style=3D"color:#000">A</span><span style=3D"col=
or:#660">&gt;(</span><span style=3D"color:#000">A</span><span style=3D"colo=
r:#660">{</span><span style=3D"color:#066">17</span><span style=3D"color:#6=
60">,</span><span style=3D"color:#000"> </span><span style=3D"color:#066">3=
</span><span style=3D"color:#660">});</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#800">// error: call to deleted constructor of &#3=
9;A&#39;</span><span style=3D"color:#000"><br></span><span style=3D"color:#=
660">}</span></div></code></div><div><br></div><div>Is there a way to direc=
t-list-initialize such a non-movable object?</div></div></div></blockquote>=
<div><br>Yes. That&#39;s what we&#39;re talking about. If `make_unique` use=
s `std::initialize` as I have defined it, you would do this:<br><br><div st=
yle=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 18=
7); border-style: solid; border-width: 1px; overflow-wrap: break-word;" cla=
ss=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subprettyprint=
"><span style=3D"color: #000;" class=3D"styled-by-prettify">make_unique</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">A</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">list_init</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pr=
ettify">17</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: #066;" class=3D"styled-by-prettify">3</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">);</span></div></code></div=
><br>You would implement `make_unique` like this:<br><br><div style=3D"back=
ground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-=
style: solid; border-width: 1px; overflow-wrap: break-word;" class=3D"prett=
yprint"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span sty=
le=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"co=
lor: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"colo=
r: #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"style=
d-by-prettify">typename</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">...</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Arg=
s</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br>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">T</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_unique</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #6=
06;" class=3D"styled-by-prettify">Args</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </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"st=
yled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></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 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">ret=
urn</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">T</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(</span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">new</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"st=
yled-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">initialize</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&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 s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">forward</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #6=
06;" class=3D"styled-by-prettify">Args</span><span style=3D"color: #660;" c=
lass=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"styl=
ed-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">}</span></div></code></div><br>Guaranteed elision allows this to =
work no matter what constructors `T` does or does not have. Well, so long a=
s it can be constructed with the given arguments.</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/8a546773-4d5c-41d2-8513-4a87a6a7a12f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/8a546773-4d5c-41d2-8513-4a87a6a7a12f=
%40isocpp.org</a>.<br />

------=_Part_4911_1571689279.1488220863077--

------=_Part_4910_1440357972.1488220863077--

.