cortex 0.0.1
Loading...
Searching...
No Matches
cortex::Generator< T > Class Template Referencefinal

A stackful generator that yields values of type T. More...

#include <generator.hpp>

Classes

struct  Builder
 A builder class for creating Generator instances with custom configuration. More...
 
class  YieldContext
 Context provided to the generator body to yield values. More...
 

Public Types

using Body = fu2::unique_function< void(YieldContext &)>
 

Public Member Functions

 Generator (const Generator &)=delete
 
 Generator (Generator &&) noexcept=default
 
Generatoroperator= (const Generator &)=delete
 
Generatoroperator= (Generator &&) noexcept=default
 
 ~Generator ()=default
 
bool IsDone () const noexcept
 Checks if the generator has finished its execution.
 
bool Next ()
 Resumes execution until a value is yielded or the generator completes.
 
DetachValue ()
 Moves out the current value and clears it.
 

Static Public Member Functions

static Generator Make (Body body, std::size_t stack_size_bytes=262144, MemoryResourceSharedPtr resource=GetDefaultMemoryResource())
 Creates a new generator with the specified body and stack size.
 

Detailed Description

template<typename T>
class cortex::Generator< T >

A stackful generator that yields values of type T.

Member Typedef Documentation

◆ Body

template<typename T >
using cortex::Generator< T >::Body = fu2::unique_function<void(YieldContext&)>

Constructor & Destructor Documentation

◆ Generator() [1/2]

template<typename T >
cortex::Generator< T >::Generator ( const Generator< T > &  )
delete

◆ Generator() [2/2]

template<typename T >
cortex::Generator< T >::Generator ( Generator< T > &&  )
defaultnoexcept

◆ ~Generator()

template<typename T >
cortex::Generator< T >::~Generator ( )
default

Member Function Documentation

◆ DetachValue()

template<typename T >
T cortex::Generator< T >::DetachValue ( )
inline

Moves out the current value and clears it.

Returns
The yielded value.
Exceptions
std::logic_errorif no value is available.

◆ IsDone()

template<typename T >
bool cortex::Generator< T >::IsDone ( ) const
inlinenoexcept

Checks if the generator has finished its execution.

Returns
true if execution is complete, false otherwise.

◆ Make()

template<typename T >
static Generator cortex::Generator< T >::Make ( Body  body,
std::size_t  stack_size_bytes = 262144,
MemoryResourceSharedPtr  resource = GetDefaultMemoryResource() 
)
inlinestatic

Creates a new generator with the specified body and stack size.

Parameters
bodyThe function or callable to execute within the generator.
stack_size_bytesThe size of the stack to allocate for the coroutine (default: 256KB).
resourceThe memory resource to use for stack and implementation allocation (default: GetDefaultMemoryResource()).
Returns
A Generator instance.
Exceptions
std::invalid_argumentif the body is empty or stack_size_bytes is 0 or resource is null.

◆ Next()

template<typename T >
bool cortex::Generator< T >::Next ( )
inline

Resumes execution until a value is yielded or the generator completes.

Returns
true if a value was yielded, false if the generator is done.

◆ operator=() [1/2]

template<typename T >
Generator & cortex::Generator< T >::operator= ( const Generator< T > &  )
delete

◆ operator=() [2/2]

template<typename T >
Generator & cortex::Generator< T >::operator= ( Generator< T > &&  )
defaultnoexcept

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