220 22001 <CA+wfc1_vMcFr4nS=dWCMK4iih03KhdbRu6AtnqneyWoYjwGw2w@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Oliver Kowalke <oliver.kowalke@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: is await an extension of the do-notation? (was Re:
 Re: Resumable expressions p0114r0 vs async/await P0057R0)
Date: Tue, 27 Oct 2015 07:47:41 +0100
Lines: 162
Approved: news@gmane.org
Message-ID: <CA+wfc1_vMcFr4nS=dWCMK4iih03KhdbRu6AtnqneyWoYjwGw2w@mail.gmail.com>
References: <639f0012-8cb4-4db3-82a6-8d042a3497f9@isocpp.org>
 <401aa118-ed0b-4c7b-92cf-3fbd706eff9d@isocpp.org> <fcbcc1c4-535c-4fa2-a17d-4acffe84a4b5@isocpp.org>
 <1d15dbc4-e0c1-4df1-86db-014e11f14d26@isocpp.org> <56114953.4030701@wanadoo.fr>
 <561B403D.4030403@gmail.com> <CAOfiQqkKvZfVatJ1Bz4qSvGc-g6iep0xeP1B1=J1-gCu43NXxg@mail.gmail.com>
 <561C07D1.3080304@gmail.com> <CAOfiQqnR4GYCttwu8G-44_UEN4WekW19uorEvf-5VC3vOpej-g@mail.gmail.com>
 <561C213F.1060009@gmail.com> <fb82d876-8a54-4c28-8e53-297018470cf6@isocpp.org>
 <561C3875.2050701@gmail.com> <86924069-44d0-447f-bf8a-a42e46579832@isocpp.org>
 <561D79A7.8080007@gmail.com> <894616d6-9609-4038-b2bc-d2c62df21e0f@isocpp.org>
 <99bdb3ae-9214-4440-8572-4c47a61eda46@isocpp.org> <58628096-14ae-42b2-89d3-c0bd2183bbc0@isocpp.org>
 <561DC957.8080603@gmail.com> <a44dae17-5f63-4c60-a943-d74a1332b54c@isocpp.org>
 <d3723a3d-1b73-4c6c-bc7f-3d224d2ec8a2@isocpp.org> <2e09660f-d688-474a-8811-85fb041f68b8@isocpp.org>
 <f3dbc6ee-80cf-43f1-9b49-7ed1879de0cc@isocpp.org> <8b78abb4-16b6-4b65-8513-6e2c17317647@isocpp.org>
 <CAL52AasThHcBZUbyT1NfgzEe+qaWKuO9eE6pxS-qfXxxSSbcbQ@mail.gmail.com>
 <779be861-3b2a-427a-b36b-ad2874c81129@isocpp.org> <CAL52AasaxsP2i-Bh-kVrCoKad_Z08dUpL-0w=Lb2dyTGz3f9PQ@mail.gmail.com>
 <767364f8-785d-4f8f-9bc0-852df56ee4eb@isocpp.org> <f27fd4c9-86c4-44a7-8162-991a32a38e63@isocpp.org>
 <CA+wfc1-qmKY-yA1fPOmWjGuR7qTMY3PRVbjxtPaPn2FLad2hBA@mail.gmail.com>
 <d7653631-b45c-4952-a308-9919e84c538e@isocpp.org> <CA+wfc1-s0_TZUn_FcoPnEFTOiofM8oLwdy_4EWDmtK+wApratw@mail.gmail.com>
 <f03a6bdc-6719-4f4a-bcff-e39d819e2eff@isocpp.org> <CA+wfc1_16+NXesmOFUrOJpPa=X+RGm0Rr89CTe1mGFWK8JUAiA@mail.gmail.com>
 <0a728eee-e8e7-48ea-adf6-2a8dae63916e@isocpp.org> <CA+wfc1-b_TaJT-FQmZ3hEYzH+B16CaqcBd4wbgmf84gagegHYw@mail.gmail.com>
 <e9b4c568-2a00-4f25-8324-921ca1926abe@isocpp.org> <CA+wfc1_mDmHcfE8-peKxfL+_kFF1UrOt4daw=mEAuT_-Rvn9Ng@mail.gmail.com>
 <CAL52AasCidZMkCaMG+5YhhC5CR-iz8oKn2S5LckEfj2qTvFQ1A@mail.gmail.com>
 <CA+wfc19ZncdOVDVhPktbKi2aikqt2MEiq66a6=vL4xq=DpZDrA@mail.gmail.com> <6a4f863e-faf0-42ac-b85d-0951738350ab@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a1140978c7c8482052310755a
X-Trace: ger.gmane.org 1445928484 23679 80.91.229.3 (27 Oct 2015 06:48:04 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 27 Oct 2015 06:48:04 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCLZHP5J7MHRBIN4XSYQKGQEVY5DRBI@isocpp.org Tue Oct 27 07:48:04 2015
Return-path: <std-proposals+bncBCLZHP5J7MHRBIN4XSYQKGQEVY5DRBI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yk0-f198.google.com ([209.85.160.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCLZHP5J7MHRBIN4XSYQKGQEVY5DRBI@isocpp.org>)
	id 1Zqy39-0003m4-2b
	for gclcip-std-proposals@m.gmane.org; Tue, 27 Oct 2015 07:48:03 +0100
Original-Received: by ykdr3 with SMTP id r3sf341656855ykd.2
        for <gclcip-std-proposals@m.gmane.org>; Mon, 26 Oct 2015 23:48:02 -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:in-reply-to:references:from:date
         :message-id:subject:to:content-type: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=540TTbo+DsLsT3vTJjEav6zvreO3nw1E9z31ycp+I7E=;
        b=bovxR3WyRGS54wGVwTLhiLmZUrkNuNs1taHaMCIk/sD0IzHT7cqpdgpNjgB9oerTFQ
         LuU8p9l9eti5cEgl46k2uyN43kgzrUklZ8q8T47dVLcRa2NMSynOJpp4a35SUv2i649B
         EC/KT7tSKNSIuWP+pIL9BwaOZDOjv0AopIOCRb2JCKxUNVpSdA9khVKsCh7+pki4DcKV
         7RtL5kMG10SSesU/4k3z2tcCNOkb/90D3oav2nysrBV4sOeWwAo5HMG0AwILC2WO5SE2
         6/djxTxKCXWFsqtu5bzWRXSHE+IC4NRzwmcQD/XIBcapuN+mRbDf3z4PQzuTXhyJEgTC
         nBmg==
X-Gm-Message-State: ALoCoQliCJSKeeGFT4EiMMRZ/OY8Cpt3R4S2RuREbuUyi9PPUHoz2ufnN8kmKRf8EzPkk567616h
X-Received: by 10.13.232.148 with SMTP id r142mr9430195ywe.51.1445928482339;
        Mon, 26 Oct 2015 23:48:02 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.248.129 with SMTP id ym1ls1956038obc.25.gmail; Mon, 26 Oct
 2015 23:48:01 -0700 (PDT)
X-Received: by 10.60.23.1 with SMTP id i1mr26623268oef.57.1445928481271;
        Mon, 26 Oct 2015 23:48:01 -0700 (PDT)
Original-Received: from mail-oi0-x231.google.com (mail-oi0-x231.google.com. [2607:f8b0:4003:c06::231])
        by mx.google.com with ESMTPS id et5si12928228obb.104.2015.10.26.23.48.01
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Mon, 26 Oct 2015 23:48:01 -0700 (PDT)
Received-SPF: pass (google.com: domain of oliver.kowalke@gmail.com designates 2607:f8b0:4003:c06::231 as permitted sender) client-ip=2607:f8b0:4003:c06::231;
Original-Received: by oiao187 with SMTP id o187so114492468oia.3
        for <std-proposals@isocpp.org>; Mon, 26 Oct 2015 23:48:01 -0700 (PDT)
X-Received: by 10.202.104.201 with SMTP id o70mr26141631oik.126.1445928481095;
 Mon, 26 Oct 2015 23:48:01 -0700 (PDT)
Original-Received: by 10.76.23.231 with HTTP; Mon, 26 Oct 2015 23:47:41 -0700 (PDT)
In-Reply-To: <6a4f863e-faf0-42ac-b85d-0951738350ab@isocpp.org>
X-Original-Sender: oliver.kowalke@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of oliver.kowalke@gmail.com designates 2607:f8b0:4003:c06::231 as
 permitted sender) smtp.mailfrom=oliver.kowalke@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) header.from=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: <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:22001
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/22001>

--001a1140978c7c8482052310755a
Content-Type: text/plain; charset=UTF-8

2015-10-22 14:47 GMT+02:00 Giovanni Piero Deretta <gpderetta@gmail.com>:

> template<class T, class R>
> class context;
>
> template<class T, class R>
> context::context() ; // create any empty context
>
> template<class T, class R>
> context::context( Fn && fn, Args && ... args); // requires
> IsSame<result_of<Fn(context<R,T>, args..), context>;
>
> template<class T, class R>
> R context::operator()(T); // invokes context and implicitly pass to it
> this context. On return 'this' contains the context we are coming from.
> Returning it explicitly is an alternative.
>

I believe that this API might only work for asymmetric context switching:

void bar( context synthctx2) {
   synthctx();
}

void foo( context synthctx1) {
   context ctx2( bar);
   ctx2();
}

context ctx1( foo);
ctx1();

context 'ctx1' and 'ctx2' own a side-stack
'synthctx1' and 'synthctx2' are synthesized context' (ctor of 'ctx1' and
'ctx2') passed as argument to 'foo() / 'bar()'
'synthctx1' is used to switch back to 'foo' (re-enter context ctx1), but it
does not own (or has a connection to) the side stack
managed by 'ctx1'!
in the ctor of 'ctx2' we have not access to the control structure managing
the side-stack of 'ctx1'
'synthctx1' is not equivalent to 'ctx1' but of the same type - that foolish
the user

another variation of the API; the current active context is passed as an
argument (no static pointer) to the context-fn:

context( Fn && fn, Args && ... args); // Fn signature '(context, void *)'
static context main_context();
void * operator()( context from, void * data);

ctor creates and owns side-stack
'operator()' requires the context to be resumed (+ data transferred to it)
and we can shared the ownership
of side-stack with the synthesized context.

the API requires static member function 'main_context()' because in
'main()' (or in top-level std::thread-fn)
we don't have a context at hand from which we switch to our desired context.
in order to be equivalent to the semantics of the other context',
'main_context()' returns a context that refers to
the same type (maybe allocated using 'schwarz pointers' etc.)

void bar( context currctx2, void * vp) {
   context mctx = ( context *) vp;
   ( * mctx)( currctx2);
}

void foo( context currctx1, void * vp) {
   context ctx2( bar);
   ctx2( currctx1, vp);
}

context mctx = context::main_context();
context ctx1( foo);
ctx1( mctx, & mctx);

-- 

--- 
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/.

--001a1140978c7c8482052310755a
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">2015=
-10-22 14:47 GMT+02:00 Giovanni Piero Deretta <span dir=3D"ltr">&lt;<a href=
=3D"mailto:gpderetta@gmail.com" target=3D"_blank">gpderetta@gmail.com</a>&g=
t;</span>:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px=
 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">template&lt=
;class T, class R&gt;<br><div>class context;<br><br>template&lt;class T, cl=
ass R&gt;<br>context::context() ; // create any empty context<br><br>templa=
te&lt;class T, class R&gt;<br>context::context( Fn &amp;&amp; fn, Args &amp=
;&amp; ... args); // requires IsSame&lt;result_of&lt;Fn(context&lt;R,T&gt;,=
 args..), context&gt;;<br><br>template&lt;class T, class R&gt;<br>R context=
::operator()(T); // invokes context and implicitly pass to it this context.=
 On return &#39;this&#39; contains the context we are coming from. Returnin=
g it explicitly is an alternative.<br></div></blockquote><div><br></div><di=
v>I believe that this API might only work for asymmetric context switching:=
<br><br></div><div>void bar( context synthctx2) {<br></div><div>=C2=A0=C2=
=A0 synthctx();<br></div><div>}<br><br></div><div>void foo( context synthct=
x1) {<br></div><div>=C2=A0=C2=A0 context ctx2( bar);<br></div><div>=C2=A0=
=C2=A0 ctx2();<br>}<br><br></div><div>context ctx1( foo);<br></div><div>ctx=
1();<br></div><div><br></div></div>context &#39;ctx1&#39; and &#39;ctx2&#39=
; own a side-stack<br></div><div class=3D"gmail_extra">&#39;synthctx1&#39; =
and &#39;synthctx2&#39; are synthesized context&#39; (ctor of &#39;ctx1&#39=
; and &#39;ctx2&#39;) passed as argument to &#39;foo() / &#39;bar()&#39;<br=
></div><div class=3D"gmail_extra">&#39;synthctx1&#39; is used to switch bac=
k to &#39;foo&#39; (re-enter context ctx1), but it does not own (or has a c=
onnection to) the side stack<br></div><div class=3D"gmail_extra">managed by=
 &#39;ctx1&#39;!<br></div><div class=3D"gmail_extra">in the ctor of &#39;ct=
x2&#39; we have not access to the control structure managing the side-stack=
 of &#39;ctx1&#39;<br>&#39;synthctx1&#39; is not equivalent to &#39;ctx1&#3=
9; but of the same type - that foolish the user<br><br></div><div class=3D"=
gmail_extra">another variation of the API; the current active context is pa=
ssed as an argument (no static pointer) to the context-fn:<br><br>context( =
Fn &amp;&amp; fn, Args &amp;&amp; ... args); // Fn signature &#39;(context,=
 void *)&#39;<br></div><div class=3D"gmail_extra">static context main_conte=
xt();<br></div><div class=3D"gmail_extra">void * operator()( context from, =
void * data);<br><br></div><div class=3D"gmail_extra">ctor creates and owns=
 side-stack<br></div><div class=3D"gmail_extra">&#39;operator()&#39; requir=
es the context to be resumed (+ data transferred to it) and we can shared t=
he ownership<br></div><div class=3D"gmail_extra">of side-stack with the syn=
thesized context.<br><br></div><div class=3D"gmail_extra">the API requires =
static member function &#39;main_context()&#39; because in &#39;main()&#39;=
 (or in top-level std::thread-fn)<br></div><div class=3D"gmail_extra">we do=
n&#39;t have a context at hand from which we switch to our desired context.=
<br></div><div class=3D"gmail_extra">in order to be equivalent to the seman=
tics of the other context&#39;, &#39;main_context()&#39; returns a context =
that refers to<br></div><div class=3D"gmail_extra">the same type (maybe all=
ocated using &#39;schwarz pointers&#39; etc.)<br><br><div>void bar(  contex=
t currctx2, void * vp) {<br>=C2=A0=C2=A0 context mctx =3D ( context *) vp;<=
br></div><div>=C2=A0=C2=A0 ( * mctx)( currctx2);<br></div><div>}<br><br></d=
iv><div>void foo( context currctx1, void * vp) {<br></div><div>=C2=A0=C2=A0=
 context ctx2( bar);<br></div><div>=C2=A0=C2=A0 ctx2( currctx1, vp);<br>}<b=
r><br></div><div><div>context mctx =3D context::main_context();<br></div>co=
ntext ctx1( foo);<br></div>ctx1( mctx, &amp; mctx);<br></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 />

--001a1140978c7c8482052310755a--

.
