33 return generator{handle_type::from_promise(*
this)};
36 value_type
const &value() {
40 static std::suspend_always initial_suspend()
noexcept
45 static std::suspend_always final_suspend()
noexcept
50 std::suspend_always yield_value(value_type
const &value)
noexcept
56 std::suspend_always yield_value(value_type &&value)
noexcept
62 void return_void()
noexcept {}
65 void await_transform() =
delete;
67 [[noreturn]]
static void unhandled_exception()
73 std::optional<value_type> _value;
76 using handle_type = std::coroutine_handle<promise_type>;
78 explicit generator(handle_type coroutine) : _coroutine(coroutine) {}
88 generator(
const generator &) =
delete;
89 generator &operator=(
const generator &) =
delete;
91 generator(generator &&other) noexcept : _coroutine{other._coroutine}
93 tt_axiom(&other !=
this);
94 other._coroutine = {};
97 generator &operator=(generator &&other)
noexcept
99 tt_return_on_self_assignment(other);
101 _coroutine.destroy();
103 _coroutine = other._coroutine;
104 other._coroutine = {};
112 explicit iterator(handle_type coroutine) : _coroutine{coroutine} {}
126 return _coroutine.promise().value();
133 return !_coroutine || _coroutine.done();
138 handle_type _coroutine;
153 std::default_sentinel_t
end()
159 handle_type _coroutine;
A return value for a generator-function.
Definition coroutine.hpp:25
std::default_sentinel_t end()
Return a sentinal for the iterator.
Definition coroutine.hpp:153
iterator begin()
Start the generator-function and return an iterator.
Definition coroutine.hpp:143
Definition coroutine.hpp:29
A forward iterator which iterates through values co_yieled by the generator-function.
Definition coroutine.hpp:110
bool operator==(std::default_sentinel_t) const
Check if the generator-function has finished.
Definition coroutine.hpp:131
iterator & operator++()
Resume the generator-function.
Definition coroutine.hpp:116
value_type const & operator*() const
Retrieve the value co_yielded by the generator-function.
Definition coroutine.hpp:124