11#include <memory_resource>
14#include "utility/module.hpp"
16namespace hi::inline
v1 {
33 static_assert(not std::is_reference_v<value_type>);
34 static_assert(not std::is_const_v<value_type>);
40 return generator{handle_type::from_promise(*
this)};
43 value_type
const& value()
const noexcept
49 static std::suspend_never initial_suspend()
noexcept
54 static std::suspend_always final_suspend()
noexcept
59 std::suspend_always yield_value(value_type
const& value)
noexcept
65 std::suspend_always yield_value(value_type&& value)
noexcept
71 void return_void()
noexcept {}
74 void await_transform() =
delete;
76 void unhandled_exception()
noexcept
83 if (
auto ptr = std::exchange(_exception,
nullptr)) {
89 std::optional<value_type> _value = {};
93 using handle_type = std::coroutine_handle<promise_type>;
97 value_proxy(value_type
const& value) noexcept : _value(value) {}
99 value_type
const& operator*()
const noexcept
112 using difference_type = ptrdiff_t;
113 using value_type = std::decay_t<value_type>;
114 using pointer = value_type
const *;
118 explicit const_iterator(handle_type coroutine) : _coroutine{coroutine} {}
126 _coroutine.promise().rethrow();
132 auto tmp =
value_proxy(_coroutine.promise().value());
135 _coroutine.promise().rethrow();
141 decltype(
auto)
operator*()
const
144 return _coroutine.promise().value();
147 pointer *operator->() const noexcept
153 [[nodiscard]]
bool at_end() const noexcept
155 return not _coroutine or _coroutine.done();
160 [[nodiscard]]
bool operator==(std::default_sentinel_t)
const noexcept
166 handle_type _coroutine;
169 explicit generator(handle_type coroutine) : _coroutine(coroutine) {}
171 generator() =
default;
175 _coroutine.destroy();
179 generator(
const generator&) =
delete;
180 generator& operator=(
const generator&) =
delete;
182 generator(generator&& other) noexcept : _coroutine{std::exchange(
other._coroutine, {})} {}
184 generator& operator=(generator&& other)
noexcept
186 hi_return_on_self_assignment(other);
188 _coroutine.destroy();
190 _coroutine = std::exchange(
other._coroutine, {});
210 std::default_sentinel_t
end()
const
217 std::default_sentinel_t
cend()
const
223 handle_type _coroutine;
229 using value_type = T&;
235 return generator{handle_type::from_promise(*
this)};
238 value_type value()
const noexcept
245 static std::suspend_never initial_suspend()
noexcept
250 static std::suspend_always final_suspend()
noexcept
255 std::suspend_always yield_value(value_type value)
noexcept
261 void return_void()
noexcept {}
264 void await_transform() =
delete;
266 void unhandled_exception()
noexcept
273 if (
auto ptr = std::exchange(_exception,
nullptr)) {
279 std::remove_reference_t<value_type> *_value =
nullptr;
283 using handle_type = std::coroutine_handle<promise_type>;
287 value_proxy(value_type value) noexcept : _value(
std::addressof(value)) {}
289 value_type operator*()
const noexcept
295 std::remove_reference_t<value_type> *_value;
300 class const_iterator {
302 using difference_type = ptrdiff_t;
303 using value_type = std::decay_t<value_type>;
304 using pointer = value_type
const *;
308 explicit const_iterator(handle_type coroutine) : _coroutine{coroutine} {}
316 _coroutine.promise().rethrow();
320 value_proxy operator++(
int)
322 auto tmp = value_proxy(_coroutine.promise().value());
325 _coroutine.promise().rethrow();
331 decltype(
auto)
operator*()
const
334 return _coroutine.promise().value();
337 pointer *operator->() const noexcept
343 [[nodiscard]]
bool at_end() const noexcept
345 return not _coroutine or _coroutine.done();
350 [[nodiscard]]
bool operator==(std::default_sentinel_t)
const noexcept
356 handle_type _coroutine;
359 explicit generator(handle_type coroutine) : _coroutine(coroutine) {}
361 generator() =
default;
365 _coroutine.destroy();
369 generator(
const generator&) =
delete;
370 generator& operator=(
const generator&) =
delete;
372 generator(generator&& other) noexcept : _coroutine{std::exchange(
other._coroutine, {})} {}
374 generator& operator=(generator&& other)
noexcept
376 hi_return_on_self_assignment(other);
378 _coroutine.destroy();
380 _coroutine = std::exchange(
other._coroutine, {});
388 return const_iterator{_coroutine};
395 return const_iterator{_coroutine};
400 std::default_sentinel_t
end()
const
407 std::default_sentinel_t
cend()
const
413 handle_type _coroutine;
This file includes functions for manipulating parameter-packs.
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238
@ other
The gui_event does not have associated data.
DOXYGEN BUG.
Definition algorithm.hpp:13
A return value for a generator-function.
Definition generator.hpp:29
std::default_sentinel_t end() const
Return a sentinel for the iterator.
Definition generator.hpp:210
const_iterator cbegin() const
Start the generator-function and return an iterator.
Definition generator.hpp:203
std::default_sentinel_t cend() const
Return a sentinel for the iterator.
Definition generator.hpp:217
const_iterator begin() const
Start the generator-function and return an iterator.
Definition generator.hpp:196
Definition generator.hpp:36
Definition generator.hpp:95
A forward iterator which iterates through values co_yieled by the generator-function.
Definition generator.hpp:110
const_iterator & operator++()
Resume the generator-function.
Definition generator.hpp:122
bool operator==(std::default_sentinel_t) const noexcept
Check if the generator-function has finished.
Definition generator.hpp:160
std::default_sentinel_t cend() const
Return a sentinel for the iterator.
Definition generator.hpp:407
std::default_sentinel_t end() const
Return a sentinel for the iterator.
Definition generator.hpp:400
const_iterator begin() const
Start the generator-function and return an iterator.
Definition generator.hpp:386
const_iterator cbegin() const
Start the generator-function and return an iterator.
Definition generator.hpp:393
bool operator==(std::default_sentinel_t) const noexcept
Check if the generator-function has finished.
Definition generator.hpp:350
const_iterator & operator++()
Resume the generator-function.
Definition generator.hpp:312
Definition concepts.hpp:36
Definition concepts.hpp:39
T current_exception(T... args)
T rethrow_exception(T... args)