11#include <memory_resource>
15namespace hi::inline v1 {
36 return generator{handle_type::from_promise(*
this)};
39 value_type
const &value()
44 static std::suspend_never initial_suspend()
noexcept
49 static std::suspend_always final_suspend()
noexcept
54 std::suspend_always yield_value(value_type
const &value)
noexcept
60 std::suspend_always yield_value(value_type &&value)
noexcept
66 void return_void()
noexcept {}
69 void await_transform() =
delete;
71 void unhandled_exception()
noexcept
78 if (
auto ptr = std::exchange(_exception,
nullptr)) {
84 std::optional<value_type> _value = {};
88 using handle_type = std::coroutine_handle<promise_type>;
92 value_proxy(value_type
const &value) noexcept : _value(value) {}
94 value_type
const &operator*()
const noexcept
107 using difference_type = ptrdiff_t;
108 using value_type = std::remove_cv_t<value_type>;
113 explicit iterator(handle_type coroutine) : _coroutine{coroutine} {}
119 hi_axiom(not at_end());
121 _coroutine.promise().rethrow();
128 hi_axiom(not at_end());
130 _coroutine.promise().rethrow();
138 hi_axiom(not at_end());
139 return _coroutine.promise().value();
142 value_type
const *operator->() const noexcept
144 hi_axiom(not at_end());
148 [[nodiscard]]
bool at_end() const noexcept
150 return (not _coroutine) or _coroutine.done();
155 [[nodiscard]]
bool operator==(std::default_sentinel_t)
const noexcept
161 handle_type _coroutine;
164 explicit generator(handle_type coroutine) : _coroutine(coroutine) {}
166 generator() =
default;
170 _coroutine.destroy();
174 generator(
const generator &) =
delete;
175 generator &operator=(
const generator &) =
delete;
177 generator(generator &&other) noexcept : _coroutine{std::exchange(other._coroutine, {})}
181 generator &operator=(generator &&other)
noexcept
183 hi_return_on_self_assignment(other);
185 _coroutine.destroy();
187 _coroutine = std::exchange(other._coroutine, {});
200 std::default_sentinel_t
end()
206 handle_type _coroutine;
This file includes functions for manipulating parameter-packs.
A return value for a generator-function.
Definition generator.hpp:28
iterator begin()
Start the generator-function and return an iterator.
Definition generator.hpp:193
std::default_sentinel_t end()
Return a sentinal for the iterator.
Definition generator.hpp:200
Definition generator.hpp:32
Definition generator.hpp:90
A forward iterator which iterates through values co_yieled by the generator-function.
Definition generator.hpp:105
bool operator==(std::default_sentinel_t) const noexcept
Check if the generator-function has finished.
Definition generator.hpp:155
iterator & operator++()
Resume the generator-function.
Definition generator.hpp:117
value_type const & operator*() const
Retrieve the value co_yielded by the generator-function.
Definition generator.hpp:136
Definition concepts.hpp:36
Definition concepts.hpp:39
T current_exception(T... args)
T rethrow_exception(T... args)