220 27071 <CAOfiQqmAmuesO=jq+Kw3XYmS0B_j32LZ25oyw+XtykMtOYGHbg@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Richard Smith <richard@metafoo.co.uk>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Proposal - non allocating std::function
Date: Fri, 15 Jul 2016 11:27:53 -0700
Lines: 92
Approved: news@gmane.org
Message-ID: <CAOfiQqmAmuesO=jq+Kw3XYmS0B_j32LZ25oyw+XtykMtOYGHbg@mail.gmail.com>
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>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a11499a74eb59f50537b0c6c2
X-Trace: ger.gmane.org 1468607282 22283 80.91.229.3 (15 Jul 2016 18:28:02 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 15 Jul 2016 18:28:02 +0000 (UTC)
To: "std-proposals@isocpp.org" <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDVNBJG4YAIBBK6WUS6AKGQEO5YDZOI@isocpp.org Fri Jul 15 20:28:02 2016
Return-path: <std-proposals+bncBDVNBJG4YAIBBK6WUS6AKGQEO5YDZOI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pa0-f69.google.com ([209.85.220.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDVNBJG4YAIBBK6WUS6AKGQEO5YDZOI@isocpp.org>)
	id 1bO7q9-0000g4-M9
	for gclcip-std-proposals@m.gmane.org; Fri, 15 Jul 2016 20:27:57 +0200
Original-Received: by mail-pa0-f69.google.com with SMTP id q2sf198597351pap.1
        for <gclcip-std-proposals@m.gmane.org>; Fri, 15 Jul 2016 11:27:56 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:from
         :date:message-id:subject:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=VEjmyMO5LMIyiS57xHtDjQPjv4x56aQZ28ZNkcMMLKE=;
        b=e7zJqBUOgDjEVsFKM8BeAOKRnA6W93/KbDUhSfvrWsX0cPEzllrENDbvCr59y/Mpjf
         cAJGGn9/K/N9Z1E2Pgm4bU7eB6Btwruek62yPfiXy52mni58FWfYoy4Wi/ajqezb9TzK
         qVZmB3cZ7GmxdufBArUYZ559KTDruEh/geupC3Ut7AiOUsWMHeBqrWjNzr3iOqPSg3+6
         1gK4nauRsfd/RTTSwhP8bKaNahR4vOQz+R2+N7KtyopTz0T56VW0opFtv0gHWfkYbNO0
         pIfQSer0UbpnG2V8J4EVoD6obmmY+TonUN0ZQaKm/MSZzfLWXct/0s31MMtzh8FRwX8z
         5LJA==
X-Gm-Message-State: ALyK8tLV3/Cn8NESFvAtJDMYEltyLSDqbsEWfX2wPvQrsSMMDQtfJQMT8GEbJn3FW2ruzQ==
X-Received: by 10.98.100.141 with SMTP id y135mr11677259pfb.6.1468607276296;
        Fri, 15 Jul 2016 11:27:56 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.54.140 with SMTP id h12ls4148999otc.40.gmail; Fri, 15 Jul
 2016 11:27:55 -0700 (PDT)
X-Received: by 10.55.109.198 with SMTP id i189mr27382830qkc.140.1468607275251;
        Fri, 15 Jul 2016 11:27:55 -0700 (PDT)
Original-Received: from mail-qk0-x22b.google.com (mail-qk0-x22b.google.com. [2607:f8b0:400d:c09::22b])
        by mx.google.com with ESMTPS id s64si6126681qka.43.2016.07.15.11.27.55
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 15 Jul 2016 11:27:55 -0700 (PDT)
Received-SPF: pass (google.com: domain of metafoo@gmail.com designates 2607:f8b0:400d:c09::22b as permitted sender) client-ip=2607:f8b0:400d:c09::22b;
Original-Received: by mail-qk0-x22b.google.com with SMTP id s63so109052815qkb.2
        for <std-proposals@isocpp.org>; Fri, 15 Jul 2016 11:27:55 -0700 (PDT)
X-Received: by 10.55.204.3 with SMTP id r3mr27567226qki.91.1468607274634; Fri,
 15 Jul 2016 11:27:54 -0700 (PDT)
Original-Sender: metafoo@gmail.com
Original-Received: by 10.200.56.152 with HTTP; Fri, 15 Jul 2016 11:27:53 -0700 (PDT)
In-Reply-To: <cd6e299d-7cec-4d8e-8a55-f25fd88d1b91@isocpp.org>
X-Original-Sender: richard@metafoo.co.uk
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com;       spf=pass (google.com: domain of metafoo@gmail.com
 designates 2607:f8b0:400d:c09::22b as permitted sender) smtp.mailfrom=metafoo@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:27071
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/27071>

--001a11499a74eb59f50537b0c6c2
Content-Type: text/plain; charset=UTF-8

On Fri, Jul 15, 2016 at 2:12 AM, Carl Cook <carl.cook@gmail.com> 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/CAOfiQqmAmuesO%3Djq%2BKw3XYmS0B_j32LZ25oyw%2BXtykMtOYGHbg%40mail.gmail.com.

--001a11499a74eb59f50537b0c6c2
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On F=
ri, Jul 15, 2016 at 2:12 AM, Carl Cook <span dir=3D"ltr">&lt;<a href=3D"mai=
lto:carl.cook@gmail.com" target=3D"_blank">carl.cook@gmail.com</a>&gt;</spa=
n> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;b=
order-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><span class=3D=
"">On Friday, 15 July 2016 02:35:42 UTC+2, Richard Smith  wrote:<blockquote=
 class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px =
#ccc solid;padding-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_quote"><d=
iv>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. (=
llvm::function_ref is to std::function as std::string_view is to std::strin=
g.) 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=
 you&#39;re tackling here (which seems to be essentially, &quot;let me cont=
rol the size and alignment in std::function&#39;s small function optimizati=
on&quot;</div></div></div></blockquote><div><br></div></span><div>Understoo=
d. What caught me out is that compilers can aggressively limit the scope of=
 lambdas. Hence I believe the following is not legal usage:</div><div><br><=
/div><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-w=
ord;background-color:rgb(250,250,250)"><code><div><div>int non_const_var =
=3D 0xf;</div><div>function_ref&lt;int()&gt; f_ref =3D [&amp;]() { return n=
on_const_var;};</div><div>return f_ref();</div></div></code></div></div></d=
iv></blockquote><div><br></div><div>Right, it&#39;s exactly as broken as th=
is:</div><div><br></div><div>string g() {</div><div>=C2=A0 string_view s_v =
=3D string(&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 re=
ference semantics to a (non-lifetime-extended) temporary object.</div></div=
></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/CAOfiQqmAmuesO%3Djq%2BKw3XYmS0B_j32LZ=
25oyw%2BXtykMtOYGHbg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOfiQqmAmu=
esO%3Djq%2BKw3XYmS0B_j32LZ25oyw%2BXtykMtOYGHbg%40mail.gmail.com</a>.<br />

--001a11499a74eb59f50537b0c6c2--

.
