Boost logo

Boost :

From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2023-08-18 20:40:41


Hi Klemens,
I have another question regarding the generator.
I think the initial examples in the dcs for `generator` are too simplistic,
because the caller seems to already know how many times it is allowed to
co_await on the Awaitable. I tried it with a loop, where I use the explicit
conversion to bool to check when to break the iteration:

```
async::generator<std::string> worker(int limit)
{
    for (int i = 0; i < limit; ++i) {
        co_yield std::format("--{}--", i);
    }
}

async::main co_main(int argc, char* argv[])
{
    try {
        auto w = worker(3);
        while (w) {
            std::cout << co_await w << std::endl;
        }
    }
    catch (std::exception const& e) {
        std::cout << "ERR: " << e.what() << std::endl;
    }
}
```

But I am surprised that this construct ends with throwing an exception.
Am I doing something wrong?

Regards,
&rzej;


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk