|
Boost Users : |
Subject: Re: [Boost-users] Using Coroutines in the Visitor Pattern (use-case: BGL event visitor)
From: Nat Goodspeed (nat_at_[hidden])
Date: 2016-01-19 16:24:33
On Tue, Jan 19, 2016 at 6:02 AM, alex <alexhighviz_at_[hidden]> wrote:
>>> I can see in the documentation that the constructor enters the coroutine-
>>function, but it is not clear to me why. Would it not have been neater if
>>this was avoided?
>>With a pull_type coroutine, the expectation is that every time it
>>suspends (until it exits), it has produced a value for its consumer.
>>If the coroutine constructor didn't enter the coroutine-function, the
>>first invocation would have to be a special case.
> To me it seems that the first invocation may either exit or produce a value,
> just as each subsequent invocation. I don't see the why the first invocation
> is special.
Okay, so let's consider this snippet:
boost::coroutines::asymmetric_coroutine<int>::pull_type source(somefunc);
while (source)
{
std::cout << source.get() << std::endl;
source();
}
Suppose the asymmetric_coroutine<int>::pull_type constructor did not
enter somefunc(). How would the operator bool() call invoked by the
while statement know whether there's a value?
>> Even if that were
>>desirable, how could you distinguish the case in which the coroutine
>>produces zero values?
> That case would just never enter the while loop.
But again: how do we know?
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net