Topic: Pointer casts with move semantics


Author: pohilets@gmail.com
Date: Sat, 21 May 2016 10:19:59 -0700 (PDT)
Raw View
------=_Part_3165_1371086206.1463851199841
Content-Type: multipart/alternative;
 boundary="----=_Part_3166_828223911.1463851199842"

------=_Part_3166_828223911.1463851199842
Content-Type: text/plain; charset=UTF-8

Recently I was optimizing reference counting in a tight loop, and was
surprised to discover that all pointer cast functions take their argument
by const reference and there are no versions that would take argument by
value or by rvalue reference. As a result, the following code makes a
completely unnecessary atomic increment and decrement:

   struct Foo {};

   struct Bar : public Foo {};

   std::shared_ptr<Foo> foo();

   auto bar = std::static_pointer_cast<Bar>(foo());


An obvious solution would be add versions that take parameter by rvalue
reference:


template<class T, class U> std::shared_ptr<T> static_pointer_cast(const std
::shared_ptr<U>& r);      // since C++11

template<class T, class U> std::shared_ptr<T> dynamic_pointer_cast(const std
::shared_ptr<U>& r);     // since C++11

template<class T, class U> std::shared_ptr<T> const_pointer_cast(const std::
shared_ptr<U>& r);       // since C++11

template<class T, class U> std::shared_ptr<T> reinterpret_pointer_cast(const
std::shared_ptr<U>& r); // since C++17


template<class T, class U> std::shared_ptr<T> static_pointer_cast(std::
shared_ptr<U>&& r);      // proposed addition

template<class T, class U> std::shared_ptr<T> dynamic_pointer_cast(std::
shared_ptr<U>&& r);     // proposed addition

template<class T, class U> std::shared_ptr<T> const_pointer_cast(std::
shared_ptr<U>&& r);       // proposed addition

template<class T, class U> std::shared_ptr<T> reinterpret_pointer_cast(std::
shared_ptr<U>&& r); // proposed addition


Or just have a single version of each function, that takes argument by
value:


template<class T, class U> std::shared_ptr<T> static_pointer_cast(std::
shared_ptr<U> r);      // proposed replacement

template<class T, class U> std::shared_ptr<T> dynamic_pointer_cast(std::
shared_ptr<U> r);     // proposed replacement

template<class T, class U> std::shared_ptr<T> const_pointer_cast(std::
shared_ptr<U> r);       // proposed replacement

template<class T, class U> std::shared_ptr<T> reinterpret_pointer_cast(std::
shared_ptr<U> r); // proposed replacement


The later makes a redundant increment/decrement in one case: when doing
dynamic_pointer_cast on a l-value and cast fails



--
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/7c02ff86-424d-48aa-bd5e-a2f768bd5484%40isocpp.org.

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

<div dir=3D"ltr">Recently I was optimizing reference counting in a tight lo=
op, and was surprised to discover that all pointer cast functions take thei=
r argument by const reference and there are no versions that would take arg=
ument by value or by rvalue reference. As a result, the following code make=
s a completely unnecessary atomic increment and decrement:<div><p style=3D"=
font-size: 11px; line-height: normal; font-family: Menlo;"><span style=3D"f=
ont-variant-ligatures: no-common-ligatures; color: #bb2ca2">=C2=A0 =C2=A0st=
ruct</span><span style=3D"font-variant-ligatures: no-common-ligatures"> Foo=
 {};</span></p>
<p style=3D"font-size: 11px; line-height: normal; font-family: Menlo;"><spa=
n style=3D"font-variant-ligatures: no-common-ligatures; color: #bb2ca2">=C2=
=A0 =C2=A0struct</span><span style=3D"font-variant-ligatures: no-common-lig=
atures"> Bar : </span><span style=3D"font-variant-ligatures: no-common-liga=
tures; color: #bb2ca2">public</span><span style=3D"font-variant-ligatures: =
no-common-ligatures"> </span><span style=3D"font-variant-ligatures: no-comm=
on-ligatures; color: #4f8187">Foo</span><span style=3D"font-variant-ligatur=
es: no-common-ligatures"> {};</span></p>
<p style=3D"font-size: 11px; line-height: normal; font-family: Menlo; color=
: rgb(112, 61, 170);"><span style=3D"font-variant-ligatures: no-common-liga=
tures"><span style=3D"color: rgb(187, 44, 162);">=C2=A0 =C2=A0</span>std</s=
pan><span style=3D"font-variant-ligatures: no-common-ligatures; color: #000=
000">::</span><span style=3D"font-variant-ligatures: no-common-ligatures">s=
hared_ptr</span><span style=3D"font-variant-ligatures: no-common-ligatures;=
 color: #000000">&lt;</span><span style=3D"font-variant-ligatures: no-commo=
n-ligatures; color: #4f8187">Foo</span><span style=3D"font-variant-ligature=
s: no-common-ligatures; color: #000000">&gt; foo();</span></p>
<p style=3D"font-size: 11px; line-height: normal; font-family: Menlo; color=
: rgb(61, 29, 129);"><span style=3D"font-variant-ligatures: no-common-ligat=
ures; color: #bb2ca2">=C2=A0 =C2=A0auto</span><span style=3D"font-variant-l=
igatures: no-common-ligatures; color: #000000"> bar =3D </span><span style=
=3D"font-variant-ligatures: no-common-ligatures; color: #703daa">std</span>=
<span style=3D"font-variant-ligatures: no-common-ligatures; color: #000000"=
>::</span><span style=3D"font-variant-ligatures: no-common-ligatures">stati=
c_pointer_cast</span><span style=3D"font-variant-ligatures: no-common-ligat=
ures; color: #000000">&lt;</span><span style=3D"font-variant-ligatures: no-=
common-ligatures; color: #4f8187">Bar</span><span style=3D"font-variant-lig=
atures: no-common-ligatures; color: #000000">&gt;(</span><span style=3D"fon=
t-variant-ligatures: no-common-ligatures; color: #31595d">foo</span><span s=
tyle=3D"font-variant-ligatures: no-common-ligatures; color: #000000">());</=
span></p><p style=3D"font-size: 11px; line-height: normal; font-family: Men=
lo; color: rgb(61, 29, 129);"><span style=3D"font-variant-ligatures: no-com=
mon-ligatures; color: #000000"><br></span></p><p style=3D"font-size: 11px; =
line-height: normal; font-family: Menlo;"><span style=3D"font-family: Arial=
, Helvetica, sans-serif; font-size: 13px;">An obvious solution would be add=
 versions that take parameter by rvalue reference</span><span style=3D"font=
-family: Arial, Helvetica, sans-serif; font-size: 13px;">:</span></p><p sty=
le=3D"font-size: 11px; line-height: normal; font-family: Menlo;"><span styl=
e=3D"font-family: Arial, Helvetica, sans-serif; font-size: 13px;"><br></spa=
n></p><p style=3D"font-size: 11px; line-height: normal; font-family: Menlo;=
"><span style=3D"font-variant-ligatures: no-common-ligatures; color: #bb2ca=
2">template</span><span style=3D"font-variant-ligatures: no-common-ligature=
s">&lt;</span><span style=3D"font-variant-ligatures: no-common-ligatures; c=
olor: #bb2ca2">class</span><span style=3D"font-variant-ligatures: no-common=
-ligatures"> T, </span><span style=3D"font-variant-ligatures: no-common-lig=
atures; color: #bb2ca2">class</span><span style=3D"font-variant-ligatures: =
no-common-ligatures"> U&gt; </span><span style=3D"font-variant-ligatures: n=
o-common-ligatures; color: #703daa">std</span><span style=3D"font-variant-l=
igatures: no-common-ligatures">::</span><span style=3D"font-variant-ligatur=
es: no-common-ligatures; color: #703daa">shared_ptr</span><span style=3D"fo=
nt-variant-ligatures: no-common-ligatures">&lt;T&gt; static_pointer_cast(</=
span><span style=3D"font-variant-ligatures: no-common-ligatures; color: #bb=
2ca2">const</span><span style=3D"font-variant-ligatures: no-common-ligature=
s"> </span><span style=3D"font-variant-ligatures: no-common-ligatures; colo=
r: #703daa">std</span><span style=3D"font-variant-ligatures: no-common-liga=
tures">::</span><span style=3D"font-variant-ligatures: no-common-ligatures;=
 color: #703daa">shared_ptr</span><span style=3D"font-variant-ligatures: no=
-common-ligatures">&lt;U&gt;&amp; r);=C2=A0 =C2=A0 =C2=A0 </span><span styl=
e=3D"font-variant-ligatures: no-common-ligatures; color: #008400">// since =
C++11</span></p><p style=3D"font-size: 11px; line-height: normal; font-fami=
ly: Menlo;"><span style=3D"font-variant-ligatures: no-common-ligatures; col=
or: #bb2ca2">template</span><span style=3D"font-variant-ligatures: no-commo=
n-ligatures">&lt;</span><span style=3D"font-variant-ligatures: no-common-li=
gatures; color: #bb2ca2">class</span><span style=3D"font-variant-ligatures:=
 no-common-ligatures"> T, </span><span style=3D"font-variant-ligatures: no-=
common-ligatures; color: #bb2ca2">class</span><span style=3D"font-variant-l=
igatures: no-common-ligatures"> U&gt; </span><span style=3D"font-variant-li=
gatures: no-common-ligatures; color: #703daa">std</span><span style=3D"font=
-variant-ligatures: no-common-ligatures">::</span><span style=3D"font-varia=
nt-ligatures: no-common-ligatures; color: #703daa">shared_ptr</span><span s=
tyle=3D"font-variant-ligatures: no-common-ligatures">&lt;T&gt; dynamic_poin=
ter_cast(</span><span style=3D"font-variant-ligatures: no-common-ligatures;=
 color: #bb2ca2">const</span><span style=3D"font-variant-ligatures: no-comm=
on-ligatures"> </span><span style=3D"font-variant-ligatures: no-common-liga=
tures; color: #703daa">std</span><span style=3D"font-variant-ligatures: no-=
common-ligatures">::</span><span style=3D"font-variant-ligatures: no-common=
-ligatures; color: #703daa">shared_ptr</span><span style=3D"font-variant-li=
gatures: no-common-ligatures">&lt;U&gt;&amp; r); =C2=A0 =C2=A0 </span><span=
 style=3D"font-variant-ligatures: no-common-ligatures; color: #008400">// s=
ince C++11</span></p><p style=3D"font-size: 11px; line-height: normal; font=
-family: Menlo;"><span style=3D"font-variant-ligatures: no-common-ligatures=
; color: #bb2ca2">template</span><span style=3D"font-variant-ligatures: no-=
common-ligatures">&lt;</span><span style=3D"font-variant-ligatures: no-comm=
on-ligatures; color: #bb2ca2">class</span><span style=3D"font-variant-ligat=
ures: no-common-ligatures"> T, </span><span style=3D"font-variant-ligatures=
: no-common-ligatures; color: #bb2ca2">class</span><span style=3D"font-vari=
ant-ligatures: no-common-ligatures"> U&gt; </span><span style=3D"font-varia=
nt-ligatures: no-common-ligatures; color: #703daa">std</span><span style=3D=
"font-variant-ligatures: no-common-ligatures">::</span><span style=3D"font-=
variant-ligatures: no-common-ligatures; color: #703daa">shared_ptr</span><s=
pan style=3D"font-variant-ligatures: no-common-ligatures">&lt;T&gt; const_p=
ointer_cast(</span><span style=3D"font-variant-ligatures: no-common-ligatur=
es; color: #bb2ca2">const</span><span style=3D"font-variant-ligatures: no-c=
ommon-ligatures"> </span><span style=3D"font-variant-ligatures: no-common-l=
igatures; color: #703daa">std</span><span style=3D"font-variant-ligatures: =
no-common-ligatures">::</span><span style=3D"font-variant-ligatures: no-com=
mon-ligatures; color: #703daa">shared_ptr</span><span style=3D"font-variant=
-ligatures: no-common-ligatures">&lt;U&gt;&amp; r); =C2=A0 =C2=A0 =C2=A0 </=
span><span style=3D"font-variant-ligatures: no-common-ligatures; color: #00=
8400">// since C++11</span></p><p style=3D"font-size: 11px; line-height: no=
rmal; font-family: Menlo;"><span style=3D"font-variant-ligatures: no-common=
-ligatures; color: #bb2ca2">template</span><span style=3D"font-variant-liga=
tures: no-common-ligatures">&lt;</span><span style=3D"font-variant-ligature=
s: no-common-ligatures; color: #bb2ca2">class</span><span style=3D"font-var=
iant-ligatures: no-common-ligatures"> T, </span><span style=3D"font-variant=
-ligatures: no-common-ligatures; color: #bb2ca2">class</span><span style=3D=
"font-variant-ligatures: no-common-ligatures"> U&gt; </span><span style=3D"=
font-variant-ligatures: no-common-ligatures; color: #703daa">std</span><spa=
n style=3D"font-variant-ligatures: no-common-ligatures">::</span><span styl=
e=3D"font-variant-ligatures: no-common-ligatures; color: #703daa">shared_pt=
r</span><span style=3D"font-variant-ligatures: no-common-ligatures">&lt;T&g=
t; reinterpret_pointer_cast(</span><span style=3D"font-variant-ligatures: n=
o-common-ligatures; color: #bb2ca2">const</span><span style=3D"font-variant=
-ligatures: no-common-ligatures"> </span><span style=3D"font-variant-ligatu=
res: no-common-ligatures; color: #703daa">std</span><span style=3D"font-var=
iant-ligatures: no-common-ligatures">::</span><span style=3D"font-variant-l=
igatures: no-common-ligatures; color: #703daa">shared_ptr</span><span style=
=3D"font-variant-ligatures: no-common-ligatures">&lt;U&gt;&amp; r); </span>=
<span style=3D"font-variant-ligatures: no-common-ligatures; color: #008400"=
>// since C++17</span></p><p style=3D"font-size: 11px; line-height: normal;=
 font-family: Menlo; min-height: 13px;"><span style=3D"font-variant-ligatur=
es: no-common-ligatures"></span><br></p><p style=3D"font-size: 11px; line-h=
eight: normal; font-family: Menlo;"><span style=3D"font-variant-ligatures: =
no-common-ligatures; color: #bb2ca2">template</span><span style=3D"font-var=
iant-ligatures: no-common-ligatures">&lt;</span><span style=3D"font-variant=
-ligatures: no-common-ligatures; color: #bb2ca2">class</span><span style=3D=
"font-variant-ligatures: no-common-ligatures"> T, </span><span style=3D"fon=
t-variant-ligatures: no-common-ligatures; color: #bb2ca2">class</span><span=
 style=3D"font-variant-ligatures: no-common-ligatures"> U&gt; </span><span =
style=3D"font-variant-ligatures: no-common-ligatures; color: #703daa">std</=
span><span style=3D"font-variant-ligatures: no-common-ligatures">::</span><=
span style=3D"font-variant-ligatures: no-common-ligatures; color: #703daa">=
shared_ptr</span><span style=3D"font-variant-ligatures: no-common-ligatures=
">&lt;T&gt; static_pointer_cast(</span><span style=3D"font-variant-ligature=
s: no-common-ligatures; color: #703daa">std</span><span style=3D"font-varia=
nt-ligatures: no-common-ligatures">::</span><span style=3D"font-variant-lig=
atures: no-common-ligatures; color: #703daa">shared_ptr</span><span style=
=3D"font-variant-ligatures: no-common-ligatures">&lt;U&gt;&amp;&amp; r); =
=C2=A0 =C2=A0 =C2=A0</span><span style=3D"font-variant-ligatures: no-common=
-ligatures; color: #008400">// proposed addition</span></p><p style=3D"font=
-size: 11px; line-height: normal; font-family: Menlo;"><span style=3D"font-=
variant-ligatures: no-common-ligatures; color: #bb2ca2">template</span><spa=
n style=3D"font-variant-ligatures: no-common-ligatures">&lt;</span><span st=
yle=3D"font-variant-ligatures: no-common-ligatures; color: #bb2ca2">class</=
span><span style=3D"font-variant-ligatures: no-common-ligatures"> T, </span=
><span style=3D"font-variant-ligatures: no-common-ligatures; color: #bb2ca2=
">class</span><span style=3D"font-variant-ligatures: no-common-ligatures"> =
U&gt; </span><span style=3D"font-variant-ligatures: no-common-ligatures; co=
lor: #703daa">std</span><span style=3D"font-variant-ligatures: no-common-li=
gatures">::</span><span style=3D"font-variant-ligatures: no-common-ligature=
s; color: #703daa">shared_ptr</span><span style=3D"font-variant-ligatures: =
no-common-ligatures">&lt;T&gt; dynamic_pointer_cast(</span><span style=3D"f=
ont-variant-ligatures: no-common-ligatures; color: #703daa">std</span><span=
 style=3D"font-variant-ligatures: no-common-ligatures">::</span><span style=
=3D"font-variant-ligatures: no-common-ligatures; color: #703daa">shared_ptr=
</span><span style=3D"font-variant-ligatures: no-common-ligatures">&lt;U&gt=
;&amp;&amp; r);=C2=A0 =C2=A0 =C2=A0</span><span style=3D"font-variant-ligat=
ures: no-common-ligatures; color: #008400">// proposed addition</span></p><=
p style=3D"font-size: 11px; line-height: normal; font-family: Menlo;"><span=
 style=3D"font-variant-ligatures: no-common-ligatures; color: #bb2ca2">temp=
late</span><span style=3D"font-variant-ligatures: no-common-ligatures">&lt;=
</span><span style=3D"font-variant-ligatures: no-common-ligatures; color: #=
bb2ca2">class</span><span style=3D"font-variant-ligatures: no-common-ligatu=
res"> T, </span><span style=3D"font-variant-ligatures: no-common-ligatures;=
 color: #bb2ca2">class</span><span style=3D"font-variant-ligatures: no-comm=
on-ligatures"> U&gt; </span><span style=3D"font-variant-ligatures: no-commo=
n-ligatures; color: #703daa">std</span><span style=3D"font-variant-ligature=
s: no-common-ligatures">::</span><span style=3D"font-variant-ligatures: no-=
common-ligatures; color: #703daa">shared_ptr</span><span style=3D"font-vari=
ant-ligatures: no-common-ligatures">&lt;T&gt; const_pointer_cast(</span><sp=
an style=3D"font-variant-ligatures: no-common-ligatures; color: #703daa">st=
d</span><span style=3D"font-variant-ligatures: no-common-ligatures">::</spa=
n><span style=3D"font-variant-ligatures: no-common-ligatures; color: #703da=
a">shared_ptr</span><span style=3D"font-variant-ligatures: no-common-ligatu=
res">&lt;U&gt;&amp;&amp; r);=C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=
=3D"font-variant-ligatures: no-common-ligatures; color: #008400">// propose=
d addition</span></p><p style=3D"font-size: 11px; line-height: normal; font=
-family: Menlo; color: rgb(187, 44, 162);">







</p><p style=3D"font-size: 11px; line-height: normal; font-family: Menlo;">=
<span style=3D"font-variant-ligatures: no-common-ligatures; color: #bb2ca2"=
>template</span><span style=3D"font-variant-ligatures: no-common-ligatures"=
>&lt;</span><span style=3D"font-variant-ligatures: no-common-ligatures; col=
or: #bb2ca2">class</span><span style=3D"font-variant-ligatures: no-common-l=
igatures"> T, </span><span style=3D"font-variant-ligatures: no-common-ligat=
ures; color: #bb2ca2">class</span><span style=3D"font-variant-ligatures: no=
-common-ligatures"> U&gt; </span><span style=3D"font-variant-ligatures: no-=
common-ligatures; color: #703daa">std</span><span style=3D"font-variant-lig=
atures: no-common-ligatures">::</span><span style=3D"font-variant-ligatures=
: no-common-ligatures; color: #703daa">shared_ptr</span><span style=3D"font=
-variant-ligatures: no-common-ligatures">&lt;T&gt; reinterpret_pointer_cast=
(</span><span style=3D"font-variant-ligatures: no-common-ligatures; color: =
#703daa">std</span><span style=3D"font-variant-ligatures: no-common-ligatur=
es">::</span><span style=3D"font-variant-ligatures: no-common-ligatures; co=
lor: #703daa">shared_ptr</span><span style=3D"font-variant-ligatures: no-co=
mmon-ligatures">&lt;U&gt;&amp;&amp; r);=C2=A0</span><span style=3D"font-var=
iant-ligatures: no-common-ligatures; color: #008400">// proposed addition</=
span></p><p style=3D"font-size: 11px; line-height: normal; font-family: Men=
lo;"><span style=3D"font-variant-ligatures: no-common-ligatures; color: #00=
8400"><br></span></p><p style=3D"font-size: 11px; line-height: normal; font=
-family: Menlo;"><span style=3D"font-variant-ligatures: no-common-ligatures=
; color: #008400"><span style=3D"color: rgb(34, 34, 34); font-family: Arial=
, Helvetica, sans-serif; font-size: 13px;">Or just have a single version of=
 each function, that takes argument by value:</span><br></span></p><p style=
=3D"font-size: 11px; line-height: normal; font-family: Menlo;"><span style=
=3D"font-variant-ligatures: no-common-ligatures; color: #008400"><span styl=
e=3D"color: rgb(34, 34, 34); font-family: Arial, Helvetica, sans-serif; fon=
t-size: 13px;"><br></span></span></p><p style=3D"font-size: 11px; line-heig=
ht: normal; font-family: Menlo;"><span style=3D"font-variant-ligatures: no-=
common-ligatures; color: rgb(187, 44, 162);">template</span><span style=3D"=
font-variant-ligatures: no-common-ligatures;">&lt;</span><span style=3D"fon=
t-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">class<=
/span><span style=3D"font-variant-ligatures: no-common-ligatures;">=C2=A0T,=
=C2=A0</span><span style=3D"font-variant-ligatures: no-common-ligatures; co=
lor: rgb(187, 44, 162);">class</span><span style=3D"font-variant-ligatures:=
 no-common-ligatures;">=C2=A0U&gt;=C2=A0</span><span style=3D"font-variant-=
ligatures: no-common-ligatures; color: rgb(112, 61, 170);">std</span><span =
style=3D"font-variant-ligatures: no-common-ligatures;">::</span><span style=
=3D"font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);"=
>shared_ptr</span><span style=3D"font-variant-ligatures: no-common-ligature=
s;">&lt;T&gt; static_pointer_cast(</span><span style=3D"font-variant-ligatu=
res: no-common-ligatures; color: rgb(112, 61, 170);">std</span><span style=
=3D"font-variant-ligatures: no-common-ligatures;">::</span><span style=3D"f=
ont-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">shar=
ed_ptr</span><span style=3D"font-variant-ligatures: no-common-ligatures;">&=
lt;U&gt; r);=C2=A0=C2=A0 =C2=A0 =C2=A0</span><span style=3D"font-variant-li=
gatures: no-common-ligatures; color: rgb(0, 132, 0);">// proposed replaceme=
nt</span></p><p style=3D"font-size: 11px; line-height: normal; font-family:=
 Menlo;"><span style=3D"font-variant-ligatures: no-common-ligatures; color:=
 rgb(187, 44, 162);">template</span><span style=3D"font-variant-ligatures: =
no-common-ligatures;">&lt;</span><span style=3D"font-variant-ligatures: no-=
common-ligatures; color: rgb(187, 44, 162);">class</span><span style=3D"fon=
t-variant-ligatures: no-common-ligatures;">=C2=A0T,=C2=A0</span><span style=
=3D"font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);"=
>class</span><span style=3D"font-variant-ligatures: no-common-ligatures;">=
=C2=A0U&gt;=C2=A0</span><span style=3D"font-variant-ligatures: no-common-li=
gatures; color: rgb(112, 61, 170);">std</span><span style=3D"font-variant-l=
igatures: no-common-ligatures;">::</span><span style=3D"font-variant-ligatu=
res: no-common-ligatures; color: rgb(112, 61, 170);">shared_ptr</span><span=
 style=3D"font-variant-ligatures: no-common-ligatures;">&lt;T&gt; dynamic_p=
ointer_cast(</span><span style=3D"font-variant-ligatures: no-common-ligatur=
es; color: rgb(112, 61, 170);">std</span><span style=3D"font-variant-ligatu=
res: no-common-ligatures;">::</span><span style=3D"font-variant-ligatures: =
no-common-ligatures; color: rgb(112, 61, 170);">shared_ptr</span><span styl=
e=3D"font-variant-ligatures: no-common-ligatures;">&lt;U&gt; r);=C2=A0 =C2=
=A0 =C2=A0</span><span style=3D"font-variant-ligatures: no-common-ligatures=
; color: rgb(0, 132, 0);">// proposed=C2=A0</span><span style=3D"color: rgb=
(0, 132, 0);">replacement</span></p><p style=3D"font-size: 11px; line-heigh=
t: normal; font-family: Menlo;"><span style=3D"font-variant-ligatures: no-c=
ommon-ligatures; color: rgb(187, 44, 162);">template</span><span style=3D"f=
ont-variant-ligatures: no-common-ligatures;">&lt;</span><span style=3D"font=
-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">class</=
span><span style=3D"font-variant-ligatures: no-common-ligatures;">=C2=A0T,=
=C2=A0</span><span style=3D"font-variant-ligatures: no-common-ligatures; co=
lor: rgb(187, 44, 162);">class</span><span style=3D"font-variant-ligatures:=
 no-common-ligatures;">=C2=A0U&gt;=C2=A0</span><span style=3D"font-variant-=
ligatures: no-common-ligatures; color: rgb(112, 61, 170);">std</span><span =
style=3D"font-variant-ligatures: no-common-ligatures;">::</span><span style=
=3D"font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);"=
>shared_ptr</span><span style=3D"font-variant-ligatures: no-common-ligature=
s;">&lt;T&gt; const_pointer_cast(</span><span style=3D"font-variant-ligatur=
es: no-common-ligatures; color: rgb(112, 61, 170);">std</span><span style=
=3D"font-variant-ligatures: no-common-ligatures;">::</span><span style=3D"f=
ont-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">shar=
ed_ptr</span><span style=3D"font-variant-ligatures: no-common-ligatures;">&=
lt;U&gt; r);=C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"font-variant-l=
igatures: no-common-ligatures; color: rgb(0, 132, 0);">// proposed=C2=A0</s=
pan><span style=3D"color: rgb(0, 132, 0);">replacement</span></p><p style=
=3D"font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(18=
7, 44, 162);"></p><p style=3D"font-size: 11px; line-height: normal; font-fa=
mily: Menlo;"><span style=3D"font-variant-ligatures: no-common-ligatures; c=
olor: #008400"></span></p><p style=3D"font-size: 11px; line-height: normal;=
 font-family: Menlo;"><span style=3D"font-variant-ligatures: no-common-liga=
tures; color: rgb(187, 44, 162);">template</span><span style=3D"font-varian=
t-ligatures: no-common-ligatures;">&lt;</span><span style=3D"font-variant-l=
igatures: no-common-ligatures; color: rgb(187, 44, 162);">class</span><span=
 style=3D"font-variant-ligatures: no-common-ligatures;">=C2=A0T,=C2=A0</spa=
n><span style=3D"font-variant-ligatures: no-common-ligatures; color: rgb(18=
7, 44, 162);">class</span><span style=3D"font-variant-ligatures: no-common-=
ligatures;">=C2=A0U&gt;=C2=A0</span><span style=3D"font-variant-ligatures: =
no-common-ligatures; color: rgb(112, 61, 170);">std</span><span style=3D"fo=
nt-variant-ligatures: no-common-ligatures;">::</span><span style=3D"font-va=
riant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">shared_ptr=
</span><span style=3D"font-variant-ligatures: no-common-ligatures;">&lt;T&g=
t; reinterpret_pointer_cast(</span><span style=3D"font-variant-ligatures: n=
o-common-ligatures; color: rgb(112, 61, 170);">std</span><span style=3D"fon=
t-variant-ligatures: no-common-ligatures;">::</span><span style=3D"font-var=
iant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">shared_ptr<=
/span><span style=3D"font-variant-ligatures: no-common-ligatures;">&lt;U&gt=
; r);=C2=A0</span><span style=3D"font-variant-ligatures: no-common-ligature=
s; color: rgb(0, 132, 0);">// proposed=C2=A0</span><span style=3D"color: rg=
b(0, 132, 0);">replacement</span></p><p style=3D"font-size: 11px; line-heig=
ht: normal; font-family: Menlo;"><span style=3D"color: rgb(0, 132, 0);"><br=
></span></p><p style=3D"line-height: normal;">The later makes a=C2=A0redund=
ant=C2=A0increment/decrement in one case: when doing=C2=A0<span style=3D"fo=
nt-family: Menlo; font-size: 11px;">dynamic_pointer_cast=C2=A0</span>on a l=
-value and cast fails<span style=3D"font-family: Menlo; font-size: 11px; co=
lor: rgb(0, 132, 0);"><br></span></p><p style=3D"line-height: normal;"><br>=
</p><p style=3D"line-height: normal;"><br></p></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/7c02ff86-424d-48aa-bd5e-a2f768bd5484%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/7c02ff86-424d-48aa-bd5e-a2f768bd5484=
%40isocpp.org</a>.<br />

------=_Part_3166_828223911.1463851199842--

------=_Part_3165_1371086206.1463851199841--

.


Author: Jakob Riedle <jakob.riedle@gmail.com>
Date: Mon, 23 May 2016 08:30:09 -0700 (PDT)
Raw View
------=_Part_280_768251862.1464017409156
Content-Type: text/plain; charset=UTF-8

Very good point! You have got my vote!

--
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/2de5b046-27c1-463d-8eb3-5120033995d5%40isocpp.org.

------=_Part_280_768251862.1464017409156--

.


Author: pohilets@gmail.com
Date: Fri, 1 Jul 2016 03:50:49 -0700 (PDT)
Raw View
------=_Part_267_1398178785.1467370249386
Content-Type: multipart/alternative;
 boundary="----=_Part_268_874370203.1467370249387"

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

Submitted as P0390R0. Should be published in the next mailing

=D1=81=D1=83=D0=B1=D0=BE=D1=82=D0=B0, 21 =D1=82=D1=80=D0=B0=D0=B2=D0=BD=D1=
=8F 2016 =D1=80. 19:19:59 UTC+2 =D0=BA=D0=BE=D1=80=D0=B8=D1=81=D1=82=D1=83=
=D0=B2=D0=B0=D1=87 pohi...@gmail.com=20
=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=B2:
>
> Recently I was optimizing reference counting in a tight loop, and was=20
> surprised to discover that all pointer cast functions take their argument=
=20
> by const reference and there are no versions that would take argument by=
=20
> value or by rvalue reference. As a result, the following code makes a=20
> completely unnecessary atomic increment and decrement:
>
>    struct Foo {};
>
>    struct Bar : public Foo {};
>
>    std::shared_ptr<Foo> foo();
>
>    auto bar =3D std::static_pointer_cast<Bar>(foo());
>
>
> An obvious solution would be add versions that take parameter by rvalue=
=20
> reference:
>
>
> template<class T, class U> std::shared_ptr<T> static_pointer_cast(const=
=20
> std::shared_ptr<U>& r);      // since C++11
>
> template<class T, class U> std::shared_ptr<T> dynamic_pointer_cast(const=
=20
> std::shared_ptr<U>& r);     // since C++11
>
> template<class T, class U> std::shared_ptr<T> const_pointer_cast(const st=
d
> ::shared_ptr<U>& r);       // since C++11
>
> template<class T, class U> std::shared_ptr<T> reinterpret_pointer_cast(
> const std::shared_ptr<U>& r); // since C++17
>
>
> template<class T, class U> std::shared_ptr<T> static_pointer_cast(std::
> shared_ptr<U>&& r);      // proposed addition
>
> template<class T, class U> std::shared_ptr<T> dynamic_pointer_cast(std::
> shared_ptr<U>&& r);     // proposed addition
>
> template<class T, class U> std::shared_ptr<T> const_pointer_cast(std::
> shared_ptr<U>&& r);       // proposed addition
>
> template<class T, class U> std::shared_ptr<T> reinterpret_pointer_cast(st=
d
> ::shared_ptr<U>&& r); // proposed addition
>
>
> Or just have a single version of each function, that takes argument by=20
> value:
>
>
> template<class T, class U> std::shared_ptr<T> static_pointer_cast(std::
> shared_ptr<U> r);      // proposed replacement
>
> template<class T, class U> std::shared_ptr<T> dynamic_pointer_cast(std::
> shared_ptr<U> r);     // proposed replacement
>
> template<class T, class U> std::shared_ptr<T> const_pointer_cast(std::
> shared_ptr<U> r);       // proposed replacement
>
> template<class T, class U> std::shared_ptr<T> reinterpret_pointer_cast(st=
d
> ::shared_ptr<U> r); // proposed replacement
>
>
> The later makes a redundant increment/decrement in one case: when doing=
=20
> dynamic_pointer_cast on a l-value and cast fails
>
>
>
>

--=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/633216ff-c3df-4d6f-b33f-3457c87c7996%40isocpp.or=
g.

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

<div dir=3D"ltr">Submitted as=C2=A0P0390R0. Should be published in the next=
 mailing<div><div><div><br>=D1=81=D1=83=D0=B1=D0=BE=D1=82=D0=B0, 21 =D1=82=
=D1=80=D0=B0=D0=B2=D0=BD=D1=8F 2016 =D1=80. 19:19:59 UTC+2 =D0=BA=D0=BE=D1=
=80=D0=B8=D1=81=D1=82=D1=83=D0=B2=D0=B0=D1=87 pohi...@gmail.com =D0=BD=D0=
=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=B2:<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">Recently I was optimizing reference counting in a ti=
ght loop, and was surprised to discover that all pointer cast functions tak=
e their argument by const reference and there are no versions that would ta=
ke argument by value or by rvalue reference. As a result, the following cod=
e makes a completely unnecessary atomic increment and decrement:<div><p sty=
le=3D"font-size:11px;line-height:normal;font-family:Menlo"><span style=3D"c=
olor:#bb2ca2">=C2=A0 =C2=A0struct</span><span> Foo {};</span></p>
<p style=3D"font-size:11px;line-height:normal;font-family:Menlo"><span styl=
e=3D"color:#bb2ca2">=C2=A0 =C2=A0struct</span><span> Bar : </span><span sty=
le=3D"color:#bb2ca2">public</span><span> </span><span style=3D"color:#4f818=
7">Foo</span><span> {};</span></p>
<p style=3D"font-size:11px;line-height:normal;font-family:Menlo;color:rgb(1=
12,61,170)"><span><span style=3D"color:rgb(187,44,162)">=C2=A0 =C2=A0</span=
>std</span><span style=3D"color:#000000">::</span><span>shared_ptr</span><s=
pan style=3D"color:#000000">&lt;</span><span style=3D"color:#4f8187">Foo</s=
pan><span style=3D"color:#000000">&gt; foo();</span></p>
<p style=3D"font-size:11px;line-height:normal;font-family:Menlo;color:rgb(6=
1,29,129)"><span style=3D"color:#bb2ca2">=C2=A0 =C2=A0auto</span><span styl=
e=3D"color:#000000"> bar =3D </span><span style=3D"color:#703daa">std</span=
><span style=3D"color:#000000">::</span><span>static_pointer_cast</span><sp=
an style=3D"color:#000000">&lt;</span><span style=3D"color:#4f8187">Bar</sp=
an><span style=3D"color:#000000">&gt;(</span><span style=3D"color:#31595d">=
<wbr>foo</span><span style=3D"color:#000000">());</span></p><p style=3D"fon=
t-size:11px;line-height:normal;font-family:Menlo;color:rgb(61,29,129)"><spa=
n style=3D"color:#000000"><br></span></p><p style=3D"font-size:11px;line-he=
ight:normal;font-family:Menlo"><span style=3D"font-family:Arial,Helvetica,s=
ans-serif;font-size:13px">An obvious solution would be add versions that ta=
ke parameter by rvalue reference</span><span style=3D"font-family:Arial,Hel=
vetica,sans-serif;font-size:13px">:</span></p><p style=3D"font-size:11px;li=
ne-height:normal;font-family:Menlo"><span style=3D"font-family:Arial,Helvet=
ica,sans-serif;font-size:13px"><br></span></p><p style=3D"font-size:11px;li=
ne-height:normal;font-family:Menlo"><span style=3D"color:#bb2ca2">template<=
/span><span>&lt;</span><span style=3D"color:#bb2ca2">class</span><span> T, =
</span><span style=3D"color:#bb2ca2">class</span><span> U&gt; </span><span =
style=3D"color:#703daa">std</span><span>::</span><span style=3D"color:#703d=
aa">shared_ptr</span><span>&lt;T&gt; static_pointer_cast(</span><span style=
=3D"color:#bb2ca2">const</span><span> </span><span style=3D"color:#703daa">=
std</span><span>::</span><span style=3D"color:#703daa">shared_ptr</span><sp=
an>&lt;U&gt;&amp; r);=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#0084=
00">// since C++11</span></p><p style=3D"font-size:11px;line-height:normal;=
font-family:Menlo"><span style=3D"color:#bb2ca2">template</span><span>&lt;<=
/span><span style=3D"color:#bb2ca2">class</span><span> T, </span><span styl=
e=3D"color:#bb2ca2">class</span><span> U&gt; </span><span style=3D"color:#7=
03daa">std</span><span>::</span><span style=3D"color:#703daa">shared_ptr</s=
pan><span>&lt;T&gt; dynamic_pointer_cast(</span><span style=3D"color:#bb2ca=
2">const</span><span> </span><span style=3D"color:#703daa">std</span><span>=
::</span><span style=3D"color:#703daa">shared_ptr</span><span>&lt;U&gt;&amp=
; r); =C2=A0 =C2=A0 </span><span style=3D"color:#008400">// since C++11</sp=
an></p><p style=3D"font-size:11px;line-height:normal;font-family:Menlo"><sp=
an style=3D"color:#bb2ca2">template</span><span>&lt;</span><span style=3D"c=
olor:#bb2ca2">class</span><span> T, </span><span style=3D"color:#bb2ca2">cl=
ass</span><span> U&gt; </span><span style=3D"color:#703daa">std</span><span=
>::</span><span style=3D"color:#703daa">shared_ptr</span><span>&lt;T&gt; co=
nst_pointer_cast(</span><span style=3D"color:#bb2ca2">const</span><span> </=
span><span style=3D"color:#703daa">std</span><span>::</span><span style=3D"=
color:#703daa">shared_ptr</span><span>&lt;U&gt;&amp; r); =C2=A0 =C2=A0 =C2=
=A0 </span><span style=3D"color:#008400">// since C++11</span></p><p style=
=3D"font-size:11px;line-height:normal;font-family:Menlo"><span style=3D"col=
or:#bb2ca2">template</span><span>&lt;</span><span style=3D"color:#bb2ca2">c=
lass</span><span> T, </span><span style=3D"color:#bb2ca2">class</span><span=
> U&gt; </span><span style=3D"color:#703daa">std</span><span>::</span><span=
 style=3D"color:#703daa">shared_ptr</span><span>&lt;T&gt; reinterpret_point=
er_cast(</span><span style=3D"color:#bb2ca2">const</span><span> </span><spa=
n style=3D"color:#703daa">std</span><span>::</span><span style=3D"color:#70=
3daa">shared_ptr</span><span>&lt;U&gt;&amp; r); </span><span style=3D"color=
:#008400">// since C++17</span></p><p style=3D"font-size:11px;line-height:n=
ormal;font-family:Menlo;min-height:13px"><span></span><br></p><p style=3D"f=
ont-size:11px;line-height:normal;font-family:Menlo"><span style=3D"color:#b=
b2ca2">template</span><span>&lt;</span><span style=3D"color:#bb2ca2">class<=
/span><span> T, </span><span style=3D"color:#bb2ca2">class</span><span> U&g=
t; </span><span style=3D"color:#703daa">std</span><span>::</span><span styl=
e=3D"color:#703daa">shared_ptr</span><span>&lt;T&gt; static_pointer_cast(</=
span><span style=3D"color:#703daa">std</span><span>::</span><span style=3D"=
color:#703daa">share<wbr>d_ptr</span><span>&lt;U&gt;&amp;&amp; r); =C2=A0 =
=C2=A0 =C2=A0</span><span style=3D"color:#008400">// proposed addition</spa=
n></p><p style=3D"font-size:11px;line-height:normal;font-family:Menlo"><spa=
n style=3D"color:#bb2ca2">template</span><span>&lt;</span><span style=3D"co=
lor:#bb2ca2">class</span><span> T, </span><span style=3D"color:#bb2ca2">cla=
ss</span><span> U&gt; </span><span style=3D"color:#703daa">std</span><span>=
::</span><span style=3D"color:#703daa">shared_ptr</span><span>&lt;T&gt; dyn=
amic_pointer_cast(</span><span style=3D"color:#703daa">std</span><span>::</=
span><span style=3D"color:#703daa">shar<wbr>ed_ptr</span><span>&lt;U&gt;&am=
p;&amp; r);=C2=A0 =C2=A0 =C2=A0</span><span style=3D"color:#008400">// prop=
osed addition</span></p><p style=3D"font-size:11px;line-height:normal;font-=
family:Menlo"><span style=3D"color:#bb2ca2">template</span><span>&lt;</span=
><span style=3D"color:#bb2ca2">class</span><span> T, </span><span style=3D"=
color:#bb2ca2">class</span><span> U&gt; </span><span style=3D"color:#703daa=
">std</span><span>::</span><span style=3D"color:#703daa">shared_ptr</span><=
span>&lt;T&gt; const_pointer_cast(</span><span style=3D"color:#703daa">std<=
/span><span>::</span><span style=3D"color:#703daa">shared<wbr>_ptr</span><s=
pan>&lt;U&gt;&amp;&amp; r);=C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D=
"color:#008400">// proposed addition</span></p><p style=3D"font-size:11px;l=
ine-height:normal;font-family:Menlo;color:rgb(187,44,162)">







</p><p style=3D"font-size:11px;line-height:normal;font-family:Menlo"><span =
style=3D"color:#bb2ca2">template</span><span>&lt;</span><span style=3D"colo=
r:#bb2ca2">class</span><span> T, </span><span style=3D"color:#bb2ca2">class=
</span><span> U&gt; </span><span style=3D"color:#703daa">std</span><span>::=
</span><span style=3D"color:#703daa">shared_ptr</span><span>&lt;T&gt; reint=
erpret_pointer_cast(</span><span style=3D"color:#703daa">std</span><span>::=
</span><span style=3D"color:#703daa"><wbr>shared_ptr</span><span>&lt;U&gt;&=
amp;&amp; r);=C2=A0</span><span style=3D"color:#008400">// proposed additio=
n</span></p><p style=3D"font-size:11px;line-height:normal;font-family:Menlo=
"><span style=3D"color:#008400"><br></span></p><p style=3D"font-size:11px;l=
ine-height:normal;font-family:Menlo"><span style=3D"color:#008400"><span st=
yle=3D"color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size=
:13px">Or just have a single version of each function, that takes argument =
by value:</span><br></span></p><p style=3D"font-size:11px;line-height:norma=
l;font-family:Menlo"><span style=3D"color:#008400"><span style=3D"color:rgb=
(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></spa=
n></span></p><p style=3D"font-size:11px;line-height:normal;font-family:Menl=
o"><span style=3D"color:rgb(187,44,162)">template</span><span>&lt;</span><s=
pan style=3D"color:rgb(187,44,162)">class</span><span>=C2=A0T,=C2=A0</span>=
<span style=3D"color:rgb(187,44,162)">class</span><span>=C2=A0U&gt;=C2=A0</=
span><span style=3D"color:rgb(112,61,170)">std</span><span><wbr>::</span><s=
pan style=3D"color:rgb(112,61,170)">shared_ptr</span><span>&lt;T&gt; static=
_pointer_cast(</span><span style=3D"color:rgb(112,61,170)">std</span><span>=
::</span><span style=3D"color:rgb(112,61,170)">share<wbr>d_ptr</span><span>=
&lt;U&gt; r);=C2=A0=C2=A0 =C2=A0 =C2=A0</span><span style=3D"color:rgb(0,13=
2,0)">// proposed replacement</span></p><p style=3D"font-size:11px;line-hei=
ght:normal;font-family:Menlo"><span style=3D"color:rgb(187,44,162)">templat=
e</span><span>&lt;</span><span style=3D"color:rgb(187,44,162)">class</span>=
<span>=C2=A0T,=C2=A0</span><span style=3D"color:rgb(187,44,162)">class</spa=
n><span>=C2=A0U&gt;=C2=A0</span><span style=3D"color:rgb(112,61,170)">std</=
span><span><wbr>::</span><span style=3D"color:rgb(112,61,170)">shared_ptr</=
span><span>&lt;T&gt; dynamic_pointer_cast(</span><span style=3D"color:rgb(1=
12,61,170)">std</span><span>::</span><span style=3D"color:rgb(112,61,170)">=
shar<wbr>ed_ptr</span><span>&lt;U&gt; r);=C2=A0 =C2=A0 =C2=A0</span><span s=
tyle=3D"color:rgb(0,132,0)">// proposed=C2=A0</span><span style=3D"color:rg=
b(0,132,0)">replacement</span></p><p style=3D"font-size:11px;line-height:no=
rmal;font-family:Menlo"><span style=3D"color:rgb(187,44,162)">template</spa=
n><span>&lt;</span><span style=3D"color:rgb(187,44,162)">class</span><span>=
=C2=A0T,=C2=A0</span><span style=3D"color:rgb(187,44,162)">class</span><spa=
n>=C2=A0U&gt;=C2=A0</span><span style=3D"color:rgb(112,61,170)">std</span><=
span><wbr>::</span><span style=3D"color:rgb(112,61,170)">shared_ptr</span><=
span>&lt;T&gt; const_pointer_cast(</span><span style=3D"color:rgb(112,61,17=
0)">std</span><span>::</span><span style=3D"color:rgb(112,61,170)">shared<w=
br>_ptr</span><span>&lt;U&gt; r);=C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span st=
yle=3D"color:rgb(0,132,0)">// proposed=C2=A0</span><span style=3D"color:rgb=
(0,132,0)">replacement</span></p><p style=3D"font-size:11px;line-height:nor=
mal;font-family:Menlo;color:rgb(187,44,162)"></p><p style=3D"font-size:11px=
;line-height:normal;font-family:Menlo"><span style=3D"color:#008400"></span=
></p><p style=3D"font-size:11px;line-height:normal;font-family:Menlo"><span=
 style=3D"color:rgb(187,44,162)">template</span><span>&lt;</span><span styl=
e=3D"color:rgb(187,44,162)">class</span><span>=C2=A0T,=C2=A0</span><span st=
yle=3D"color:rgb(187,44,162)">class</span><span>=C2=A0U&gt;=C2=A0</span><sp=
an style=3D"color:rgb(112,61,170)">std</span><span><wbr>::</span><span styl=
e=3D"color:rgb(112,61,170)">shared_ptr</span><span>&lt;T&gt; reinterpret_po=
inter_cast(</span><span style=3D"color:rgb(112,61,170)">std</span><span>::<=
/span><span style=3D"color:rgb(112,61,170)"><wbr>shared_ptr</span><span>&lt=
;U&gt; r);=C2=A0</span><span style=3D"color:rgb(0,132,0)">// proposed=C2=A0=
</span><span style=3D"color:rgb(0,132,0)">replacement</span></p><p style=3D=
"font-size:11px;line-height:normal;font-family:Menlo"><span style=3D"color:=
rgb(0,132,0)"><br></span></p><p style=3D"line-height:normal">The later make=
s a=C2=A0redundant=C2=A0increment/<wbr>decrement in one case: when doing=C2=
=A0<span style=3D"font-family:Menlo;font-size:11px">dynamic_pointer_cast=C2=
=A0</span>on a l-value and cast fails<span style=3D"font-family:Menlo;font-=
size:11px;color:rgb(0,132,0)"><br></span></p><p style=3D"line-height:normal=
"><br></p><p style=3D"line-height:normal"><br></p></div></div></blockquote>=
</div></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/633216ff-c3df-4d6f-b33f-3457c87c7996%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/633216ff-c3df-4d6f-b33f-3457c87c7996=
%40isocpp.org</a>.<br />

------=_Part_268_874370203.1467370249387--

------=_Part_267_1398178785.1467370249386--

.