32 return generator{handle_type::from_promise(*
this)};
35 value_type
const &value() {
39 static std::suspend_always initial_suspend()
noexcept
44 static std::suspend_always final_suspend()
noexcept
49 std::suspend_always yield_value(value_type
const &value)
noexcept
55 std::suspend_always yield_value(value_type &&value)
noexcept
61 void return_void()
noexcept {}
64 void await_transform() =
delete;
66 [[noreturn]]
static void unhandled_exception()
72 std::optional<value_type> _value;
75 using handle_type = std::coroutine_handle<promise_type>;
77 explicit generator(handle_type coroutine) : _coroutine(coroutine) {}
87 generator(
const generator &) =
delete;
88 generator &operator=(
const generator &) =
delete;
90 generator(generator &&other) noexcept : _coroutine{other._coroutine}
92 other._coroutine = {};
95 generator &operator=(generator &&other)
noexcept
101 _coroutine = other._coroutine;
102 other._coroutine = {};
111 explicit iterator(handle_type coroutine) : _coroutine{coroutine} {}
125 return _coroutine.promise().value();
132 return !_coroutine || _coroutine.done();
137 handle_type _coroutine;
152 std::default_sentinel_t
end()
158 handle_type _coroutine;
A return value for a generator-function.
Definition coroutine.hpp:24
std::default_sentinel_t end()
Return a sentinal for the iterator.
Definition coroutine.hpp:152
iterator begin()
Start the generator-function and return an iterator.
Definition coroutine.hpp:142
Definition coroutine.hpp:28
A forward iterator which iterates through values co_yieled by the generator-function.
Definition coroutine.hpp:109
bool operator==(std::default_sentinel_t) const
Check if the generator-function has finished.
Definition coroutine.hpp:130
iterator & operator++()
Resume the generator-function.
Definition coroutine.hpp:115
value_type const & operator*() const
Retrieve the value co_yielded by the generator-function.
Definition coroutine.hpp:123