ORIGINAL
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
original::coroutine::generator< TYPE > Class Template Reference

Lazy sequence generator using C++20 coroutines. More...

#include <coroutines.h>

Collaboration diagram for original::coroutine::generator< TYPE >:
Collaboration graph

Public Types

using promise_type = promise_type
 Promise type for coroutine protocol.
 
using iterator = iterator
 Iterator type for range operations.
 

Public Member Functions

 generator (const generator &)=delete
 Copy constructor deleted.
 
generatoroperator= (const generator &)=delete
 Copy assignment deleted.
 
 generator (generator &&other) noexcept
 Move constructor transfers coroutine ownership.
 
generatoroperator= (generator &&other) noexcept
 Move assignment operator transfers coroutine ownership.
 
 generator ()=default
 Default constructor creates empty generator.
 
 generator (handle h)
 Constructs generator from coroutine handle.
 
iterator begin ()
 Gets begin iterator for range-based operations.
 
bool launched () const
 Checks if coroutine has been launched.
 
bool hasNext () const
 Checks if generator has more values.
 
alternative< TYPEpeek () const
 Peeks at current value without advancing.
 
alternative< TYPEnext ()
 Advances generator and gets next value.
 
 ~generator ()
 Destructor cleans up coroutine resources.
 

Static Public Member Functions

static iterator end ()
 Gets end iterator for range-based operations.
 

Detailed Description

template<typename TYPE>
class original::coroutine::generator< TYPE >

Lazy sequence generator using C++20 coroutines.

Template Parameters
TYPEType of values generated by the coroutine

Implements the coroutine promise protocol to create generators that can yield sequences of values. Supports range-based for loops, manual iteration, and exception propagation.

The generator maintains the following states:

Note
Generators are move-only types to prevent accidental copying of coroutine state.
Iterators become invalid when the generator is destroyed or moved.

Constructor & Destructor Documentation

◆ generator() [1/2]

template<typename TYPE >
original::coroutine::generator< TYPE >::generator ( generator< TYPE > &&  other)
noexcept

Move constructor transfers coroutine ownership.

Parameters
otherGenerator to move from
Note
Source generator becomes empty after move

◆ generator() [2/2]

template<typename TYPE >
original::coroutine::generator< TYPE >::generator ( handle  h)
explicit

Constructs generator from coroutine handle.

Parameters
hCoroutine handle to manage

◆ ~generator()

Destructor cleans up coroutine resources.

Note
Automatically destroys coroutine handle

Member Function Documentation

◆ begin()

Gets begin iterator for range-based operations.

Returns
Iterator positioned at first value
Note
Resumes coroutine to get first value

◆ end()

Gets end iterator for range-based operations.

Returns
End iterator marker

◆ hasNext()

template<typename TYPE >
bool original::coroutine::generator< TYPE >::hasNext ( ) const

Checks if generator has more values.

Returns
true if next() would return a value

◆ launched()

template<typename TYPE >
bool original::coroutine::generator< TYPE >::launched ( ) const

Checks if coroutine has been launched.

Returns
true if coroutine has started execution

◆ next()

Advances generator and gets next value.

Returns
optional containing next value if available
Note
Resumes coroutine execution and may throw exceptions

◆ operator=()

template<typename TYPE >
original::coroutine::generator< TYPE > & original::coroutine::generator< TYPE >::operator= ( generator< TYPE > &&  other)
noexcept

Move assignment operator transfers coroutine ownership.

Parameters
otherGenerator to move from
Returns
Reference to this generator
Note
Destroys current coroutine handle before transfer

◆ peek()

Peeks at current value without advancing.

Returns
optional containing current value if available
Note
Does not resume coroutine or change state

The documentation for this class was generated from the following file: