Topic: new auto


Author: Dale Weiler <weilercdale@gmail.com>
Date: Tue, 8 Mar 2016 10:34:05 -0800 (PST)
Raw View
------=_Part_248_1811077598.1457462045647
Content-Type: multipart/alternative;
 boundary="----=_Part_249_237990868.1457462045648"

------=_Part_249_237990868.1457462045648
Content-Type: text/plain; charset=UTF-8



Exibit
class A {
  A();
  T *a;
};


Need to know type of *a* here to call new correctly:
 A::A() : a(new T) { }

Imagine the class member type changes but implementing code stays the
same, thus it allocates an incorrect amount of memory for the object and
calls the wrong constructor. How do we solve this?
A::A() : a (new typename remove_reference<decltype(A::a)>::type) { }


Not that pretty but does handle this case. What's interesting is in these
contexts the compiler knows the type from the binding side:
T *a = new T;
T *b(new T);


We can see this is true with container types too:
unique_ptr<T> a = make_unique<T>(...);
unique_ptr<T> b(new T(...));
shared_ptr<T> c = make_shared<T>(...);
shared_ptr<T> d(new T(...));

Lets review our original example now with *new auto:*
A::A() : a(new auto) { }

Changes of the class member type does not affect implementing code,
since *auto* knows the type

Consistent with other forms of initialization as well:
T *a = new auto;
T *a(new auto);

Ambigious
*new auto(expr)* already exists in C++, it's defined such that new allocates
storage for type of *expr* and constructs with value of *expr*.

We argue this behavior is inconsistent with the rest of the language as*auto* is treated as a non-type and as a function-style cast in this example.

With explicit initialization this would be preferred behavior of the syntax,
which shouldn't break anything either:
T *a = new auto(...);
T *b(new auto(...));

Assuming existing C++ code uses *new auto(expr)*, the binding
side of the expression must have same type as the new expression,
otherwise a compile error results. The only time this is not the case
is when a *reinterpret_cast* is used on the result of the new expression which
is undefined unless the pointer types are compatible. When the binding side
is of the same type as the new expression the result is consistent with
this proposal and does not break existing C++ code that uses *new auto(expr)*.

Visibility

What we obtain is improved visibility for containment and consistency
with respect to *auto* and other language syntax.

For example *make_unique* and *make_shared* can be made much simpler and
better:
template <typename T, typename A...>
unique_ptr<T> make_unique(A&&... a) {
  // Note we don't use new T here since that prevents visibility
  return { new auto(forward<A>(a)...) };
}
template <typename T, typename A...>
shared_ptr<T> make_shared(A&&... a) {
  // Ditto no use of new T here either
  return { new auto(forward<A>(a)...) };
}


Now *make_unique* and *make_shared* can access private constructors,
since `auto` avoids the visibility problem in this construct:
class A {
  A() { ... }
public:
  void x() {
    auto x = make_unique<A>(); // Works!
    ...
  }
};

However outside class scope:
auto x = make_unique<A>(); // Does not work since private (as expected)

Yes it works for arrays too:
int *x = new auto[10]; // 10 integers (uninitialized)
int *y = new auto[10](100); // 10 integers (initialized to 100

--
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/d98f26dc-e801-4e74-bcbc-7e085986de63%40isocpp.org.

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

<pre><font size=3D"6">Exibit</font><br>
<div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); b=
order-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; wo=
rd-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettypr=
int"><span style=3D"color: #008;" class=3D"styled-by-prettify">class</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> A </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 A</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 T </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">a</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">};</span></div></code></div>

Need to know type of <b>a</b> here to call new correctly:
<div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); b=
order-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; wo=
rd-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettypr=
int"><span style=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0A</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">A</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> a</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
new</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</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: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span></div></code></div>
Imagine the class member type changes but implementing code stays the
same, thus it allocates an incorrect amount of memory for the object and
calls the wrong constructor. How do we solve this? <br><div class=3D"pretty=
print" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187=
, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-word;=
"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"=
color: #000;" class=3D"styled-by-prettify">A</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">A</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> a </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">new</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> remove_reference</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">decltype</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</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: #000;" class=3D"styled-by-pre=
ttify">a</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)&=
gt;::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">type<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><sp=
an 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"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">}</span></div></code></div><br>
Not that pretty but does handle this case. What&#39;s interesting is in the=
se
contexts the compiler knows the type from the binding side:<br><div class=
=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-colo=
r: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: b=
reak-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><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">a </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">new</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>T </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">b</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">new</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">);</span></div></code></div><br>
We can see this is true with container types too:
<div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); b=
order-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; wo=
rd-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettypr=
int"><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><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"c=
olor: #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;" c=
lass=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">T</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&gt;(...);</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>unique_ptr</span><span style=3D"color: #660;" class=3D"s=
tyled-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-pretti=
fy">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> b=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">new</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">(...));</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>shared_ptr</span><span style=3D"c=
olor: #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;" cl=
ass=3D"styled-by-prettify">&gt;</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-pre=
ttify"> make_shared</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(.=
...);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <br>s=
hared_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=
><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> d</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">new</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"><br></span></div></code></div>
Lets review our original example now with <b>new auto:</b>
<div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); b=
order-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; wo=
rd-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettypr=
int"><span style=3D"color: #000;" class=3D"styled-by-prettify">A</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">A</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> a</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">new</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"colo=
r: #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"> </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br></span></div></code></div><br>Changes of the class member type does =
not affect implementing code,
since <b>auto</b> knows the type

Consistent with other forms of initialization as well:<br><div class=3D"pre=
ttyprint" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(=
187, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-wo=
rd;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=
=3D"color: #000;" class=3D"styled-by-prettify">T </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">*</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"sty=
led-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">new</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>T </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">a</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">new</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">auto</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)=
;</span></div></code></div>

<font size=3D"6">Ambigious</font>

<b>new auto(expr)</b> already exists in C++, it&#39;s defined such that new=
 allocates<br>storage for type of <b>expr</b> and constructs with value of =
<b>expr</b>.

We argue this behavior is inconsistent with the rest of the language as
<b>auto</b> is treated as a non-type and as a function-style cast in this e=
xample.

With explicit initialization this would be preferred behavior of the syntax=
,
which shouldn&#39;t break anything either:
<div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); b=
order-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; wo=
rd-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettypr=
int"><span style=3D"color: #000;" class=3D"styled-by-prettify">T </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">a </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">new</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">auto</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">(...);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r>T </span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">b</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">new</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">auto</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(...));</span></div></code></div><br>Assuming existing =
C++ code uses <b>new auto(expr)</b>, the binding<br>side of the expression =
must have same type as the new expression,<br>otherwise a compile error res=
ults. The only time this is not the case<br>is when a <b>reinterpret_cast</=
b> is used on the result of the new expression which<br>is undefined unless=
 the pointer types are compatible. When the binding side<br>is of the same =
type as the new expression the result is consistent with<br>this proposal a=
nd does not break existing C++ code that uses <b>new auto(expr)</b>.<br><fo=
nt size=3D"6"><br>Visibility<br><br></font>What we obtain is improved visib=
ility for containment and consistency
with respect to <b>auto</b> and other language syntax.

For example <b>make_unique</b> and <b>make_shared</b> can be made much simp=
ler and=20
better:
<div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); b=
order-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; wo=
rd-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettypr=
int"><span style=3D"color: #008;" class=3D"styled-by-prettify">template</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"s=
tyled-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-pr=
ettify"><br>unique_ptr</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> make_uni=
que</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">A</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&amp;&amp;...</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> a</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>=C2=A0 </span><span style=3D"color: #800;" class=3D=
"styled-by-prettify">// Note we don&#39;t use new T here since that prevent=
s visibility</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br>=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">return</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</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: #008;" class=3D"styled-by-prettify">new</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">auto</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">forward</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">A</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&g=
t;(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">a</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">)...)</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">template</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">&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 styl=
e=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> A</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">...&gt;</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br>shared_ptr</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">T</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"> make_shared</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">A</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&amp;&amp;...</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> a</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: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span styl=
e=3D"color: #800;" class=3D"styled-by-prettify">// Ditto no use of new T he=
re either</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">=
return</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">new</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">auto</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">forward</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">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"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=
"styled-by-prettify"> </span></div></code></div>

Now <b>make_unique</b> and <b>make_shared</b> can access private constructo=
rs,
since `auto` avoids the visibility problem in this construct:<br><div class=
=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-colo=
r: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: b=
reak-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">class</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> A </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>=C2=A0 A</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">.=
...</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">public</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">:</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">void</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> x</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </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"=
>auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> x </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> make_unique</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">A</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&gt;();</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #800;=
" class=3D"styled-by-prettify">// Works!</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">...</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br>=C2=A0 </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"st=
yled-by-prettify">};</span></div></code></div>
However outside class scope:<br><div class=3D"prettyprint" style=3D"backgro=
und-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-sty=
le: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pretty=
print"><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"> x </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">=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=
">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">A</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;();</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #800;" class=3D"styled-by-prettify">// Does not work since pr=
ivate (as expected)</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span></div></code></div><br>Yes it works for arrays too:
<div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); b=
order-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; wo=
rd-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettypr=
int"><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><s=
pan 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">x </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">new</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">a=
uto</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[</span=
><span style=3D"color: #066;" class=3D"styled-by-prettify">10</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">];</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #8=
00;" class=3D"styled-by-prettify">// 10 integers (uninitialized)</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"co=
lor: #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">y </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
new</span><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: #660;" class=3D"styled-by-prettify">[</span><span style=3D=
"color: #066;" class=3D"styled-by-prettify">10</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">](</span><span style=3D"color: #066;" c=
lass=3D"styled-by-prettify">100</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-pretti=
fy">// 10 integers (initialized to 100</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br></span></div></code></div></pre>

<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/d98f26dc-e801-4e74-bcbc-7e085986de63%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d98f26dc-e801-4e74-bcbc-7e085986de63=
%40isocpp.org</a>.<br />

------=_Part_249_237990868.1457462045648--
------=_Part_248_1811077598.1457462045647--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 8 Mar 2016 11:43:37 -0800 (PST)
Raw View
------=_Part_751_1898878374.1457466217796
Content-Type: multipart/alternative;
 boundary="----=_Part_752_734926934.1457466217798"

------=_Part_752_734926934.1457466217798
Content-Type: text/plain; charset=UTF-8

On Tuesday, March 8, 2016 at 1:34:05 PM UTC-5, Dale Weiler wrote:
>
> Exibit
> class A {
>   A();
>   T *a;
> };
>
>
> Need to know type of *a* here to call new correctly:
>  A::A() : a(new T) { }
>
> Imagine the class member type changes but implementing code stays the
> same, thus it allocates an incorrect amount of memory for the object and
> calls the wrong constructor.
>
>
Unless the new type `U` has an implicit conversion from `T*` to `U*` (for
example, if `U` is a base class of `T`), you get a *compiler error*, not
allocating "an incorrect amount of memory".

 How do we solve this?
>
>
I don't think this is a problem that needs to be solved.


> A::A() : a (new typename remove_reference<decltype(A::a)>::type) { }
>
>
> Not that pretty but does handle this case. What's interesting is in these
> contexts the compiler knows the type from the binding side:
> T *a = new T;
> T *b(new T);
>
>
> We can see this is true with container types too:
> unique_ptr<T> a = make_unique<T>(...);
> unique_ptr<T> b(new T(...));
> shared_ptr<T> c = make_shared<T>(...);
> shared_ptr<T> d(new T(...));
>
> Lets review our original example now with *new auto:*
> A::A() : a(new auto) { }
>
> Changes of the class member type does not affect implementing code,
> since *auto* knows the type
>
> Consistent with other forms of initialization as well:
> T *a = new auto;
> T *a(new auto);
>
> Ambigious
> *new auto(expr)* already exists in C++, it's defined such that new allocates
> storage for type of *expr* and constructs with value of *expr*.
>
> We argue this behavior is inconsistent with the rest of the language as*auto* is treated as a non-type and as a function-style cast in this example.
>
>
How is it inconsistent? `new auto(expr)` doesn't treat `auto` as a type
anymore than `auto x = expr` does. It treats `auto` as a type to be deduced
based on `expr`.

And let's pretend that it is inconsistent. So what? Being able to do `new
auto(expr)` is *very useful*; you shouldn't take that away for something
that is decidedly less useful.

With explicit initialization this would be preferred behavior of the syntax,
> which shouldn't break anything either:
> T *a = new auto(...);
> T *b(new auto(...));
>
> Assuming existing C++ code uses *new auto(expr)*, the binding
> side of the expression must have same type as the new expression,
> otherwise a compile error results. The only time this is not the case
> is when a *reinterpret_cast* is used on the result of the new expression which
> is undefined unless the pointer types are compatible. When the binding side
> is of the same type as the new expression the result is consistent with
> this proposal and does not break existing C++ code that uses *new auto(expr)*.
>
>
Unless of course you want to do this:

auto p = new auto(expr);

Where the type of `p` is determined based on the type of `expr`.

Breaking existing programs is a non-starter for something like this.

Visibility
>
> What we obtain is improved visibility for containment and consistency
> with respect to *auto* and other language syntax.
>
> For example *make_unique* and *make_shared* can be made much simpler and
> better:
> template <typename T, typename A...>
> unique_ptr<T> make_unique(A&&... a) {
>   // Note we don't use new T here since that prevents visibility
>   return { new auto(forward<A>(a)...) };
> }
> template <typename T, typename A...>
> shared_ptr<T> make_shared(A&&... a) {
>   // Ditto no use of new T here either
>   return { new auto(forward<A>(a)...) };
> }
>
>
> Now *make_unique* and *make_shared* can access private constructors,
> since `auto` avoids the visibility problem in this construct:
>
> class A {
>   A() { ... }
> public:
>   void x() {
>     auto x = make_unique<A>(); // Works!
>     ...
>   }
> };
>
> However outside class scope:
> auto x = make_unique<A>(); // Does not work since private (as expected)
>
>
That... makes absolutely no sense. You are suggesting that we require the
compiler to decide whether the code within that function is legal or not
based on where it *gets called from*? That's *insane*.

Even in the context of template instantiation, you're violating the One
Definition Rule. The reason being that `make_unqiue<A>` is a function. And
in every translation unit, that function must have the same definition for
the same A. You can't make one version of `make_unique` callable and a
different version not callable based on where you call it from.

If you want to allow some from of private forwarding, then you're going to
have to do it the hard way. Like this:

class A {
  static key_type key_;
public:
  explicit A(key_type) { ... }


  void x() {
    auto x = make_unique<A>(key_); // Works!
    ...
  }
};

auto x = make_unique<A>(A::key_); //Access to `A::key_` is restricted.

Furthermore, this doesn't solve the visibility problem for things like
`make_tuple`, since it doesn't use `new` at all.

--
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/eaca51a5-050f-43f7-a4f0-84ea17ed9d90%40isocpp.org.

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

<div dir=3D"ltr">On Tuesday, March 8, 2016 at 1:34:05 PM UTC-5, Dale Weiler=
 wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><pre><font size=3D"6">E=
xibit</font><br>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#008">class</span><span style=3D"color:#000"> A </span><s=
pan style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 A</s=
pan><span style=3D"color:#660">();</span><span style=3D"color:#000"><br>=C2=
=A0 T </span><span style=3D"color:#660">*</span><span style=3D"color:#000">=
a</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br><=
/span><span style=3D"color:#660">};</span></div></code></div>

Need to know type of <b>a</b> here to call new correctly:
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#000">=C2=A0A</span><span style=3D"color:#660">::</span><=
span style=3D"color:#000">A</span><span style=3D"color:#660">()</span><span=
 style=3D"color:#000"> </span><span style=3D"color:#660">:</span><span styl=
e=3D"color:#000"> a</span><span style=3D"color:#660">(</span><span style=3D=
"color:#008">new</span><span style=3D"color:#000"> T</span><span style=3D"c=
olor:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:=
#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#660"=
>}</span></div></code></div>
Imagine the class member type changes but implementing code stays the
same, thus it allocates an incorrect amount of memory for the object and
calls the wrong constructor.</pre></blockquote><div><br>Unless the new type=
 `U` has an implicit conversion from `T*` to `U*` (for example, if `U` is a=
 base class of `T`), you get a <i>compiler error</i>, not allocating &quot;=
an incorrect amount of memory&quot;.<br><br></div><blockquote class=3D"gmai=
l_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;=
padding-left: 1ex;"><pre> How do we solve this? <br></pre></blockquote><div=
><br>I don&#39;t think this is a problem that needs to be solved.<br>=C2=A0=
</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8=
ex;border-left: 1px #ccc solid;padding-left: 1ex;"><pre><div style=3D"backg=
round-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:sol=
id;border-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#=
000">A</span><span style=3D"color:#660">::</span><span style=3D"color:#000"=
>A</span><span style=3D"color:#660">()</span><span style=3D"color:#000"> </=
span><span style=3D"color:#660">:</span><span style=3D"color:#000"> a </spa=
n><span style=3D"color:#660">(</span><span style=3D"color:#008">new</span><=
span style=3D"color:#000"> </span><span style=3D"color:#008">typename</span=
><span style=3D"color:#000"> remove_reference</span><span style=3D"color:#6=
60">&lt;</span><span style=3D"color:#008">decltype</span><span style=3D"col=
or:#660">(</span><span style=3D"color:#000">A</span><span style=3D"color:#6=
60">::</span><span style=3D"color:#000">a</span><span style=3D"color:#660">=
<wbr>)&gt;::</span><span style=3D"color:#000">type</span><span style=3D"col=
or:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"> </span><span style=3D"color:#660">}=
</span></div></code></div><br>
Not that pretty but does handle this case. What&#39;s interesting is in the=
se
contexts the compiler knows the type from the binding side:<br><div style=
=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);border-=
style:solid;border-width:1px;word-wrap:break-word"><code><div><span style=
=3D"color:#000">T </span><span style=3D"color:#660">*</span><span style=3D"=
color:#000">a </span><span style=3D"color:#660">=3D</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#008">new</span><span style=3D"color=
:#000"> T</span><span style=3D"color:#660">;</span><span style=3D"color:#00=
0"><br>T </span><span style=3D"color:#660">*</span><span style=3D"color:#00=
0">b</span><span style=3D"color:#660">(</span><span style=3D"color:#008">ne=
w</span><span style=3D"color:#000"> T</span><span style=3D"color:#660">);</=
span></div></code></div><br>
We can see this is true with container types too:
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#000">unique_ptr</span><span style=3D"color:#660">&lt;</s=
pan><span style=3D"color:#000">T</span><span style=3D"color:#660">&gt;</spa=
n><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">&=
lt;</span><span style=3D"color:#000">T</span><span style=3D"color:#660">&gt=
;(...);</span><span style=3D"color:#000"><br>unique_ptr</span><span style=
=3D"color:#660">&lt;</span><span style=3D"color:#000">T</span><span style=
=3D"color:#660">&gt;</span><span style=3D"color:#000"> b</span><span style=
=3D"color:#660">(</span><span style=3D"color:#008">new</span><span style=3D=
"color:#000"> T</span><span style=3D"color:#660">(...));</span><span style=
=3D"color:#000"><br>shared_ptr</span><span style=3D"color:#660">&lt;</span>=
<span style=3D"color:#000">T</span><span style=3D"color:#660">&gt;</span><s=
pan style=3D"color:#000"> c </span><span style=3D"color:#660">=3D</span><sp=
an style=3D"color:#000"> make_shared</span><span style=3D"color:#660">&lt;<=
/span><span style=3D"color:#000">T</span><span style=3D"color:#660">&gt;(..=
..);</span><span style=3D"color:#000"> <br>shared_ptr</span><span style=3D"c=
olor:#660">&lt;</span><span style=3D"color:#000">T</span><span style=3D"col=
or:#660">&gt;</span><span style=3D"color:#000"> d</span><span style=3D"colo=
r:#660">(</span><span style=3D"color:#008">new</span><span style=3D"color:#=
000"> T</span><span style=3D"color:#660">(...));</span><span style=3D"color=
:#000"><br></span></div></code></div>
Lets review our original example now with <b>new auto:</b>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#000">A</span><span style=3D"color:#660">::</span><span s=
tyle=3D"color:#000">A</span><span style=3D"color:#660">()</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">:</span><span style=3D"c=
olor:#000"> a</span><span style=3D"color:#660">(</span><span style=3D"color=
:#008">new</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
08">auto</span><span style=3D"color:#660">)</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </=
span><span style=3D"color:#660">}</span><span style=3D"color:#000"><br></sp=
an></div></code></div><br>Changes of the class member type does not affect =
implementing code,
since <b>auto</b> knows the type

Consistent with other forms of initialization as well:<br><div style=3D"bac=
kground-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:s=
olid;border-width:1px;word-wrap:break-word"><code><div><span style=3D"color=
:#000">T </span><span style=3D"color:#660">*</span><span style=3D"color:#00=
0">a </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"=
> </span><span style=3D"color:#008">new</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#008">auto</span><span style=3D"color:#660">;</s=
pan><span style=3D"color:#000"><br>T </span><span style=3D"color:#660">*</s=
pan><span style=3D"color:#000">a</span><span style=3D"color:#660">(</span><=
span style=3D"color:#008">new</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#008">auto</span><span style=3D"color:#660">);</span></div=
></code></div>

<font size=3D"6">Ambigious</font>

<b>new auto(expr)</b> already exists in C++, it&#39;s defined such that new=
 allocates<br>storage for type of <b>expr</b> and constructs with value of =
<b>expr</b>.

We argue this behavior is inconsistent with the rest of the language as
<b>auto</b> is treated as a non-type and as a function-style cast in this e=
xample.</pre></blockquote><div><br>How is it inconsistent? `new auto(expr)`=
 doesn&#39;t treat `auto` as a type anymore than `auto x =3D expr` does. It=
 treats `auto` as a type to be deduced based on `expr`.<br><br>And let&#39;=
s pretend that it is inconsistent. So what? Being able to do `new auto(expr=
)` is <i>very useful</i>; you shouldn&#39;t take that away for something th=
at is decidedly less useful.<br><br></div><blockquote class=3D"gmail_quote"=
 style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-=
left: 1ex;"><pre>With explicit initialization this would be preferred behav=
ior of the syntax,
which shouldn&#39;t break anything either:
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#000">T </span><span style=3D"color:#660">*</span><span s=
tyle=3D"color:#000">a </span><span style=3D"color:#660">=3D</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#008">new</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">auto</span><span style=
=3D"color:#660">(...);</span><span style=3D"color:#000"><br>T </span><span =
style=3D"color:#660">*</span><span style=3D"color:#000">b</span><span style=
=3D"color:#660">(</span><span style=3D"color:#008">new</span><span style=3D=
"color:#000"> </span><span style=3D"color:#008">auto</span><span style=3D"c=
olor:#660">(...));</span></div></code></div><br></pre></blockquote><blockqu=
ote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left=
: 1px #ccc solid;padding-left: 1ex;"><pre>Assuming existing C++ code uses <=
b>new auto(expr)</b>, the binding<br>side of the expression must have same =
type as the new expression,<br>otherwise a compile error results. The only =
time this is not the case<br>is when a <b>reinterpret_cast</b> is used on t=
he result of the new expression which<br>is undefined unless the pointer ty=
pes are compatible. When the binding side<br>is of the same type as the new=
 expression the result is consistent with<br>this proposal and does not bre=
ak existing C++ code that uses <b>new auto(expr)</b>.<br></pre></blockquote=
><div><br>Unless of course you want to do this:<br><br><div class=3D"pretty=
print" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187=
, 187, 187); border-style: solid; border-width: 1px; 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"> p </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">new</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">a=
uto</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">expr</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">);</span></div></code>=
</div><br>Where the type of `p` is determined based on the type of `expr`.<=
br><br>Breaking existing programs is a non-starter for something like this.=
<br><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><pre><font size=
=3D"6">Visibility<br><br></font>What we obtain is improved visibility for c=
ontainment and consistency
with respect to <b>auto</b> and other language syntax.

For example <b>make_unique</b> and <b>make_shared</b> can be made much simp=
ler and=20
better:
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an 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</s=
pan><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</spa=
n><span style=3D"color:#000"> A</span><span style=3D"color:#660">...&gt;</s=
pan><span style=3D"color:#000"><br>unique_ptr</span><span style=3D"color:#6=
60">&lt;</span><span style=3D"color:#000">T</span><span style=3D"color:#660=
">&gt;</span><span style=3D"color:#000"> make_unique</span><span style=3D"c=
olor:#660">(</span><span style=3D"color:#000">A</span><span style=3D"color:=
#660">&amp;&amp;...</span><span style=3D"color:#000"> a</span><span style=
=3D"color:#660">)</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">{</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=
=3D"color:#800">// Note we don&#39;t use new T here since that prevents vis=
ibility</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"c=
olor:#008">return</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:=
#008">new</span><span style=3D"color:#000"> </span><span style=3D"color:#00=
8">auto</span><span style=3D"color:#660">(</span><span style=3D"color:#000"=
>forward</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:#0=
00">a</span><span style=3D"color:#660">)...)</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#660">};</span><span style=3D"color:#000"><=
br></span><span style=3D"color:#660">}</span><span style=3D"color:#000"><br=
></span><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 style=3D"color:#66=
0">,</span><span style=3D"color:#000"> </span><span style=3D"color:#008">ty=
pename</span><span style=3D"color:#000"> A</span><span style=3D"color:#660"=
>...&gt;</span><span style=3D"color:#000"><br>shared_ptr</span><span style=
=3D"color:#660">&lt;</span><span style=3D"color:#000">T</span><span style=
=3D"color:#660">&gt;</span><span style=3D"color:#000"> make_shared</span><s=
pan style=3D"color:#660">(</span><span style=3D"color:#000">A</span><span s=
tyle=3D"color:#660">&amp;&amp;...</span><span style=3D"color:#000"> a</span=
><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 </span=
><span style=3D"color:#800">// Ditto no use of new T here either</span><spa=
n style=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#008">return<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span=
><span style=3D"color:#000"> </span><span style=3D"color:#008">new</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#008">auto</span><spa=
n style=3D"color:#660">(</span><span style=3D"color:#000">forward</span><sp=
an 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">a</span><span =
style=3D"color:#660">)...)</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#660">};</span><span style=3D"color:#000"><br></span><span st=
yle=3D"color:#660">}</span><span style=3D"color:#000"> </span></div></code>=
</div>

Now <b>make_unique</b> and <b>make_shared</b> can access private constructo=
rs,
since `auto` avoids the visibility problem in this construct:<br></pre></bl=
ockquote><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: =
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><pre><div style=3D"ba=
ckground-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:=
solid;border-width:1px;word-wrap:break-word"><code><div><span style=3D"colo=
r:#008">class</span><span style=3D"color:#000"> A </span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"><br>=C2=A0 A</span><span style=
=3D"color:#660">()</span><span style=3D"color:#000"> </span><span style=3D"=
color:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color=
:#660">...</span><span style=3D"color:#000"> </span><span style=3D"color:#6=
60">}</span><span style=3D"color:#000"><br></span><span style=3D"color:#008=
">public</span><span style=3D"color:#660">:</span><span style=3D"color:#000=
"><br>=C2=A0 </span><span style=3D"color:#008">void</span><span style=3D"co=
lor:#000"> x</span><span style=3D"color:#660">()</span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000=
"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">auto</span><span styl=
e=3D"color:#000"> x </span><span style=3D"color:#660">=3D</span><span style=
=3D"color:#000"> make_unique</span><span style=3D"color:#660">&lt;</span><s=
pan style=3D"color:#000">A</span><span style=3D"color:#660">&gt;();</span><=
span style=3D"color:#000"> </span><span style=3D"color:#800">// Works!</spa=
n><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:=
#660">...</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D=
"color:#660">}</span><span style=3D"color:#000"><br></span><span style=3D"c=
olor:#660">};</span></div></code></div>
However outside class scope:<br><div style=3D"background-color:rgb(250,250,=
250);border-color:rgb(187,187,187);border-style:solid;border-width:1px;word=
-wrap:break-word"><code><div><span style=3D"color:#008">auto</span><span st=
yle=3D"color:#000"> x </span><span style=3D"color:#660">=3D</span><span sty=
le=3D"color:#000"> make_unique</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"> </span><span style=3D"color:#800">// Does not =
work since private (as expected)</span><span style=3D"color:#000"><br></spa=
n></div></code></div><br></pre></blockquote><div><br>That... makes absolute=
ly no sense. You are suggesting that we require the compiler to decide whet=
her the code within that function is legal or not based on where it <i>gets=
 called from</i>? That&#39;s <i>insane</i>.<br><br>Even in the context of t=
emplate instantiation, you&#39;re violating the One Definition Rule. The re=
ason being that `make_unqiue&lt;A&gt;` is a function. And in every translat=
ion unit, that function must have the same definition for the same A. You c=
an&#39;t make one version of `make_unique` callable and a different version=
 not callable based on where you call it from.<br><br>If you want to allow =
some from of private forwarding, then you&#39;re going to have to do it the=
 hard way. Like this:<br><br><div class=3D"prettyprint" style=3D"background=
-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style:=
 solid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettypri=
nt"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">class</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> A </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">sta=
tic</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> key_ty=
pe key_</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: #008;" class=3D"styled-by-prettify">public</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">explicit</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> A</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify">key_type</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">...</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br><br><br>=C2=A0 </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> x </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> make_unique</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">key_</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=
: #800;" class=3D"styled-by-prettify">// Works!</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">...</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> x </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> mak=
e_unique</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&l=
t;</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"styled-by-prettify">::</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">key_</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"style=
d-by-prettify">//Access to `A::key_` is restricted.</span></div></code></di=
v><br>Furthermore, this doesn&#39;t solve the visibility problem for things=
 like `make_tuple`, since it doesn&#39;t use `new` at all.<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/eaca51a5-050f-43f7-a4f0-84ea17ed9d90%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/eaca51a5-050f-43f7-a4f0-84ea17ed9d90=
%40isocpp.org</a>.<br />

------=_Part_752_734926934.1457466217798--
------=_Part_751_1898878374.1457466217796--

.


Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Tue, 8 Mar 2016 19:16:01 -0800 (PST)
Raw View
------=_Part_3535_914147474.1457493361379
Content-Type: multipart/alternative;
 boundary="----=_Part_3536_1831975150.1457493361379"

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

On Tuesday, March 8, 2016 at 10:34:05 AM UTC-8, Dale Weiler wrote:
>
> Exibit
> class A {
>   A();
>   T *a;
> };
>
>
> Need to know type of *a* here to call new correctly:
>  A::A() : a(new T) { }
>
> Imagine the class member type changes but implementing code stays the
> same, thus it allocates an incorrect amount of memory for the object and
> calls the wrong constructor. How do we solve this?=20
> A::A() : a (new typename remove_reference<decltype(A::a)>::type) { }
>
>
Now, now, it's not that bad.

A::A() : a(new std::remove_reference_t<decltype(*a)>) {}

Anyway, you can't have the type of auto in new auto depend on the *context=
=20
in which it's called*. That way lies Perl, and std::initializer_list, and=
=20
various other madnesses.

The "best practices" answer in this context is almost certainly *don't use=
=20
naked new.* Use owning smart pointers, or don't use pointers at all, and=20
then you don't need to use new, and then all your problems related to new's=
=20
weird syntax pretty much go away.

my $.02,
=E2=80=93Arthur

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

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

<div dir=3D"ltr">On Tuesday, March 8, 2016 at 10:34:05 AM UTC-8, Dale Weile=
r wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0=
..8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><pre><font size=3D"6">=
Exibit</font><br>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#008">class</span><span style=3D"color:#000"> A </span><s=
pan style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 A</s=
pan><span style=3D"color:#660">();</span><span style=3D"color:#000"><br>=C2=
=A0 T </span><span style=3D"color:#660">*</span><span style=3D"color:#000">=
a</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br><=
/span><span style=3D"color:#660">};</span></div></code></div>

Need to know type of <b>a</b> here to call new correctly:
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#000">=C2=A0A</span><span style=3D"color:#660">::</span><=
span style=3D"color:#000">A</span><span style=3D"color:#660">()</span><span=
 style=3D"color:#000"> </span><span style=3D"color:#660">:</span><span styl=
e=3D"color:#000"> a</span><span style=3D"color:#660">(</span><span style=3D=
"color:#008">new</span><span style=3D"color:#000"> T</span><span style=3D"c=
olor:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:=
#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#660"=
>}</span></div></code></div>
Imagine the class member type changes but implementing code stays the
same, thus it allocates an incorrect amount of memory for the object and
calls the wrong constructor. How do we solve this? <br><div style=3D"backgr=
ound-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:soli=
d;border-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#0=
00">A</span><span style=3D"color:#660">::</span><span style=3D"color:#000">=
A</span><span style=3D"color:#660">()</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">:</span><span style=3D"color:#000"> a </span=
><span style=3D"color:#660">(</span><span style=3D"color:#008">new</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#008">typename</span>=
<span style=3D"color:#000"> remove_reference</span><span style=3D"color:#66=
0">&lt;</span><span style=3D"color:#008">decltype</span><span style=3D"colo=
r:#660">(</span><span style=3D"color:#000">A</span><span style=3D"color:#66=
0">::</span><span style=3D"color:#000">a</span><span style=3D"color:#660"><=
wbr>)&gt;::</span><span style=3D"color:#000">type</span><span style=3D"colo=
r:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:#66=
0">{</span><span style=3D"color:#000"> </span><span style=3D"color:#660">}<=
/span></div></code></div></pre></blockquote><div><br></div><div>Now, now, i=
t&#39;s not that bad.</div><div><br></div><div class=3D"prettyprint" style=
=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, 1=
87); word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subp=
rettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify">A</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">A</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;" cl=
ass=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> a</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>new</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">remove_reference_t</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">decltype</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">(*</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: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">{}</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span></div></code></div><div><br></div><div>Anyway, =
you can&#39;t have the type of <font face=3D"courier new, monospace">auto</=
font> in <font face=3D"courier new, monospace">new auto</font> depend on th=
e <i><b>context in which it&#39;s called</b></i>. That way lies Perl, and <=
font face=3D"courier new, monospace">std::initializer_list</font>, and vari=
ous other madnesses.</div><div><br></div><div>The &quot;best practices&quot=
; answer in this context is almost certainly <b><i>don&#39;t use naked <fon=
t face=3D"courier new, monospace">new</font>.</i></b> Use owning smart poin=
ters, or don&#39;t use pointers at all, and then you don&#39;t need to use =
<font face=3D"courier new, monospace">new</font>, and then all your problem=
s related to <font face=3D"courier new, monospace">new</font>&#39;s weird s=
yntax pretty much go away.</div><div><br></div><div>my $.02,</div><div>=E2=
=80=93Arthur</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/5db50906-b180-475d-9f4d-7453897be2b0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/5db50906-b180-475d-9f4d-7453897be2b0=
%40isocpp.org</a>.<br />

------=_Part_3536_1831975150.1457493361379--
------=_Part_3535_914147474.1457493361379--

.