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::decay_t<value_type>;
109 using pointer = value_type
const *;
113 explicit const_iterator(handle_type coroutine) : _coroutine{coroutine} {}
121 _coroutine.promise().rethrow();
130 _coroutine.promise().rethrow();
139 return _coroutine.promise().value();
142 pointer *operator->() const noexcept
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, {});
207 std::default_sentinel_t
end()
const
214 std::default_sentinel_t
cend()
const
220 handle_type _coroutine;
Utilities to assert and bound check.
#define hi_axiom(expression)
Specify an axiom; an expression that is true.
Definition assert.hpp:133
This file includes functions for manipulating parameter-packs.
DOXYGEN BUG.
Definition algorithm.hpp:15
A return value for a generator-function.
Definition generator.hpp:28
std::default_sentinel_t end() const
Return a sentinel for the iterator.
Definition generator.hpp:207
const_iterator cbegin() const
Start the generator-function and return an iterator.
Definition generator.hpp:200
std::default_sentinel_t cend() const
Return a sentinel for the iterator.
Definition generator.hpp:214
const_iterator begin() const
Start the generator-function and return an iterator.
Definition generator.hpp:193
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
const_iterator & operator++()
Resume the generator-function.
Definition generator.hpp:117
reference & operator*() const
Retrieve the value co_yielded by the generator-function.
Definition generator.hpp:136
bool operator==(std::default_sentinel_t) const noexcept
Check if the generator-function has finished.
Definition generator.hpp:155
Definition concepts.hpp:36
Definition concepts.hpp:39
T current_exception(T... args)
T rethrow_exception(T... args)