220 14040 <c8fdc18d-278c-438c-97ad-bc36231104f4@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: chris.kohlhoff@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Comment on N4244
Date: Sun, 19 Oct 2014 13:50:01 -0700 (PDT)
Lines: 139
Approved: news@gmane.org
Message-ID: <c8fdc18d-278c-438c-97ad-bc36231104f4@isocpp.org>
References: <0632b234-2e7b-489f-a640-aa927648eaf7@isocpp.org>
 <02d9673d-3dd3-4fec-aa7a-b925b73f9893@isocpp.org>
 <6d5e0622-29bb-4196-ad7b-9c6b5f08f8cb@isocpp.org>
 <CAFk2RUbct+MJad3mi24detu-AcJM52V7F6pK+ekR8rJSMsLx4Q@mail.gmail.com>
 <75c80e2f-e1a1-4e5f-8ae3-10ba25baad64@isocpp.org>
 <CAFk2RUae8tiiH0Xss=0JGCwb_-eMw_yeqZMvyspS4QeMCx2DRg@mail.gmail.com>
 <15c7ed1d-55c5-4329-9ada-605ee4c27080@isocpp.org>
 <CAFk2RUahyxN2=Hc2kE5Cg+t1DLhatEn6kC-_6dy3=o=4izgQnw@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_403_1565842355.1413751801166"
X-Trace: ger.gmane.org 1413751813 28252 80.91.229.3 (19 Oct 2014 20:50:13 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 19 Oct 2014 20:50:13 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCS7VEH374ORB6WHSCRAKGQEF65VXKI@isocpp.org Sun Oct 19 22:50:04 2014
Return-path: <std-proposals+bncBCS7VEH374ORB6WHSCRAKGQEF65VXKI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f199.google.com ([209.85.214.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCS7VEH374ORB6WHSCRAKGQEF65VXKI@isocpp.org>)
	id 1XfxQS-00015B-Eq
	for gclcip-std-proposals@m.gmane.org; Sun, 19 Oct 2014 22:50:04 +0200
Original-Received: by mail-ob0-f199.google.com with SMTP id va2sf21868281obc.2
        for <gclcip-std-proposals@m.gmane.org>; Sun, 19 Oct 2014 13:50:03 -0700 (PDT)
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
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=LcdwRfN40pQkPGvWw1JpiNxgaPrHMto9VXrYp9Gik28=;
        b=AyN1B5XhxedO74ERP2lUENqSIm9Os7HibunZGc5j9awJ6X7I3Qx9eQ6K2JP+RlDIUs
         KDtRJ8BpjLySem2PYgUCVXmNV7nxH5GxFup4FnOtdarWV4zWjqt7AmN/9UCib/X5xRqx
         XcOzhe9xIy8fsdGOU8fGgWdGSFfmFnIdCOaEIPVSZNHpT5CC7qnn7ZKoNCA+POX9kqAR
         CuRseDCu1pkndzX5RWGpRKJHBhewX0DctzAh5FPcCsXRNXwGfXGUyM+AwInQaH9D9HZz
         6C4R6m6iEZuM8VPKAP8Ab5zGRffo1W9Gxe8yIvjWDCaRCaz/yUW0eK+f5EumIMjTbHsh
         S6sQ==
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:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=LcdwRfN40pQkPGvWw1JpiNxgaPrHMto9VXrYp9Gik28=;
        b=gomksuD3KLqmPyjvMgYSH+ghGIm5cZzseWJqSjaxZO8ZA1Dv8HYxkZd5FP/UlyEXmb
         3bJ2293sxztPznds5cnBMlkgnyhP4Xc9pJ9d4Gsl+Hczbt8mx0c/hHyPoGkTWj4jii7T
         gIFvrQ6voQcMuMbiVKWqPzIWeRiQHfUaX3dgomUl9pd8dTcd7eRpNPBbA0aM7eT7ioES
         iWT7IC3jMJzug8kLwADgliK7aOmUuG3F4ZHux7+1SvoXpxZM+F6UjWptfeAb+wMc2+y2
         ESdg8+CeT26Xjkz4u44qe2GgghYYvFr/9PCQxw98/aAgalrRnI9NanphwvEuY7HlyEf0
         F4Qg==
X-Gm-Message-State: ALoCoQmB1UdTVMGdBs4nxRRzl8KYMHpt1ySnSysBjLHpmk2LQk1dOv1cLZ+qPz3XIBReDH+IpXvQ
X-Received: by 10.50.134.131 with SMTP id pk3mr9181883igb.8.1413751803476;
        Sun, 19 Oct 2014 13:50:03 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.51.16.66 with SMTP id fu2ls464817igd.0.canary; Sun, 19 Oct
 2014 13:50:02 -0700 (PDT)
X-Received: by 10.50.43.232 with SMTP id z8mr127508igl.13.1413751802851;
        Sun, 19 Oct 2014 13:50:02 -0700 (PDT)
In-Reply-To: <CAFk2RUahyxN2=Hc2kE5Cg+t1DLhatEn6kC-_6dy3=o=4izgQnw@mail.gmail.com>
X-Original-Sender: chris.kohlhoff@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>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://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>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:14040
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/14040>

------=_Part_403_1565842355.1413751801166
Content-Type: text/plain; charset=UTF-8



On Monday, October 20, 2014 4:35:16 AM UTC+11, Ville Voutilainen wrote:
>
> On 19 October 2014 01:36,  <chris.k...@gmail.com <javascript:>> wrote: 
> >> Then again, I don't quite see how to return a future<T> with N4244 - I 
> >> would 
> >> expect I need to return a future<T>& and have the future as a capture. 
> > It's a similar principle to when you write "async(f)". The function f 
> > doesn't return the future; instead std::async wraps it in the necessary 
> > machinery to run f and make the result available as a future. So, we 
> could 
>
> Blargh, I was confused for a moment. The gist of the matter is sharing the 
> state, and the lifetime of it. From the state of a resumable lambda, the 
> lambda can quite easily generate futures that are not necessarily 
> associated 
> with the state of the lambda. The lifetime of the state itself 
> is bound to the lambda, and sharing the state itself via the return type 
> is not really important, although it could theoretically be done. Neither 
> resumable lambdas nor resumable functions can move the state itself 
> out of themselves(*).


Experience with the macro-based equivalent of resumable lambdas shows that 
they can. For example:

  []() resumable
  {
    ...
    yield async_something(std::move(*[]this));
    ...
  }

is roughly equivalent to:

  __state = __LINE__; \
  async_something(std::move(*this)); \
  return; \
  case __LINE__:

Any state is moved along into the operation and the only thing the 
moved-from lambda does is exit following the yield.

This works very nicely as a truly lightweight way to chain async operations.

The return type of a resumable function takes care 
> of the lifetime of the state, whereas in a resumable lambda, the lambda 
> itself takes care of it.
>

I prefer to think that the resumable lambda itself is the state, but yes.

Cheers,
Chris

-- 

--- 
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/.

------=_Part_403_1565842355.1413751801166
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Monday, October 20, 2014 4:35:16 AM UTC+11, Vil=
le Voutilainen wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 19 Oct=
ober 2014 01:36, &nbsp;&lt;<a href=3D"javascript:" target=3D"_blank" gdf-ob=
fuscated-mailto=3D"kmRiJ4EmNA4J" onmousedown=3D"this.href=3D'javascript:';r=
eturn true;" onclick=3D"this.href=3D'javascript:';return true;">chris.k...@=
gmail.com</a>&gt; wrote:
<br>&gt;&gt; Then again, I don't quite see how to return a future&lt;T&gt; =
with N4244 - I
<br>&gt;&gt; would
<br>&gt;&gt; expect I need to return a future&lt;T&gt;&amp; and have the fu=
ture as a capture.
<br>&gt; It's a similar principle to when you write "async(f)". The functio=
n f
<br>&gt; doesn't return the future; instead std::async wraps it in the nece=
ssary
<br>&gt; machinery to run f and make the result available as a future. So, =
we could
<br>
<br>Blargh, I was confused for a moment. The gist of the matter is sharing =
the
<br>state, and the lifetime of it. From the state of a resumable lambda, th=
e
<br>lambda can quite easily generate futures that are not necessarily assoc=
iated
<br>with the state of the lambda. The lifetime of the state itself
<br>is bound to the lambda, and sharing the state itself via the return typ=
e
<br>is not really important, although it could theoretically be done. Neith=
er
<br>resumable lambdas nor resumable functions can move the state itself
<br>out of themselves(*).</blockquote><div><br></div><div>Experience with t=
he macro-based equivalent of resumable lambdas shows that they can. For exa=
mple:</div><div><br></div><div>&nbsp; []() resumable</div><div>&nbsp; {</di=
v><div>&nbsp; &nbsp; ...</div><div>&nbsp; &nbsp; yield async_something(std:=
:move(*[]this));</div><div>&nbsp; &nbsp; ...</div><div>&nbsp; }</div><div><=
br></div><div>is roughly equivalent to:</div><div><br></div><div>&nbsp; __s=
tate =3D __LINE__; \</div><div>&nbsp; async_something(std::move(*this)); \<=
/div><div>&nbsp; return; \</div><div>&nbsp; case __LINE__:</div><div><br></=
div><div>Any state is moved along into the operation and the only thing the=
 moved-from lambda does is exit following the yield.</div><div><br></div><d=
iv>This works very nicely as a truly lightweight way to chain async operati=
ons.</div><div><br></div><blockquote class=3D"gmail_quote" style=3D"margin:=
 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">The r=
eturn type of a resumable function takes care
<br>of the lifetime of the state, whereas in a resumable lambda, the lambda
<br>itself takes care of it.<br></blockquote><div><br></div><div>I prefer t=
o think that the resumable lambda itself is the state, but yes.</div><div><=
br></div><div>Cheers,</div><div>Chris</div></div>

<p></p>

-- <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"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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_403_1565842355.1413751801166--

.
