Topic: Post-assignment operator


Author: Lingxi Li <lilingxi.cs@gmail.com>
Date: Sat, 14 Nov 2015 09:32:45 -0800 (PST)
Raw View
------=_Part_676_1596912999.1447522365576
Content-Type: multipart/alternative;
 boundary="----=_Part_677_1584800959.1447522365576"

------=_Part_677_1584800959.1447522365576
Content-Type: text/plain; charset=UTF-8

I frequently find code similar to the following:

delete ptr;
ptr = nullptr;
close(fd);
fd = -1;

Why don't we just introduce a post-assignment operator that performs the
assignment
but returns the previous value of the left-hand-side, just like the
post-increment/decrement
operator? Denote such an operator by `.=`, the above code snippet could be
simplied to

delete ptr .= nullptr;
close(fd .= -1);

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

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

<div dir=3D"ltr">I frequently find code similar to the following:<br><br><d=
iv class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); wor=
d-wrap: break-word; background-color: rgb(250, 250, 250);"><code class=3D"p=
rettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">delete</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> ptr</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>ptr </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">nullptr</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>close</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">fd</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br>fd </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: #660;" class=3D"styled-by-pr=
ettify">-</span><span style=3D"color: #066;" class=3D"styled-by-prettify">1=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span></=
div></code></div><br>Why don&#39;t we just introduce a post-assignment oper=
ator that performs the assignment<br>but returns the previous value of the =
left-hand-side, just like the post-increment/decrement<br>operator? Denote =
such an operator by `.=3D`, the above code snippet could be simplied to<br>=
<br><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187=
); word-wrap: break-word; background-color: rgb(250, 250, 250);"><code clas=
s=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;=
" class=3D"styled-by-prettify">delete</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> ptr </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">.=3D</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">nullptr</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>close</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">fd </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">.=3D</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">-</span><span style=3D"color: #066;=
" class=3D"styled-by-prettify">1</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">);</span></div></code></div><br></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_677_1584800959.1447522365576--
------=_Part_676_1596912999.1447522365576--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sat, 14 Nov 2015 09:39:30 -0800 (PST)
Raw View
------=_Part_236_707647325.1447522771090
Content-Type: multipart/alternative;
 boundary="----=_Part_237_1825039045.1447522771090"

------=_Part_237_1825039045.1447522771090
Content-Type: text/plain; charset=UTF-8



On Saturday, November 14, 2015 at 12:32:45 PM UTC-5, Lingxi Li wrote:
>
> I frequently find code similar to the following:
>
> delete ptr;
> ptr = nullptr;
> close(fd);
> fd = -1;
>
>
If you truly "frequently" find yourself doing this, you're not using enough
RAII.

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

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

<br><br>On Saturday, November 14, 2015 at 12:32:45 PM UTC-5, Lingxi Li wrot=
e:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;b=
order-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">I frequentl=
y find code similar to the following:<br><br><div style=3D"border:1px solid=
 rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><=
code><div><span style=3D"color:#008">delete</span><span style=3D"color:#000=
"> ptr</span><span style=3D"color:#660">;</span><span style=3D"color:#000">=
<br>ptr </span><span style=3D"color:#660">=3D</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#008">nullptr</span><span style=3D"color:#=
660">;</span><span style=3D"color:#000"><br>close</span><span style=3D"colo=
r:#660">(</span><span style=3D"color:#000">fd</span><span style=3D"color:#6=
60">);</span><span style=3D"color:#000"><br>fd </span><span style=3D"color:=
#660">=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#66=
0">-</span><span style=3D"color:#066">1</span><span style=3D"color:#660">;<=
/span></div></code></div><br></div></blockquote><div><br>If you truly &quot=
;frequently&quot; find yourself doing this, you&#39;re not using enough RAI=
I.</div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_237_1825039045.1447522771090--
------=_Part_236_707647325.1447522771090--

.


Author: Lingxi Li <lilingxi.cs@gmail.com>
Date: Sat, 14 Nov 2015 09:46:06 -0800 (PST)
Raw View
------=_Part_741_1540903508.1447523167064
Content-Type: multipart/alternative;
 boundary="----=_Part_742_2143210253.1447523167064"

------=_Part_742_2143210253.1447523167064
Content-Type: text/plain; charset=UTF-8

Alas, almost all native operating system API (e.g., POSIX and Windows API)
is provided in C and there
are a bunch of libraries that just don't much use RAII, and I don't bother
doing the tedious work to write
wrappers.

On Sunday, November 15, 2015 at 1:39:31 AM UTC+8, Nicol Bolas wrote:
>
>
>
> On Saturday, November 14, 2015 at 12:32:45 PM UTC-5, Lingxi Li wrote:
>>
>> I frequently find code similar to the following:
>>
>> delete ptr;
>> ptr = nullptr;
>> close(fd);
>> fd = -1;
>>
>>
> If you truly "frequently" find yourself doing this, you're not using
> enough RAII.
>

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

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

<div dir=3D"ltr">Alas, almost all native operating system API (e.g., POSIX =
and Windows API) is provided in C and there<br>are a bunch of libraries tha=
t just don&#39;t much use RAII, and I don&#39;t bother doing the tedious wo=
rk to write<br>wrappers.<br><br>On Sunday, November 15, 2015 at 1:39:31 AM =
UTC+8, Nicol Bolas wrote:<blockquote class=3D"gmail_quote" style=3D"margin:=
 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><br><=
br>On Saturday, November 14, 2015 at 12:32:45 PM UTC-5, Lingxi Li wrote:<bl=
ockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">I frequently find cod=
e similar to the following:<br><br><div style=3D"border:1px solid rgb(187,1=
87,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code><div>=
<span style=3D"color:#008">delete</span><span style=3D"color:#000"> ptr</sp=
an><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>ptr </=
span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#008">nullptr</span><span style=3D"color:#660">;</sp=
an><span style=3D"color:#000"><br>close</span><span style=3D"color:#660">(<=
/span><span style=3D"color:#000">fd</span><span style=3D"color:#660">);</sp=
an><span style=3D"color:#000"><br>fd </span><span style=3D"color:#660">=3D<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#660">-</span=
><span style=3D"color:#066">1</span><span style=3D"color:#660">;</span></di=
v></code></div><br></div></blockquote><div><br>If you truly &quot;frequentl=
y&quot; find yourself doing this, you&#39;re not using enough RAII.</div></=
blockquote></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_742_2143210253.1447523167064--
------=_Part_741_1540903508.1447523167064--

.


Author: Lingxi Li <lilingxi.cs@gmail.com>
Date: Sat, 14 Nov 2015 09:51:54 -0800 (PST)
Raw View
------=_Part_745_467190960.1447523514963
Content-Type: multipart/alternative;
 boundary="----=_Part_746_1671876296.1447523514964"

------=_Part_746_1671876296.1447523514964
Content-Type: text/plain; charset=UTF-8

I have to admit that the `delete ptr;` example is not suitable, cause one
can simply argue the use of an
RAII smart pointer. As a replacement, consider the following case
concerning Windows API:

CloseHandle(handle);
handle = 0;

On Sunday, November 15, 2015 at 1:46:07 AM UTC+8, Lingxi Li wrote:
>
> Alas, almost all native operating system API (e.g., POSIX and Windows API)
> is provided in C and there
> are a bunch of libraries that just don't much use RAII, and I don't bother
> doing the tedious work to write
> wrappers.
>
> On Sunday, November 15, 2015 at 1:39:31 AM UTC+8, Nicol Bolas wrote:
>>
>>
>>
>> On Saturday, November 14, 2015 at 12:32:45 PM UTC-5, Lingxi Li wrote:
>>>
>>> I frequently find code similar to the following:
>>>
>>> delete ptr;
>>> ptr = nullptr;
>>> close(fd);
>>> fd = -1;
>>>
>>>
>> If you truly "frequently" find yourself doing this, you're not using
>> enough RAII.
>>
>

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

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

<div dir=3D"ltr">I have to admit that the `delete ptr;` example is not suit=
able, cause one can simply argue the use of an<br>RAII smart pointer. As a =
replacement, consider the following case concerning Windows API:<br><br><di=
v class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word=
-wrap: break-word; background-color: rgb(250, 250, 250);"><code class=3D"pr=
ettyprint"><div class=3D"subprettyprint"><span style=3D"color: #606;" class=
=3D"styled-by-prettify">CloseHandle</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">handle</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br>handle </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #066;" class=3D"styled-by-prettify">0</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">;</span></div></code=
></div><br>On Sunday, November 15, 2015 at 1:46:07 AM UTC+8, Lingxi Li wrot=
e:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;b=
order-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Alas, almos=
t all native operating system API (e.g., POSIX and Windows API) is provided=
 in C and there<br>are a bunch of libraries that just don&#39;t much use RA=
II, and I don&#39;t bother doing the tedious work to write<br>wrappers.<br>=
<br>On Sunday, November 15, 2015 at 1:39:31 AM UTC+8, Nicol Bolas wrote:<bl=
ockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><br><br>On Saturday, November 14, 2015=
 at 12:32:45 PM UTC-5, Lingxi Li wrote:<blockquote class=3D"gmail_quote" st=
yle=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1=
ex"><div dir=3D"ltr">I frequently find code similar to the following:<br><b=
r><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;back=
ground-color:rgb(250,250,250)"><code><div><span style=3D"color:#008">delete=
</span><span style=3D"color:#000"> ptr</span><span style=3D"color:#660">;</=
span><span style=3D"color:#000"><br>ptr </span><span style=3D"color:#660">=
=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#008">nul=
lptr</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><b=
r>close</span><span style=3D"color:#660">(</span><span style=3D"color:#000"=
>fd</span><span style=3D"color:#660">);</span><span style=3D"color:#000"><b=
r>fd </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"=
> </span><span style=3D"color:#660">-</span><span style=3D"color:#066">1</s=
pan><span style=3D"color:#660">;</span></div></code></div><br></div></block=
quote><div><br>If you truly &quot;frequently&quot; find yourself doing this=
, you&#39;re not using enough RAII.</div></blockquote></div></blockquote></=
div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_746_1671876296.1447523514964--
------=_Part_745_467190960.1447523514963--

.


Author: =?UTF-8?Q?Daniel_Kr=C3=BCgler?= <daniel.kruegler@gmail.com>
Date: Sat, 14 Nov 2015 18:56:44 +0100
Raw View
2015-11-14 18:51 GMT+01:00 Lingxi Li <lilingxi.cs@gmail.com>:
> I have to admit that the `delete ptr;` example is not suitable, cause one
> can simply argue the use of an
> RAII smart pointer. As a replacement, consider the following case concerning
> Windows API:
>
> CloseHandle(handle);
> handle = 0;

Given your actual use cases, I'm wondering why you are not starting
with a request to extend the C standard in this regard?

- Daniel

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: Lingxi Li <lilingxi.cs@gmail.com>
Date: Sat, 14 Nov 2015 10:05:55 -0800 (PST)
Raw View
------=_Part_753_1941622502.1447524355855
Content-Type: multipart/alternative;
 boundary="----=_Part_754_405285636.1447524355856"

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

I've thought about it. There seems to be little information as to how to=20
propose to the C standard, nor is
there any ISO C Standard discussion group similar to this one. Any=20
suggestions?

On Sunday, November 15, 2015 at 1:56:46 AM UTC+8, Daniel Kr=C3=BCgler wrote=
:
>
> 2015-11-14 18:51 GMT+01:00 Lingxi Li <lilin...@gmail.com <javascript:>>:=
=20
> > I have to admit that the `delete ptr;` example is not suitable, cause=
=20
> one=20
> > can simply argue the use of an=20
> > RAII smart pointer. As a replacement, consider the following case=20
> concerning=20
> > Windows API:=20
> >=20
> > CloseHandle(handle);=20
> > handle =3D 0;=20
>
> Given your actual use cases, I'm wondering why you are not starting=20
> with a request to extend the C standard in this regard?=20
>
> - Daniel=20
>

--=20

---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

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

<div dir=3D"ltr">I&#39;ve thought about it. There seems to be little inform=
ation as to how to propose to the C standard, nor is<br>there any ISO C Sta=
ndard discussion group similar to this one. Any suggestions?<br><br>On Sund=
ay, November 15, 2015 at 1:56:46 AM UTC+8, Daniel Kr=C3=BCgler wrote:<block=
quote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-le=
ft: 1px #ccc solid;padding-left: 1ex;">2015-11-14 18:51 GMT+01:00 Lingxi Li=
 &lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"okg=
7oUJ1AwAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#39=
;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;">=
lilin...@gmail.com</a>&gt;:
<br>&gt; I have to admit that the `delete ptr;` example is not suitable, ca=
use one
<br>&gt; can simply argue the use of an
<br>&gt; RAII smart pointer. As a replacement, consider the following case =
concerning
<br>&gt; Windows API:
<br>&gt;
<br>&gt; CloseHandle(handle);
<br>&gt; handle =3D 0;
<br>
<br>Given your actual use cases, I&#39;m wondering why you are not starting
<br>with a request to extend the C standard in this regard?
<br>
<br>- Daniel
<br></blockquote></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_754_405285636.1447524355856--
------=_Part_753_1941622502.1447524355855--

.


Author: "'Jeffrey Yasskin' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Sat, 14 Nov 2015 10:07:13 -0800
Raw View
--089e01183eecccb8270524840bbf
Content-Type: text/plain; charset=UTF-8

Check out std::exchange().
On Nov 14, 2015 9:32 AM, "Lingxi Li" <lilingxi.cs@gmail.com> wrote:

> I frequently find code similar to the following:
>
> delete ptr;
> ptr = nullptr;
> close(fd);
> fd = -1;
>
> Why don't we just introduce a post-assignment operator that performs the
> assignment
> but returns the previous value of the left-hand-side, just like the
> post-increment/decrement
> operator? Denote such an operator by `.=`, the above code snippet could be
> simplied to
>
> delete ptr .= nullptr;
> close(fd .= -1);
>
> --
>
> ---
> 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.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

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

<p dir=3D"ltr">Check out std::exchange().</p>
<div class=3D"gmail_quote">On Nov 14, 2015 9:32 AM, &quot;Lingxi Li&quot; &=
lt;<a href=3D"mailto:lilingxi.cs@gmail.com">lilingxi.cs@gmail.com</a>&gt; w=
rote:<br type=3D"attribution"><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"lt=
r">I frequently find code similar to the following:<br><br><div style=3D"bo=
rder:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(2=
50,250,250)"><code><div><span style=3D"color:#008">delete</span><span style=
=3D"color:#000"> ptr</span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"><br>ptr </span><span style=3D"color:#660">=3D</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#008">nullptr</span><span =
style=3D"color:#660">;</span><span style=3D"color:#000"><br>close</span><sp=
an style=3D"color:#660">(</span><span style=3D"color:#000">fd</span><span s=
tyle=3D"color:#660">);</span><span style=3D"color:#000"><br>fd </span><span=
 style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">-</span><span style=3D"color:#066">1</span><span style=
=3D"color:#660">;</span></div></code></div><br>Why don&#39;t we just introd=
uce a post-assignment operator that performs the assignment<br>but returns =
the previous value of the left-hand-side, just like the post-increment/decr=
ement<br>operator? Denote such an operator by `.=3D`, the above code snippe=
t could be simplied to<br><br><div style=3D"border:1px solid rgb(187,187,18=
7);word-wrap:break-word;background-color:rgb(250,250,250)"><code><div><span=
 style=3D"color:#008">delete</span><span style=3D"color:#000"> ptr </span><=
span style=3D"color:#660">.=3D</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#008">nullptr</span><span style=3D"color:#660">;</span><s=
pan style=3D"color:#000"><br>close</span><span style=3D"color:#660">(</span=
><span style=3D"color:#000">fd </span><span style=3D"color:#660">.=3D</span=
><span style=3D"color:#000"> </span><span style=3D"color:#660">-</span><spa=
n style=3D"color:#066">1</span><span style=3D"color:#660">);</span></div></=
code></div><br></div>

<p></p>

-- <br>
<br>
--- <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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</blockquote></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--089e01183eecccb8270524840bbf--

.


Author: Lingxi Li <lilingxi.cs@gmail.com>
Date: Sat, 14 Nov 2015 10:16:11 -0800 (PST)
Raw View
------=_Part_676_1162193704.1447524971092
Content-Type: multipart/alternative;
 boundary="----=_Part_677_804193311.1447524971093"

------=_Part_677_804193311.1447524971093
Content-Type: text/plain; charset=UTF-8

I didn't know about this thing yet. But, yes, this will do it, though as a
library feature. Thanks :)

On Sunday, November 15, 2015 at 2:07:17 AM UTC+8, Jeffrey Yasskin wrote:
>
> Check out std::exchange().
> On Nov 14, 2015 9:32 AM, "Lingxi Li" <lilin...@gmail.com <javascript:>>
> wrote:
>
>> I frequently find code similar to the following:
>>
>> delete ptr;
>> ptr = nullptr;
>> close(fd);
>> fd = -1;
>>
>> Why don't we just introduce a post-assignment operator that performs the
>> assignment
>> but returns the previous value of the left-hand-side, just like the
>> post-increment/decrement
>> operator? Denote such an operator by `.=`, the above code snippet could
>> be simplied to
>>
>> delete ptr .= nullptr;
>> close(fd .= -1);
>>
>> --
>>
>> ---
>> 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-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> Visit this group at
>> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>>
>

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

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

<div dir=3D"ltr">I didn&#39;t know about this thing yet. But, yes, this wil=
l do it, though as a library feature. Thanks :)<br><br>On Sunday, November =
15, 2015 at 2:07:17 AM UTC+8, Jeffrey Yasskin wrote:<blockquote class=3D"gm=
ail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc soli=
d;padding-left: 1ex;"><p dir=3D"ltr">Check out std::exchange().</p>
<div class=3D"gmail_quote">On Nov 14, 2015 9:32 AM, &quot;Lingxi Li&quot; &=
lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"BfURn=
9V1AwAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;=
return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;">li=
lin...@gmail.com</a>&gt; wrote:<br type=3D"attribution"><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex"><div dir=3D"ltr">I frequently find code similar to the follow=
ing:<br><br><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break=
-word;background-color:rgb(250,250,250)"><code><div><span style=3D"color:#0=
08">delete</span><span style=3D"color:#000"> ptr</span><span style=3D"color=
:#660">;</span><span style=3D"color:#000"><br>ptr </span><span style=3D"col=
or:#660">=3D</span><span style=3D"color:#000"> </span><span style=3D"color:=
#008">nullptr</span><span style=3D"color:#660">;</span><span style=3D"color=
:#000"><br>close</span><span style=3D"color:#660">(</span><span style=3D"co=
lor:#000">fd</span><span style=3D"color:#660">);</span><span style=3D"color=
:#000"><br>fd </span><span style=3D"color:#660">=3D</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#660">-</span><span style=3D"color:#=
066">1</span><span style=3D"color:#660">;</span></div></code></div><br>Why =
don&#39;t we just introduce a post-assignment operator that performs the as=
signment<br>but returns the previous value of the left-hand-side, just like=
 the post-increment/decrement<br>operator? Denote such an operator by `.=3D=
`, the above code snippet could be simplied to<br><br><div style=3D"border:=
1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,25=
0,250)"><code><div><span style=3D"color:#008">delete</span><span style=3D"c=
olor:#000"> ptr </span><span style=3D"color:#660">.=3D</span><span style=3D=
"color:#000"> </span><span style=3D"color:#008">nullptr</span><span style=
=3D"color:#660">;</span><span style=3D"color:#000"><br>close</span><span st=
yle=3D"color:#660">(</span><span style=3D"color:#000">fd </span><span style=
=3D"color:#660">.=3D</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">-</span><span style=3D"color:#066">1</span><span style=3D"c=
olor:#660">);</span></div></code></div><br></div>

<p></p>

-- <br>
<br>
--- <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"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
BfURn9V1AwAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&=
#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"BfURn9V1AwAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D&#39;javascript:&#39;;return true;" onclick=3D"this.href=3D&#39=
;javascript:&#39;;return true;">std-pr...@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=
=3D&#39;http://groups.google.com/a/isocpp.org/group/std-proposals/&#39;;ret=
urn true;" onclick=3D"this.href=3D&#39;http://groups.google.com/a/isocpp.or=
g/group/std-proposals/&#39;;return true;">http://groups.google.com/a/<wbr>i=
socpp.org/group/std-<wbr>proposals/</a>.<br>
</blockquote></div>
</blockquote></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_677_804193311.1447524971093--
------=_Part_676_1162193704.1447524971092--

.