220 32270 <dbbdbc10-3f83-48ea-9a78-beb179bd113a@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Solving the std::swap embarrassment*?
Date: Tue, 2 May 2017 15:09:06 -0700 (PDT)
Lines: 201
Approved: news@gmane.org
Message-ID: <dbbdbc10-3f83-48ea-9a78-beb179bd113a@isocpp.org>
References: <201705022023.38635.marc.mutz@kdab.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_2521_1187088980.1493762946388"
X-Trace: blaine.gmane.org 1493762949 30027 195.159.176.226 (2 May 2017 22:09:09 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 2 May 2017 22:09:09 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBA4HUTEAKGQEBZLVWFQ@isocpp.org Wed May 03 00:09:04 2017
Return-path: <std-proposals+bncBCEKFTV6ZUMBBA4HUTEAKGQEBZLVWFQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw0-f200.google.com ([209.85.161.200])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBA4HUTEAKGQEBZLVWFQ@isocpp.org>)
	id 1d5fyg-0007fL-Mk
	for gclcip-std-proposals@m.gmane.org; Wed, 03 May 2017 00:09:02 +0200
Original-Received: by mail-yw0-f200.google.com with SMTP id 17sf57655167ywk.7
        for <gclcip-std-proposals@m.gmane.org>; Tue, 02 May 2017 15:09:08 -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=3uCiVGnowF5CIm4kfqf95Ho93nIvOMAmstA7idaDusw=;
        b=EWoPiOnWSUERs/sdImxWAD3uCG93nwCXBjxAhY+4uTsdaqf1rnPbCZU/zcgaIpseWc
         ceV1Iw49Nuu7YMUkSvj9fiI3/KtHiQ4vsciMwYmJhISEMrfIwqTzBlUxNTXfHUlC6svx
         Zw58aGHzKErkZBhgOBRe3xRPMyTGb2x2z0i+pz/d+3bDlJbN6h/Y0F1DvUraeqJuxn3F
         YJwVsYIdyKbXDM53Rv02Yv6WpkEKOw+tBr4rykn4n9+CsgadRdF3z/2aDK9g+jvlw/dJ
         Gbukj1ig0tog2658jAboHom24EdxFeUov1t4N7kZhjQjW1405rWLXq1DcPnvon4WUAbC
         7lyQ==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        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=3uCiVGnowF5CIm4kfqf95Ho93nIvOMAmstA7idaDusw=;
        b=s4i75PqjOYtcbb+c/1SModfaAsq8rnkqa9bAPFONKZA7gZBmyQ83YSwuk8/s0/t4wD
         SDZDNx6BPl1yT43llfrlrnZIK3ueOWiylNAf2T8r3p/92uLD+vwnbXvkAiwcNhUtuTME
         4Or1J3y8SQrmJn3Mj2dEx6qwBDpqbmM39c/OWoOG+hzIBn8CAuoHgzGZdE/f9ilFC9/o
         DSlzgSkkcXTFWpznO76SwUvk2dZgn7EknoqZLGUPq8CvjRacboCc/odS7eymHywS32KT
         2Jqxh+PM7UGcUpSjsL5wka+xHWibr6z9FGA9aRsG6wbabGyRZ4FuqOBar4mbhug9Gd5I
         Opqg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        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=3uCiVGnowF5CIm4kfqf95Ho93nIvOMAmstA7idaDusw=;
        b=KOjwQPqCEbuIjrgbGrtG06lQAup0f+NH+NDAj2KHvONXric5GBJ81LBN3uy4lROnmJ
         wRTbPk23h4uDeNdLaj78CkKvf3Rfkf6F4b4npS8YMKwkR3p5i2rmg2WHhBB40HbFILNl
         NExWZbarrPpvL+wBVSLJJ2sFC7TAjqDQ6xJ1cVHrs+ekqz/T8YmrXjFOpZd9RoRTiC22
         9UO0nOkqlHTmDz58QpO3ns23kIupMA7vIjUEPSx+HYJXr73983sNWnEY1fveJ1nPkNVv
         gKBXR6I1EOpZn9pHYYomeIJYgZasN9aV5e9BLSScLaEt0nocurw+Y+2+L8HF3H+udK13
         QSTA==
X-Gm-Message-State: AN3rC/6C09Itqhcd75S0Kqy1Y+/c7guiqSoYM2X3ZzXvTLZi/ctfUcSQ
	XhWzlZ6uFGuG4g==
X-Received: by 10.13.238.65 with SMTP id x62mr13244959ywe.5.1493762947970;
        Tue, 02 May 2017 15:09:07 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.61.227 with SMTP id l90ls2182836otc.19.gmail; Tue, 02 May
 2017 15:09:07 -0700 (PDT)
X-Received: by 10.157.37.213 with SMTP id q79mr672824ota.11.1493762946988;
        Tue, 02 May 2017 15:09:06 -0700 (PDT)
In-Reply-To: <201705022023.38635.marc.mutz@kdab.com>
X-Original-Sender: jmckesson@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <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:32270
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/32270>

------=_Part_2521_1187088980.1493762946388
Content-Type: multipart/alternative; 
	boundary="----=_Part_2522_355650694.1493762946388"

------=_Part_2522_355650694.1493762946388
Content-Type: text/plain; charset=UTF-8

On Tuesday, May 2, 2017 at 2:25:03 PM UTC-4, Marc Mutz wrote:
>
> * technical term, not judgmental 
>
> Hi, 
>
> I thought this was solved in C++11 but Ville proved me wrong today: 
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#229 motivates 
> partial function specialisation for solving the problem that the world 
> outside 
> namespace std has to write 
>
>    using std::swap; 
>    swap(a, b); 
>
> (where swap() is a stand-in for any std function, incl. e.g. sin(), 
> for_each()). They can't just write 
>
>     std::swap(a, b); 
>
> because class authors are forbidden by [namespace.std] to add new 
> declarations 
> (that includes function overloads) to namespace std, even though they are 
> allowed to partically specialise class templates there. You cannot 
> partially 
> specialise function templates, you need to overload them. But you can't. 
> Not 
> in namespace std. So users need to activate ADL, while still allowing 
> falling 
> back to the std version, thus the using declaration + unqualified name 
> lookup. 
>
> I don't know when I learned about this the first time, but I do know from 
> where: Scott Meyer's books. Those are ~20 years old by now. 
>
> Can't we do better than forcing the world to permanently add that 
>
>    using std::name; 
>
> for essentially any call to a function in namespace std?
>

It's not "any call". It's only for calls where users would reasonably be 
expected to provide overloads for their types. So that means just `swap`.

And `begin` and `end`. And `cbegin` and `cend`. And `rbegin/rend`. And 
`crbegin/crend`. And `size` ;)

The problem really is that we want interfaces to allow 3 things though the 
same syntax, and C++ doesn't really support this combination very well:

1) Users can specify the behavior of these functions via member functions.

2) Users can specify the behavior of these functions for types via 
functions that are not members of that type.

3) Fundamental types can have defaults applied.

The problem is really #1 and #3. Both of these are important, and both of 
them are provided by the same overload. And neither of them use ADL

The solution to this insanity was supposed to be unified function call 
syntax, but the standards committee took a knee on that and refuses to even 
think about fixing it anymore.

So no, it's not gonna be fixed.

Or, alternatively, can't
>
>   int i, j;
>   swap(i, j);
>
> automagically find the std version? 
>

Even ignoring what breakage that could cause, it would still not be enough. 
Remember that #1 is implemented through the same mechanism: `std::swap` 
calling the type's member function. So if you have a type that provides a 
member `swap` but it doesn't have a `swap` at namespace scope (and let's be 
frank, it's *stupid* to have both), you still need `using std::swap` to get 
an unqualified call to `swap` to call the member function.

Again, UFC would have fixed this, but we cannot have nice things in C++.

-- 
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/dbbdbc10-3f83-48ea-9a78-beb179bd113a%40isocpp.org.

------=_Part_2522_355650694.1493762946388
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Tuesday, May 2, 2017 at 2:25:03 PM UTC-4, Marc Mutz wro=
te:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;=
border-left: 1px #ccc solid;padding-left: 1ex;">* technical term, not judgm=
ental
<br>
<br>Hi,
<br>
<br>I thought this was solved in C++11 but Ville proved me wrong today:
<br>
<br><a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#=
229" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;htt=
p://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fw=
g21%2Fdocs%2Fcwg_closed.html%23229\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCN=
FxTv-rQxEI42eHIzhGojw1j-CMEQ&#39;;return true;" onclick=3D"this.href=3D&#39=
;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22=
%2Fwg21%2Fdocs%2Fcwg_closed.html%23229\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAF=
QjCNFxTv-rQxEI42eHIzhGojw1j-CMEQ&#39;;return true;">http://www.open-std.org=
/jtc1/<wbr>sc22/wg21/docs/cwg_closed.<wbr>html#229</a> motivates=20
<br>partial function specialisation for solving the problem that the world =
outside=20
<br>namespace std has to write
<br>
<br>=C2=A0 =C2=A0using std::swap;
<br>=C2=A0 =C2=A0swap(a, b);
<br>
<br>(where swap() is a stand-in for any std function, incl. e.g. sin(),=20
<br>for_each()). They can&#39;t just write
<br>
<br>=C2=A0 =C2=A0 std::swap(a, b);
<br>
<br>because class authors are forbidden by [namespace.std] to add new decla=
rations=20
<br>(that includes function overloads) to namespace std, even though they a=
re=20
<br>allowed to partically specialise class templates there. You cannot part=
ially=20
<br>specialise function templates, you need to overload them. But you can&#=
39;t. Not=20
<br>in namespace std. So users need to activate ADL, while still allowing f=
alling=20
<br>back to the std version, thus the using declaration + unqualified name =
lookup.
<br>
<br>I don&#39;t know when I learned about this the first time, but I do kno=
w from=20
<br>where: Scott Meyer&#39;s books. Those are ~20 years old by now.
<br>
<br>Can&#39;t we do better than forcing the world to permanently add that
<br>
<br>=C2=A0 =C2=A0using std::name;
<br>
<br>for essentially any call to a function in namespace std?<br></blockquot=
e><div><br>It&#39;s not &quot;any call&quot;. It&#39;s only for calls where=
 users would reasonably be expected to provide overloads for their types. S=
o that means just `swap`.<br><br>And `begin` and `end`. And `cbegin` and `c=
end`. And `rbegin/rend`. And `crbegin/crend`. And `size` ;)<br><br>The prob=
lem really is that we want interfaces to allow 3 things though the same syn=
tax, and C++ doesn&#39;t really support this combination very well:<br><br>=
1) Users can specify the behavior of these functions via member functions.<=
br><br>2) Users can specify the behavior of these functions for types via f=
unctions that are not members of that type.<br><br>3) Fundamental types can=
 have defaults applied.<br><br>The problem is really #1 and #3. Both of the=
se are important, and both of them are provided by the same overload. And n=
either of them use ADL<br><br>The solution to this insanity was supposed to=
 be unified function call syntax, but the standards committee took a knee o=
n that and refuses to even think about fixing it anymore.<br><br>So no, it&=
#39;s not gonna be fixed.<br><br><blockquote class=3D"gmail_quote" style=3D=
"margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padd=
ing-left: 1ex;">Or, alternatively, can&#39;t<br><br>=C2=A0 int i, j;<br>=C2=
=A0 swap(i, j);<br><br>automagically find the std version? <br></blockquote=
></div><br>Even ignoring what breakage that could cause, it would still not=
 be enough. Remember that #1 is implemented through the same mechanism: `st=
d::swap` calling the type&#39;s member function. So if you have a type that=
 provides a member `swap` but it doesn&#39;t have a `swap` at namespace sco=
pe (and let&#39;s be frank, it&#39;s <i>stupid</i> to have both), you still=
 need `using std::swap` to get an unqualified call to `swap` to call the me=
mber function.<br><br>Again, UFC would have fixed this, but we cannot have =
nice things in C++.<br></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/dbbdbc10-3f83-48ea-9a78-beb179bd113a%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/dbbdbc10-3f83-48ea-9a78-beb179bd113a=
%40isocpp.org</a>.<br />

------=_Part_2522_355650694.1493762946388--

------=_Part_2521_1187088980.1493762946388--

.
