220 26368 <b45ad971-0874-4372-b204-699767d25c21@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: FrankHB1989 <frankhb1989@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Swapping with volatile lvalues
Date: Tue, 21 Jun 2016 16:33:54 -0700 (PDT)
Lines: 234
Approved: news@gmane.org
Message-ID: <b45ad971-0874-4372-b204-699767d25c21@isocpp.org>
References: <81998cb5-722e-49a1-be98-7ca1e219b72a@isocpp.org>
 <CAGNvRgB9K2W=AL5y3b7PbVvitDAaTOLXSYzi9rbC2kpZVG+ZKQ@mail.gmail.com>
 <9608d5c4-e60f-449e-9078-f27fed1f79fd@isocpp.org> <CAGNvRgCYLywvtFSO65-NKpeycpT4cPnw0SjvQPhE_DRL98UO7g@mail.gmail.com>
 <CALDL7dFth8B=XvDL4pAb_jy=QAKJ_J6VWs-8vMxnmsOxz=R-DA@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_104_2136466998.1466552034679"
X-Trace: ger.gmane.org 1466552052 14910 80.91.229.3 (21 Jun 2016 23:34:12 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 21 Jun 2016 23:34:12 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCTJVBPG3QIBBY45U65QKGQET5P5CRY@isocpp.org Wed Jun 22 01:34:04 2016
Return-path: <std-proposals+bncBCTJVBPG3QIBBY45U65QKGQET5P5CRY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qk0-f197.google.com ([209.85.220.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCTJVBPG3QIBBY45U65QKGQET5P5CRY@isocpp.org>)
	id 1bFVBC-0005GP-Qg
	for gclcip-std-proposals@m.gmane.org; Wed, 22 Jun 2016 01:34:03 +0200
Original-Received: by mail-qk0-f197.google.com with SMTP id z142sf86152948qkb.0
        for <gclcip-std-proposals@m.gmane.org>; Tue, 21 Jun 2016 16:33:57 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=Cmif/cWs/U1X65jQIQmJoLbhTPdZeJFmpTpF2qZBdqo=;
        b=K92LT5e3pHA19UKX/3Q2FnNP2YPfuZo10m4HshuDtsal8ZVoMRxvDGpCAPOuvn4Svp
         6ZHHy65ht7n1vfBMkVhUEUVJ7AXg+Pp4oDDYEvzHSUTS59D2teBODKzNHjEG3NzKNaSt
         5xMDCeUUhaMSN97ZtFMUug/05xGRAi4/3evaymS6+Wd7cwKNs0NrdNY75u5VHWDY/+N9
         KWnzA7x6nWlkrvCZ+hO2CuS/a7QlNrWr1N+egnBcBzcI83Q096gJ39/k2IifSpYUVCA5
         kjaMfbdStSrgB34WYVRtp8oeYkICjEio1LASdFZ6f3VpYK9WHjYEjKn0V4bfOtFmA8y/
         F7MA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=Cmif/cWs/U1X65jQIQmJoLbhTPdZeJFmpTpF2qZBdqo=;
        b=ajj3vKlgiXk0z54OkWQML024uQTSwcluNNwQltPRN8zYTBW0yq1sh9zpo1MqRBhILO
         YfUA69q5hKPp5hg/6fSi1b2z6an1LJUXj3ufeluYyvg5ea3GAhO4klPGlG/oHBUXMoY9
         y/ZCQFHBtbEDTCB/8yTI2KJGCZBkWl5R6OC1FhpdZBi6PWJ6RRcq3NntyHf1y4NXF/OJ
         faH2eH2TTVarL6JUgPXkZfPe1dn7aY5chMj4dBYrJeYKKO+si4KFJ9wnRyq1Bl63ruwK
         srL7kUBxRpw98iu8XWpqm6hqPvtN2ZdxhiPTaERN0wInVKJMaWc5/Q8L1qUtCxH9iSee
         p5Pw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=Cmif/cWs/U1X65jQIQmJoLbhTPdZeJFmpTpF2qZBdqo=;
        b=d75pzYcwVGRcY2KkzCUVebmu83PEZOR91wTbnsQqzh36DqmtK/oryerPhyxdGAd+2U
         0JvcmDaxommuPMsXF7KObVe46Sm9AIuYGtG2rgtlONQj78hkFX0lgL4Idr10wUxI6dLP
         pgnXbUwXp6+49kYjEb9j/znxB7uFNtlNZp+aPYI4IjVPlScV6XJzT4mSCTFG/7SY2/68
         aRIgdCQLu9ILCJ8G2rkfQO22x3BhSrrrGaRAMdnKiJYDt+b4UX232YDPO9xnzQAZ40Wu
         jAeauk+HvUNs2RHj/XHMuZGggSu2ziw8ndLc6kztWuzFUx5JDUNR+JS4uc36GOqQE7GU
         S5MA==
X-Gm-Message-State: ALyK8tISGtmqVdkzGaXcs0kfpG/kCpJBwpdeGdmCVjfoEpcwzi2+RYo4sYh5rOuzWVEiKQ==
X-Received: by 10.129.112.131 with SMTP id l125mr29858260ywc.5.1466552036885;
        Tue, 21 Jun 2016 16:33:56 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.174.7 with SMTP id x7ls2596445ioe.53.gmail; Tue, 21 Jun
 2016 16:33:55 -0700 (PDT)
X-Received: by 10.36.196.5 with SMTP id v5mr244123itf.4.1466552035706;
        Tue, 21 Jun 2016 16:33:55 -0700 (PDT)
In-Reply-To: <CALDL7dFth8B=XvDL4pAb_jy=QAKJ_J6VWs-8vMxnmsOxz=R-DA@mail.gmail.com>
X-Original-Sender: frankhb1989@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:26368
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/26368>

------=_Part_104_2136466998.1466552034679
Content-Type: multipart/alternative; 
	boundary="----=_Part_105_1551560846.1466552034680"

------=_Part_105_1551560846.1466552034680
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



=E5=9C=A8 2016=E5=B9=B46=E6=9C=8822=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=89 UTC=
+8=E4=B8=8A=E5=8D=882:37:36=EF=BC=8CFarid Mehrabi=E5=86=99=E9=81=93=EF=BC=
=9A
>
> Whenever I face volatile, the atomic bells start to ring in my ears.=20
> Should swapping a volatile object mean atomic exchange, for non-trivial=
=20
> types we might get in trouble, but for in-built integrals I would rather=
=20
> use std::atomic_exchange.
>
Well, atomic operations are another monsters... Actually I don't want=20
"volatile" as possible.
=20

> Otherwise (if atomicity is not a concern), a cv-cast followed by=20
> conventional swap can do.
>
> I'm afraid you can't. "Reading a volatile object through a non-volatile=
=20
glvalue has undefined behavior." I find no effect way to avoid a volatile=
=20
glvalue referring a volatile object.

=20

> regards,
> FM.
>
> 2016-06-21 14:48 GMT+04:30 Daniel Kr=C3=BCgler <daniel....@gmail.com=20
> <javascript:>>:
>
>> 2016-06-21 12:12 GMT+02:00 FrankHB1989 <frank...@gmail.com <javascript:>
>> >:
>> > Call of std::exchange can work, but it seems not so ideal.
>>
>> This is a misunderstanding of my possibly ambiguous response. I didn't
>> mean to use std::exchange, but instead I was trying to suggest that if
>> you were considering to reuse an existing name it should better be
>> exchange instead of swap.
>>
>> > The return type
>> > of std::exchange is template parameter type T, so when T is a volatile=
=20
>> type,
>> > lvalue-to-rvalue conversion would be performed, and there are likely=
=20
>> more
>> > side effects than needed.
>> > I also don't think using the volatile lvalue return value (which is no=
t=20
>> the
>> > case for std::exchange) a good idea. Discarded-value expressions can=
=20
>> work in
>> > such cases, but is seems to be strange and too error-prone. So perhaps=
=20
>> the
>> > return type of the call should be void.
>> > Regarding with Swappable requriements and symmetry... how about=20
>> providing 2
>> > overloading?
>>
>> I still feel uneasy about it, especially when trying to make a
>> consistent sense with your suggested overloads (even assuming that
>> both overloads would be provided) and the Swappable post-conditions.
>> But again, I haven't thought carefully through it.
>>
>> - Daniel
>>
>> --
>> You received this message because you are subscribed to the Google Group=
s=20
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n=20
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit=20
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAGNvRgCYLy=
wvtFSO65-NKpeycpT4cPnw0SjvQPhE_DRL98UO7g%40mail.gmail.com
>> .
>>
>
>
>
> --=20
> how am I supposed to end the twisted road of  your hair in such a dark=20
> night??
> unless the candle of your face does shed some light upon my way!!!
>

--=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/b45ad971-0874-4372-b204-699767d25c21%40isocpp.or=
g.

------=_Part_105_1551560846.1466552034680
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>=E5=9C=A8 2016=E5=B9=B46=E6=9C=8822=E6=97=A5=E6=98=
=9F=E6=9C=9F=E4=B8=89 UTC+8=E4=B8=8A=E5=8D=882:37:36=EF=BC=8CFarid Mehrabi=
=E5=86=99=E9=81=93=EF=BC=9A<blockquote class=3D"gmail_quote" style=3D"margi=
n: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><di=
v dir=3D"rtl"><div style=3D"font-family:&quot;arial narrow&quot;,sans-serif=
;font-size:large" dir=3D"ltr">Whenever I face volatile, the atomic bells st=
art to ring in my ears. Should swapping a volatile object mean atomic excha=
nge, for non-trivial types we might get in trouble, but for in-built integr=
als I would rather use std::atomic_exchange.</div></div></blockquote><div>W=
ell, atomic operations are another monsters... Actually I don&#39;t want &q=
uot;volatile&quot; as possible.<br>=C2=A0<br></div><blockquote class=3D"gma=
il_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid=
;padding-left: 1ex;"><div dir=3D"rtl"><div style=3D"font-family:&quot;arial=
 narrow&quot;,sans-serif;font-size:large" dir=3D"ltr">Otherwise (if atomici=
ty is not a concern), a cv-cast followed by conventional swap can do.</div>=
<div style=3D"font-family:&quot;arial narrow&quot;,sans-serif;font-size:lar=
ge" dir=3D"ltr"><br></div></div></blockquote><div>I&#39;m afraid you can&#3=
9;t. &quot;Reading a volatile object through a non-volatile glvalue has und=
efined behavior.&quot; I find no effect way to avoid a volatile glvalue ref=
erring a volatile object.<br><br>=C2=A0<br></div><blockquote class=3D"gmail=
_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;p=
adding-left: 1ex;"><div dir=3D"rtl"><div style=3D"font-family:&quot;arial n=
arrow&quot;,sans-serif;font-size:large" dir=3D"ltr"></div><div style=3D"fon=
t-family:&quot;arial narrow&quot;,sans-serif;font-size:large" dir=3D"ltr">r=
egards,</div><div style=3D"font-family:&quot;arial narrow&quot;,sans-serif;=
font-size:large" dir=3D"ltr">FM.</div></div><div><br><div class=3D"gmail_qu=
ote"><div dir=3D"ltr">2016-06-21 14:48 GMT+04:30 Daniel Kr=C3=BCgler <span =
dir=3D"ltr">&lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-ma=
ilto=3D"ko2dHxJHBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;java=
script:&#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;ret=
urn true;">daniel....@gmail.com</a>&gt;</span>:</div><blockquote class=3D"g=
mail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-l=
eft:1ex"><span>2016-06-21 12:12 GMT+02:00 FrankHB1989 &lt;<a href=3D"javasc=
ript:" target=3D"_blank" gdf-obfuscated-mailto=3D"ko2dHxJHBAAJ" rel=3D"nofo=
llow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;return true;" onclic=
k=3D"this.href=3D&#39;javascript:&#39;;return true;">frank...@gmail.com</a>=
&gt;:<br>
&gt; Call of std::exchange can work, but it seems not so ideal.<br>
<br>
</span>This is a misunderstanding of my possibly ambiguous response. I didn=
&#39;t<br>
mean to use std::exchange, but instead I was trying to suggest that if<br>
you were considering to reuse an existing name it should better be<br>
exchange instead of swap.<br>
<span><br>
&gt; The return type<br>
&gt; of std::exchange is template parameter type T, so when T is a volatile=
 type,<br>
&gt; lvalue-to-rvalue conversion would be performed, and there are likely m=
ore<br>
&gt; side effects than needed.<br>
&gt; I also don&#39;t think using the volatile lvalue return value (which i=
s not the<br>
&gt; case for std::exchange) a good idea. Discarded-value expressions can w=
ork in<br>
&gt; such cases, but is seems to be strange and too error-prone. So perhaps=
 the<br>
&gt; return type of the call should be void.<br>
&gt; Regarding with Swappable requriements and symmetry... how about provid=
ing 2<br>
&gt; overloading?<br>
<br>
</span>I still feel uneasy about it, especially when trying to make a<br>
consistent sense with your suggested overloads (even assuming that<br>
both overloads would be provided) and the Swappable post-conditions.<br>
But again, I haven&#39;t thought carefully through it.<br>
<span><br>
- Daniel<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"=
ko2dHxJHBAAJ" 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"ko2dHxJHBAAJ" 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>
</span>To view this discussion on the web visit <a href=3D"https://groups.g=
oogle.com/a/isocpp.org/d/msgid/std-proposals/CAGNvRgCYLywvtFSO65-NKpeycpT4c=
Pnw0SjvQPhE_DRL98UO7g%40mail.gmail.com" rel=3D"nofollow" target=3D"_blank" =
onmousedown=3D"this.href=3D&#39;https://groups.google.com/a/isocpp.org/d/ms=
gid/std-proposals/CAGNvRgCYLywvtFSO65-NKpeycpT4cPnw0SjvQPhE_DRL98UO7g%40mai=
l.gmail.com&#39;;return true;" onclick=3D"this.href=3D&#39;https://groups.g=
oogle.com/a/isocpp.org/d/msgid/std-proposals/CAGNvRgCYLywvtFSO65-NKpeycpT4c=
Pnw0SjvQPhE_DRL98UO7g%40mail.gmail.com&#39;;return true;">https://groups.go=
ogle.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/CAGNvRgCYLywvtFSO65-<=
wbr>NKpeycpT4cPnw0SjvQPhE_<wbr>DRL98UO7g%40mail.gmail.com</a>.<br>
</blockquote></div><br><br clear=3D"all"><div><br></div>-- <br><div><div di=
r=3D"rtl"><div><div dir=3D"ltr">how am I supposed to end the twisted road o=
f=C2=A0 your hair in such a dark night??<br>unless the candle of your face =
does shed some light upon my way!!!<br></div></div></div></div>
</div>
</blockquote></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/b45ad971-0874-4372-b204-699767d25c21%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/b45ad971-0874-4372-b204-699767d25c21=
%40isocpp.org</a>.<br />

------=_Part_105_1551560846.1466552034680--

------=_Part_104_2136466998.1466552034679--

.
