220 4640 <d89adabd-edca-4a40-8a8a-ff23f66c436f@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Changing lambda scope
Date: Mon, 27 May 2013 07:03:21 -0700 (PDT)
Lines: 137
Approved: news@gmane.org
Message-ID: <d89adabd-edca-4a40-8a8a-ff23f66c436f@isocpp.org>
References: <ae01f736-d3ac-48d6-981f-702b9ab2b3b3@isocpp.org>
 <01190eaa-6223-4d3c-a9d3-b0d850aab98e@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_631_13155021.1369663401362"
X-Trace: ger.gmane.org 1369663406 27244 80.91.229.3 (27 May 2013 14:03:26 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 27 May 2013 14:03:26 +0000 (UTC)
Cc: potswa@gmail.com
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBLGPRWGQKGQESWNEYLA@isocpp.org Mon May 27 16:03:27 2013
Return-path: <std-proposals+bncBCEKFTV6ZUMBBLGPRWGQKGQESWNEYLA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f197.google.com ([209.85.214.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBLGPRWGQKGQESWNEYLA@isocpp.org>)
	id 1Ugy1F-0001SS-Gl
	for gclcip-std-proposals@m.gmane.org; Mon, 27 May 2013 16:03:25 +0200
Original-Received: by mail-ob0-f197.google.com with SMTP id dn14sf30652866obc.8
        for <gclcip-std-proposals@m.gmane.org>; Mon, 27 May 2013 07:03:24 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=x-beenthere:date:from:to:cc:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-google-group-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe:content-type;
        bh=qoEoC2fy+UIuAC8txaVpgO6x8btCQmEgwmsRNZTftPI=;
        b=mop+471o/sETzsTkitSoCrBmnp5CBjthnvcP0vrfYydY+wxyPgB86X1zfSurnI3XZx
         9S5FaqtafEtUaBTRYQf6GbKB38aBrh02x2Sz5g8uA+0cHtT6xxT+dmIDx1W2xdp0JbSH
         sA3cJqzZ7Vxx6nJv2PiTJk1sXe8MAnpUfy5A3yP2ftp+GkaDcOp+oUrj2OqXUpByyPhW
         CLPSi8u1qyxl2f/xvzZfhqgWHprrq0fdtaWLwVVWAFihpQfQEO5QwSgtoenQ4vbMyqJK
         Y+eJ1Q3MLhFbrWi/agPuxy0ZFHu0hReOPo9ycksV4FELY3u5OVHcV+T/iVrTN2RoCSPd
         9jLg==
X-Received: by 10.42.254.72 with SMTP id nd8mr20101760icb.31.1369663404450;
        Mon, 27 May 2013 07:03:24 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.117.36 with SMTP id kb4ls1994579igb.11.gmail; Mon, 27 May
 2013 07:03:23 -0700 (PDT)
X-Received: by 10.50.196.227 with SMTP id ip3mr975387igc.10.1369663402853;
        Mon, 27 May 2013 07:03:22 -0700 (PDT)
In-Reply-To: <01190eaa-6223-4d3c-a9d3-b0d850aab98e@isocpp.org>
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: <http://groups.google.com/a/isocpp.org/group/std-proposals/post?hl=en>,
 <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?hl=en&topic=25838>,
 <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:4640
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/4640>

------=_Part_631_13155021.1369663401362
Content-Type: text/plain; charset=ISO-8859-1

On Monday, May 27, 2013 4:52:17 AM UTC-7, pot...@gmail.com wrote:
>
> GCC 4.9 accepts your example already, but if it didn't, the fix would 
> simply be a wrapper class template in the desired associated namespace.
>
> namespace X {
> template< typename t > // wrapper class
> struct adl_wrapper : t { using t::t; };
>
> template< typename t > // wrapper factory
> adl_wrapper< t > adl_wrap( t o ) { return { o }; }
>
> template<typename L, typename R> L operator+(L l, R r) { }
> auto f() { return adl_wrapper( [] {} ); }
> }
>
> It would be bad to make lambdas different from other local classes. Would 
> applying the proposal so broadly break much? Before C++11 it was illegal to 
> use a local class as a template argument and it we're only noticing this 
> now because returning a local type is a C++14 feature.
>

Technically, the issue was caused by the ability to allow local classes to 
escape the functions in which they're defined at all. And that's due to the 
C++11 ability to have template argument deduction deduce them. At which 
point you could pass a local class as a template parameter to some 
algorithm, which could then attempt to use ADL-based operations on it.

It's just that, now with return type deduction (combined with deduction in 
very arbitrary places, so that a type can go far from where it was defined 
without anyone having to actually type the name of an unnameable type), we 
have dramatically magnified the number of places where this can happen.

-- 

--- 
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/?hl=en.



------=_Part_631_13155021.1369663401362
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Monday, May 27, 2013 4:52:17 AM UTC-7, pot...@gmail.com wrote:<blockquot=
e class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: =
1px #ccc solid;padding-left: 1ex;">GCC 4.9 accepts your example already, bu=
t if it didn't, the fix would simply be a wrapper class template in the des=
ired associated namespace.<br><br><div style=3D"background-color:rgb(250,25=
0,250);border-color:rgb(187,187,187);border-style:solid;border-width:1px;wo=
rd-wrap:break-word"><code><div><span style=3D"color:#008">namespace</span><=
span style=3D"color:#000"> X </span><span style=3D"color:#660">{</span><spa=
n style=3D"color:#000"><br></span><span style=3D"color:#008">template</span=
><span style=3D"color:#660">&lt;</span><span style=3D"color:#000"> </span><=
span style=3D"color:#008">typename</span><span style=3D"color:#000"> t </sp=
an><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"> </span=
><span style=3D"color:#800">// wrapper class</span><span style=3D"color:#00=
0"><br></span><span style=3D"color:#008">struct</span><span style=3D"color:=
#000"> adl_wrapper </span><span style=3D"color:#660">:</span><span style=3D=
"color:#000"> t </span><span style=3D"color:#660">{</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#008">using</span><span style=3D"col=
or:#000"> t</span><span style=3D"color:#660">::</span><span style=3D"color:=
#000">t</span><span style=3D"color:#660">;</span><span style=3D"color:#000"=
> </span><span style=3D"color:#660">};</span><span style=3D"color:#000"><br=
><br></span><span style=3D"color:#008">template</span><span style=3D"color:=
#660">&lt;</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
08">typename</span><span style=3D"color:#000"> t </span><span style=3D"colo=
r:#660">&gt;</span><span style=3D"color:#000"> </span><span style=3D"color:=
#800">// wrapper factory</span><span style=3D"color:#000"><br>adl_wrapper</=
span><span style=3D"color:#660">&lt;</span><span style=3D"color:#000"> t </=
span><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"> adl_=
wrap</span><span style=3D"color:#660">(</span><span style=3D"color:#000"> t=
 o </span><span style=3D"color:#660">)</span><span style=3D"color:#000"> </=
span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#008">return</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"> o </span><sp=
an style=3D"color:#660">};</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span><span=
 style=3D"color:#008">template</span><span style=3D"color:#660">&lt;</span>=
<span style=3D"color:#008">typename</span><span style=3D"color:#000"> L</sp=
an><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#008">typename</span><span style=3D"color:#000"> R</span=
><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"> L </span=
><span style=3D"color:#008">operator</span><span style=3D"color:#660">+(</s=
pan><span style=3D"color:#000">L l</span><span style=3D"color:#660">,</span=
><span style=3D"color:#000"> R r</span><span style=3D"color:#660">)</span><=
span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span =
style=3D"color:#000"> </span><span style=3D"color:#660">}</span><span style=
=3D"color:#000"><br></span><span style=3D"color:#008">auto</span><span styl=
e=3D"color:#000"> f</span><span style=3D"color:#660">()</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#008">return</span><span style=3D"c=
olor:#000"> adl_wrapper</span><span style=3D"color:#660">(</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#660">[]</span><span style=3D=
"color:#000"> </span><span style=3D"color:#660">{}</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#660">);</span><span style=3D"color:#=
000"> </span><span style=3D"color:#660">}</span><span style=3D"color:#000">=
<br></span><span style=3D"color:#660">}</span><span style=3D"color:#000"><b=
r></span></div></code></div><br>It would be bad to make lambdas different f=
rom other local classes. Would applying the proposal so broadly break much?=
 Before C++11 it was illegal to use a local class as a template argument an=
d it we're only noticing this now because returning a local type is a C++14=
 feature.<br></blockquote><div><br>Technically, the issue was caused by the=
 ability to allow local classes to escape the functions in which they're de=
fined at all. And that's due to the C++11 ability to have template argument=
 deduction deduce them. At which point you could pass a local class as a te=
mplate parameter to some algorithm, which could then attempt to use ADL-bas=
ed operations on it.<br><br>It's just that, now with return type deduction =
(combined with deduction in very arbitrary places, so that a type can go fa=
r from where it was defined without anyone having to actually type the name=
 of an unnameable type), we have dramatically magnified the number of place=
s where this can happen.<br></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_631_13155021.1369663401362--

.
