3#ifdef CXXITER_HAS_COROUTINE
25 using Handle = std::coroutine_handle<promise_type>;
29 std::exception_ptr exceptionPtr;
32 return Generator{Handle::from_promise(*
this)};
34 static std::suspend_always initial_suspend()
noexcept {
return {}; }
35 static std::suspend_always final_suspend()
noexcept {
return {}; }
36 std::suspend_always yield_value(T value)
noexcept {
41 void unhandled_exception() {
42 exceptionPtr = std::current_exception();
46 explicit Generator(
const Handle coroutine) : m_coroutine{coroutine} {}
50 m_coroutine.destroy();
54 Generator(
const Generator&) =
delete;
55 Generator& operator=(
const Generator&) =
delete;
57 Generator(Generator&& other) noexcept : m_coroutine{other.m_coroutine} {
58 other.m_coroutine = {};
60 Generator& operator=(Generator&& other)
noexcept {
62 other.m_coroutine = {};
67 if(m_coroutine && !m_coroutine.promise().currentItem.has_value()) {
69 if(m_coroutine.promise().exceptionPtr) {
70 std::rethrow_exception(m_coroutine.promise().exceptionPtr);
73 if(m_coroutine.done()) {
74 m_coroutine.destroy();
81 return std::move(m_coroutine.promise().currentItem);
89 concept GeneratorFunction = (std::invocable<T> && util::is_template_instance_v<std::invoke_result_t<T>, Generator>);
Generator that C++20 coroutines passed to CXXIter::IterApi::generateFrom() have to return....
Container that is used to pass elements through CXXIter's iterator pipelines.