220 27399 <c3bc751f-5586-44d5-ba6c-4c3d6708e4ad@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Carl Cook <carl.cook@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Proposal - non allocating std::function
Date: Sun, 31 Jul 2016 06:29:29 -0700 (PDT)
Lines: 128
Approved: news@gmane.org
Message-ID: <c3bc751f-5586-44d5-ba6c-4c3d6708e4ad@isocpp.org>
References: <e00db911-40f5-4c11-a4b8-32bba77aa0a5@isocpp.org>
 <CANh-dXnpUNf2O5NTj213K1Jfmhge1=eit6+SistzYWZj+5CkNg@mail.gmail.com>
 <ff1087cf-5777-47e9-8caa-d28136aae130@isocpp.org> <CAOfiQqn31H_Mfkxx3yty1=wqu50JnpcSv25uLP3DNDTb5E8WYQ@mail.gmail.com>
 <cd6e299d-7cec-4d8e-8a55-f25fd88d1b91@isocpp.org>
 <CAOfiQqmAmuesO=jq+Kw3XYmS0B_j32LZ25oyw+XtykMtOYGHbg@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_55_691771595.1469971769382"
X-Trace: blaine.gmane.org 1469971793 16904 80.91.229.8 (31 Jul 2016 13:29:53 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sun, 31 Jul 2016 13:29:53 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBD27VEPGSEGBBO72666AKGQEEKKRK5Y@isocpp.org Sun Jul 31 15:29:39 2016
Return-path: <std-proposals+bncBD27VEPGSEGBBO72666AKGQEEKKRK5Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw0-f198.google.com ([209.85.161.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBD27VEPGSEGBBO72666AKGQEEKKRK5Y@isocpp.org>)
	id 1bTqoE-0004Lc-Ns
	for gclcip-std-proposals@m.gmane.org; Sun, 31 Jul 2016 15:29:39 +0200
Original-Received: by mail-yw0-f198.google.com with SMTP id f123sf190213284ywd.2
        for <gclcip-std-proposals@m.gmane.org>; Sun, 31 Jul 2016 06:29:38 -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=g4DmyFPhQaNi/N132e80UdiRvBzJmG+FCXq9YX05ZHA=;
        b=M0t7vXfOQcGANRxBocwIey732EPbgAeYJS6VV8wWj4FeHtT9SYa053E2WIhbHzLa/c
         HlxpgDFWOLjkqB58AlN/77GiuE6rz+rShJaWLMClrAHMjYe0DzQd3i+A9UHzw831aS54
         s5Y+S+Bj2KU64HQtVrW7s1BwFSHsvzqGcEQGLS/iCtMuf9cp0cIAnd8Bu2sEfqtsyGoT
         YLBsTesj8k4EHKhjQCIsHb2vUeJHdBg4fieqvPQp97TMoCPrHwwwy82kmFVis36ymYxr
         JESENhE+0UEVlL7q3GpWrBZtrzyZPaOrXLZ/F1HrTp/k6ThQQRy4kPF7m92EmY0MfSMu
         59uA==
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=g4DmyFPhQaNi/N132e80UdiRvBzJmG+FCXq9YX05ZHA=;
        b=OsyX0tR5AyCuJvTp+KRZBwkYqSUnXQ/T3sdKPmhSmrO1JlrI2XFjqKzzzU0LH7NW8C
         0+bYmlWoIaErs3ZaVsV/m/Eb68dLzaErqdhV+SKZKtTeH+51ZZiyhKiCGgk5glUnJGQ7
         xHEEtZNLYRsxs7mU3jRKUQhco5Oqa7HApwDVKK3h2pOsjiRC+aAHYcS3uFKADo4B/Yg1
         P479uE9Rjn8sLS2rABIu4aG+kbhXwEbq0EeNlLPbtc9NJaTe38c0ROMlbOG5NvXKY4U1
         0dMvehIFSiRMiAzZ5Q9hHsAr1hTL7RaA0KFulX5tIyuIuLe1YsbiEXr7G316Op9CKW01
         ezeA==
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=g4DmyFPhQaNi/N132e80UdiRvBzJmG+FCXq9YX05ZHA=;
        b=CEsgFEqYpHOdwu10mb6Dktgd8EYJMjtvHXaY1vA6s28VJbQtv5mGE//LuxK7PYMPt8
         t1Qn6Rs9lFtLLmPktVT8o4cx3WyQUG8bErnavrOyGjG7sojDFJIV0hVBGNVZwwNq50jZ
         aRvP2S70zi0o4b7HYtRzJnSh8sr4KGqrRB9d4sN1zFXt6Ve4Ez20qVjhm4BDOsf4OdKt
         eJ+Ajo4ZBNDGzOmY1a7r5B2M2rsY79+arHeHy4mBBC6aULAhvhCnFQdaM2PEagsvqEp8
         HKSJIJJEYhXyryZTv4Ullj5Oqm0M3h8/edIekLt2Q8o+ehDK+3t4iT5wb82O+2u4Ngn8
         YPLw==
X-Gm-Message-State: AEkoouu2RcAcIWsKsaMcvBsm4MwZE2IA/LB/boH9ryQsSXMneOhhuaS4sV2xG2iRFR611w==
X-Received: by 10.13.204.198 with SMTP id o189mr43288122ywd.35.1469971777630;
        Sun, 31 Jul 2016 06:29:37 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.20.68 with SMTP id 65ls3334553iou.16.gmail; Sun, 31 Jul
 2016 06:29:30 -0700 (PDT)
X-Received: by 10.36.108.66 with SMTP id w63mr369379itb.7.1469971770935;
        Sun, 31 Jul 2016 06:29:30 -0700 (PDT)
In-Reply-To: <CAOfiQqmAmuesO=jq+Kw3XYmS0B_j32LZ25oyw+XtykMtOYGHbg@mail.gmail.com>
X-Original-Sender: carl.cook@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:27399
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/27399>

------=_Part_55_691771595.1469971769382
Content-Type: multipart/alternative; 
	boundary="----=_Part_56_44143503.1469971769382"

------=_Part_56_44143503.1469971769382
Content-Type: text/plain; charset=UTF-8

In the example below, I am not passing a function_ref as the return value, 
I am returning the result of the invocation of that function_ref, which I'd 
assumed would be safe (i.e. return an integer).

However, it is the invocation that has failed, because the compiler has 
decided that the lambda can already be cleaned up (from what I can tell, 
looking at the disassembly).

So, granted that the function_ref certainly doesn't copy callable objects, 
but I don't think it's useful for any lambda, unless that lambda is just 
used to invoke a function (as in the llvm example usage).

On Friday, 15 July 2016 20:27:56 UTC+2, Richard Smith wrote:
>
> On Fri, Jul 15, 2016 at 2:12 AM, Carl Cook <carl...@gmail.com 
> <javascript:>> wrote:
>
>> On Friday, 15 July 2016 02:35:42 UTC+2, Richard Smith wrote:
>>>
>>> llvm::function_ref doesn't capture anything, and is not supposed to -- 
>>> it's a *non-owning* handle to a callable that outlives the handle. 
>>> (llvm::function_ref is to std::function as std::string_view is to 
>>> std::string.) This is a feature and a design goal of llvm::function_ref, 
>>> but I think it means it's addressing a fundamentally different problem than 
>>> the one you're tackling here (which seems to be essentially, "let me 
>>> control the size and alignment in std::function's small function 
>>> optimization"
>>>
>>
>> Understood. What caught me out is that compilers can aggressively limit 
>> the scope of lambdas. Hence I believe the following is not legal usage:
>>
>> int non_const_var = 0xf;
>> function_ref<int()> f_ref = [&]() { return non_const_var;};
>> return f_ref();
>>
>
> Right, it's exactly as broken as this:
>
> string g() {
>   string_view s_v = string("blah blah");
>   return s_v;
> }
>
> In both cases, you've bound an object with reference semantics to a 
> (non-lifetime-extended) temporary object.
>

-- 
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/c3bc751f-5586-44d5-ba6c-4c3d6708e4ad%40isocpp.org.

------=_Part_56_44143503.1469971769382
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">In the example below, I am not passing a function_ref as t=
he return value, I am returning the result of the invocation of that functi=
on_ref, which I&#39;d assumed would be safe (i.e. return an integer).<div><=
br></div><div>However, it is the invocation that has failed, because the co=
mpiler has decided that the lambda can already be cleaned up (from what I c=
an tell, looking at the disassembly).</div><div><br></div><div>So, granted =
that the function_ref certainly doesn&#39;t copy callable objects, but I do=
n&#39;t think it&#39;s useful for any lambda, unless that lambda is just us=
ed to invoke a function (as in the llvm example usage).<br><br>On Friday, 1=
5 July 2016 20:27:56 UTC+2, Richard Smith  wrote:<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"ltr"><div><div class=3D"gmail_quote">On Fri,=
 Jul 15, 2016 at 2:12 AM, Carl Cook <span dir=3D"ltr">&lt;<a href=3D"javasc=
ript:" target=3D"_blank" gdf-obfuscated-mailto=3D"PLqVwXikCwAJ" 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;">carl...@gmail.com</a>&=
gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 =
0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><span>=
On Friday, 15 July 2016 02:35:42 UTC+2, Richard Smith  wrote:<blockquote cl=
ass=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #cc=
c solid;padding-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_quote"><div>=
llvm::function_ref doesn&#39;t capture anything, and is not supposed to -- =
it&#39;s a *non-owning* handle to a callable that outlives the handle. (llv=
m::function_ref is to std::function as std::string_view is to std::string.)=
 This is a feature and a design goal of llvm::function_ref, but I think it =
means it&#39;s addressing a fundamentally different problem than the one yo=
u&#39;re tackling here (which seems to be essentially, &quot;let me control=
 the size and alignment in std::function&#39;s small function optimization&=
quot;</div></div></div></blockquote><div><br></div></span><div>Understood. =
What caught me out is that compilers can aggressively limit the scope of la=
mbdas. Hence I believe the following is not legal usage:</div><div><br></di=
v><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word=
;background-color:rgb(250,250,250)"><code><div><div>int non_const_var =3D 0=
xf;</div><div>function_ref&lt;int()&gt; f_ref =3D [&amp;]() { return non_co=
nst_var;};</div><div>return f_ref();</div></div></code></div></div></div></=
blockquote><div><br></div><div>Right, it&#39;s exactly as broken as this:</=
div><div><br></div><div>string g() {</div><div>=C2=A0 string_view s_v =3D s=
tring(&quot;blah blah&quot;);</div><div>=C2=A0 return s_v;</div><div>}</div=
><div><br></div><div>In both cases, you&#39;ve bound an object with referen=
ce semantics to a (non-lifetime-extended) temporary object.</div></div></di=
v></div>
</blockquote></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/c3bc751f-5586-44d5-ba6c-4c3d6708e4ad%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/c3bc751f-5586-44d5-ba6c-4c3d6708e4ad=
%40isocpp.org</a>.<br />

------=_Part_56_44143503.1469971769382--

------=_Part_55_691771595.1469971769382--

.
