|
Boost : |
Subject: Re: [boost] [coroutine] new versions
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2012-10-11 05:22:48
-------- Original-Nachricht --------
> Datum: Thu, 11 Oct 2012 08:20:38 +0200
> Von: "Oliver Kowalke" <oliver.kowalke_at_[hidden]>
> An: boost_at_[hidden], boost_at_[hidden]
> Betreff: Re: [boost] [coroutine] new versions
> > I would
> > like to see the coroutine-function with a void return type. Or have an
> > option for that.
>
> I've had such a version but I dropped it because for detecting the
> completeness of the coroutine would require an extra jump (return from last
> jump-function and calling return in the coroutine-fn).
> And this makes the implementation for iterators very painful:
>
> void fn( coroutine<void(int)> & c) {
> c( 1);
> c( 2);
> }
>
> The iterator would be required to be incremented three times. And
> std::distance would return 3 instead of 2.
If coroutine-fn is required to return void - we could detect the last 'caller_t::operator()' from coroutine-fn if we require to test the coroutine after each call:
typedef coroutine< int() > coro1_t;
typedef coroutine< void(int) > coro2_t;
void fn( coro2_t & c) {
c( 1);
c( 2);
}
coro1_t c( fn);
while ( c) {
c();
if ( ! c) break;
int res = c.get();
}
Oliver
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk