1#ifndef ORIGINAL_COROUTINES_H
2#define ORIGINAL_COROUTINES_H
56 template<
typename TYPE>
61 using handle = std::coroutine_handle<promise_type>;
75 std::exception_ptr
e_;
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>
323template <
typename TYPE>
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>
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();
Input iterator for generator range-based operations.
Definition coroutines.h:133
TYPE operator*()
Dereferences iterator to get current value.
Definition coroutines.h:324
iterator & operator++()
Advances iterator to next value.
Definition coroutines.h:313
bool operator!=(const iterator &other) const
Checks iterator inequality.
Definition coroutines.h:332
bool operator==(const iterator &other) const
Checks iterator equality.
Definition coroutines.h:338
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.
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
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
Exception for null pointer dereference attempts.
Definition error.h:245
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:1353
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.
Implements the coroutine promise interface for generator.
Definition coroutines.h:72
void rethrow_if_exception() const
Re-throws any captured exception.
Definition coroutines.h:292
static void return_void()
Handles coroutine completion without value.
Definition coroutines.h:273
void unhandled_exception()
Captures exceptions thrown from coroutine.
Definition coroutines.h:286
bool initial_staus
Tracks if coroutine has started execution.
Definition coroutines.h:73
generator get_return_object()
Creates the generator object from this promise.
Definition coroutines.h:255
static std::suspend_always final_suspend() noexcept
Defines final suspension behavior.
Definition coroutines.h:267
static std::suspend_always initial_suspend()
Defines initial suspension behavior.
Definition coroutines.h:261
std::suspend_always yield_value(TYPE value)
Handles value yielding from coroutine.
Definition coroutines.h:276
std::exception_ptr e_
Captured exceptions for propagation.
Definition coroutines.h:75
alternative< TYPE > value_
Storage for the current yielded value.
Definition coroutines.h:74