1#ifndef ORIGINAL_COROUTINES_H
2#define ORIGINAL_COROUTINES_H
56 template<
typename TYPE>
65 bool initial_staus =
false;
67 std::exception_ptr e_;
80 static std::suspend_always initial_suspend();
87 static std::suspend_always final_suspend()
noexcept;
92 static void return_void();
100 std::suspend_always yield_value(
TYPE value);
105 void unhandled_exception();
111 void rethrow_if_exception()
const;
147 iterator& operator++();
171 using handle = std::coroutine_handle<promise_type>;
253template <
typename TYPE>
257 return generator{handle::from_promise(*
this)};
260template <
typename TYPE>
263 return std::suspend_always{};
266template <
typename TYPE>
269 return std::suspend_always{};
272template <
typename TYPE>
275template <
typename TYPE>
278 if (!this->initial_staus) {
279 this->initial_staus =
true;
281 this->value_ = std::move(value);
282 return std::suspend_always{};
285template <
typename TYPE>
288 this->e_ = std::current_exception();
291template <
typename TYPE>
295 std::rethrow_exception(this->e_);
298template <
typename TYPE>
301template <
typename TYPE>
311template <
typename TYPE>
317 if (
auto gen_next = this->gen_->next(); !gen_next) {
323template <
typename TYPE>
327 throw nullPointerError(
"Dereferencing end iterator");
328 return *this->gen_->peek();
331template <
typename TYPE>
334 return !(*
this == other);
337template <
typename TYPE>
340 if (this->end_ && other.end_)
342 if (this->end_ != other.end_)
344 return this->gen_ == other.gen_;
347template <
typename TYPE>
350 this->handle_ =
other.handle_;
351 other.handle_ =
nullptr;
354template <
typename TYPE>
358 if (
this == &
other) {
363 this->handle_.destroy();
366 this->handle_ =
other.handle_;
367 other.handle_ =
nullptr;
371template <
typename TYPE>
374template <
typename TYPE>
378 return iterator{
this};
381template <
typename TYPE>
388template <
typename TYPE>
391 return this->handle_.promise().initial_staus;
394template <
typename TYPE>
397 return this->handle_ && !this->handle_.done();
400template <
typename TYPE>
403 return this->handle_.promise().value_;
406template <
typename TYPE>
410 if (!this->hasNext())
413 this->handle_.resume();
414 this->handle_.promise().rethrow_if_exception();
416 if (!this->hasNext())
419 return this->handle_.promise().value_;
422template <
typename TYPE>
426 this->handle_.destroy();
Lazy sequence generator using C++20 coroutines.
Definition coroutines.h:57
iterator begin()
Gets begin iterator for range-based operations.
Definition coroutines.h:376
generator(const generator &)=delete
Copy constructor deleted.
~generator()
Destructor cleans up coroutine resources.
Definition coroutines.h:423
generator()=default
Default constructor creates empty generator.
generator & operator=(const generator &)=delete
Copy assignment deleted.
promise_type promise_type
Promise type for coroutine protocol.
Definition coroutines.h:176
alternative< TYPE > peek() const
Peeks at current value without advancing.
Definition coroutines.h:401
bool hasNext() const
Checks if generator has more values.
Definition coroutines.h:395
bool launched() const
Checks if coroutine has been launched.
Definition coroutines.h:389
static iterator end()
Gets end iterator for range-based operations.
Definition coroutines.h:383
iterator iterator
Iterator type for range operations.
Definition coroutines.h:177
alternative< TYPE > next()
Advances generator and gets next value.
Definition coroutines.h:408
Namespace for coroutine-related utilities and generator implementation.
Definition coroutines.h:37
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
Main namespace for the project Original.
Definition algorithms.h:21
time::duration operator*(const time::duration &d, time::time_val_type factor)
Definition zeit.h:1319
bool operator!=(const autoPtr< T, DER, DEL > &ptr, const std::nullptr_t &null)
Inequality comparison with nullptr.
Definition autoPtr.h:755
bool operator==(const autoPtr< T, DER, DEL > &ptr, const std::nullptr_t &null)
Equality comparison with nullptr.
Definition autoPtr.h:750
Standard namespace extensions for original::alternative.
Definition allocator.h:351
Type-safe optional value container.