Topic: Coroutine defect: impossible to implement


Author: TONGARI J <tongari95@gmail.com>
Date: Sun, 26 Jul 2015 01:14:55 -0700 (PDT)
Raw View
------=_Part_2102_1973164972.1437898495097
Content-Type: multipart/alternative;
 boundary="----=_Part_2103_543712293.1437898495097"

------=_Part_2103_543712293.1437898495097
Content-Type: text/plain; charset=UTF-8

Hi,

The changes in N4402 relative to N4286:

   - changing requirements on the return type of initial_suspend() and
   final_suspend() to be lexically convertible to bool;
   - changing requirements on the return type of yield_value() to be either
   of a void type or a type lexically convertible to bool;

For initial_suspend/final_suspend, I think it's fine, however, for yield_value,
it's now impossible to implement recursive_generator, consider this:

recursive_generator<int> recursive(...)
{
    try
    {
        yield recursive(...); // [A]
    }
    catch (...) // [B]
    {
        ...
    }
}

If [A] throws an exception, we should be able to catch it at [B] in the
parent coroutine, to make this work, the exception thrown in the child
coroutine should be rethrown after the parent is resumed (i.e. await_resume),
but the new proposal restricted `yield_value` to return either of void a
type lexically convertible to bool, this kills the possibility of
recursive_generator, we still need `yield_value` to return an Awaitable for
that.

What am I missing?

--

---
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_2103_543712293.1437898495097
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi,</div><div><br></div> The changes in N4402 relativ=
e to N4286:<br><ul><li>changing requirements on the return type of initial_=
suspend() and final_suspend() to be lexically convertible to bool;<br></li>=
<li>changing requirements on the return type of yield_value() to be either =
of a void type or a type lexically convertible to bool;<br></li></ul><div><=
span style=3D"line-height: 17px;">For=C2=A0</span><span style=3D"line-heigh=
t: 17px;">initial_suspend/</span><span style=3D"line-height: 17px;">final_s=
uspend, I think it&#39;s fine, however, for=C2=A0</span><span style=3D"line=
-height: 17px;">yield_value, it&#39;s now=C2=A0impossible to implement recu=
rsive_generator, consider this:</span></div><div><span style=3D"line-height=
: 17px;"><br></span></div><div class=3D"prettyprint" style=3D"border: 1px s=
olid rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, =
250, 250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">recursive_generator</s=
pan><span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;int&gt;</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> recursive</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">(...)</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">try</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">yield</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> recursive</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">(...);</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #800;" class=3D"styled-by-prettify">// [A]</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">catch</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(...)</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=
=3D"styled-by-prettify">// [B]</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">...</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span></div></code></div><div><span style=3D"line-he=
ight: 17px;"><br></span></div><div><span style=3D"line-height: 17px;">If [A=
] throws an exception, we should be able to catch it at [B] in the parent c=
oroutine, to make this work, the=C2=A0</span><span style=3D"line-height: 17=
px;">exception thrown in the child=C2=A0</span><span style=3D"line-height: =
17px;">coroutine</span><span style=3D"line-height: 17px;">=C2=A0should be r=
ethrown after </span><span style=3D"line-height: 17px;">the parent is resum=
ed (i.e. await_</span><span style=3D"line-height: 17px;">resume), but the n=
ew proposal restricted `</span><span style=3D"line-height: 17px;">yield_val=
ue` to return either of void a type lexically convertible to bool, this kil=
ls the possibility of=C2=A0</span><span style=3D"line-height: 17px;">recurs=
ive_generator</span><span style=3D"line-height: 17px;">, we still need=C2=
=A0</span><span style=3D"line-height: 17px;">`</span><span style=3D"line-he=
ight: 17px;">yield_value` to return an Awaitable for that.</span></div><div=
><span style=3D"line-height: 17px;"><br></span></div><div><span style=3D"li=
ne-height: 17px;">What am I missing?</span></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_2103_543712293.1437898495097--
------=_Part_2102_1973164972.1437898495097--

.