CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::Generator< T >::Iterator Class Referencefinal

An iterator type that allows the caller to iterate over the results of a generator. More...

#include <CeresEngine/Foundation/Generator.hpp>

Public Types

using iterator_category = std::input_iterator_tag
 
using difference_type = std::ptrdiff_t
 
using value_type = typename Promise::Value
 
using reference = typename Promise::Reference
 
using pointer = typename Promise::Pointer
 

Public Member Functions

 Iterator () noexcept
 Iterator needs to be default-constructible to satisfy the Range concept.
 
 Iterator (CoroutineHandle coroutine) noexcept
 Creates a new Iterator object with an attached coroutine handle.
 
bool operator== (const Iterator &other) const noexcept
 Check if two iterator are equal.
 
bool operator!= (const Iterator &other) const noexcept
 Check if two iterator are not equal.
 
Iteratoroperator++ ()
 Resumes the generator coroutine and runs until the next value is yielded by it.
 
void operator++ (int)
 Resumes the generator coroutine and runs until the next value is yielded by it.
 
reference operator* () const noexcept
 Dereferences the iterator and returns a reference to the last yielded value.
 
pointer operator-> () const noexcept
 Dereferences the iterator and returns a pointer to the last yielded value.
 

Private Attributes

CoroutineHandle mCoroutine = nullptr
 The coroutine handle instance.
 

Detailed Description

template<typename T>
class CeresEngine::Generator< T >::Iterator

An iterator type that allows the caller to iterate over the results of a generator.

Member Typedef Documentation

◆ difference_type

template<typename T >
using CeresEngine::Generator< T >::Iterator::difference_type = std::ptrdiff_t

◆ iterator_category

template<typename T >
using CeresEngine::Generator< T >::Iterator::iterator_category = std::input_iterator_tag

◆ pointer

template<typename T >
using CeresEngine::Generator< T >::Iterator::pointer = typename Promise::Pointer

◆ reference

template<typename T >
using CeresEngine::Generator< T >::Iterator::reference = typename Promise::Reference

◆ value_type

template<typename T >
using CeresEngine::Generator< T >::Iterator::value_type = typename Promise::Value

Constructor & Destructor Documentation

◆ Iterator() [1/2]

template<typename T >
CeresEngine::Generator< T >::Iterator::Iterator ( )
inlinenoexcept

Iterator needs to be default-constructible to satisfy the Range concept.

◆ Iterator() [2/2]

template<typename T >
CeresEngine::Generator< T >::Iterator::Iterator ( CoroutineHandle  coroutine)
inlineexplicitnoexcept

Creates a new Iterator object with an attached coroutine handle.

Parameters
coroutineThe coroutine handle

Member Function Documentation

◆ operator!=()

template<typename T >
bool CeresEngine::Generator< T >::Iterator::operator!= ( const Iterator other) const
inlinenoexcept

Check if two iterator are not equal.

See operator== for more details.

Parameters
otherThe iterator to check against
Returns
true if the generator has reached the end.

◆ operator*()

template<typename T >
reference CeresEngine::Generator< T >::Iterator::operator* ( ) const
inlinenoexcept

Dereferences the iterator and returns a reference to the last yielded value.

Returns
A reference to the latest element

◆ operator++() [1/2]

template<typename T >
Iterator & CeresEngine::Generator< T >::Iterator::operator++ ( )
inline

Resumes the generator coroutine and runs until the next value is yielded by it.

Returns
*this.

◆ operator++() [2/2]

template<typename T >
void CeresEngine::Generator< T >::Iterator::operator++ ( int  )
inline

Resumes the generator coroutine and runs until the next value is yielded by it.

This only provided so that the iterator can implement the Range concept.

◆ operator->()

template<typename T >
pointer CeresEngine::Generator< T >::Iterator::operator-> ( ) const
inlinenoexcept

Dereferences the iterator and returns a pointer to the last yielded value.

Returns
A pointer to the latest element

◆ operator==()

template<typename T >
bool CeresEngine::Generator< T >::Iterator::operator== ( const Iterator other) const
inlinenoexcept

Check if two iterator are equal.

Since a generator sequence is potentially infinite, this only checks if there is any value remaining in the sequence.

Parameters
otherThe iterator to check against
Returns
true if there is at least one more value in the generator sequence.

Member Data Documentation

◆ mCoroutine

template<typename T >
CoroutineHandle CeresEngine::Generator< T >::Iterator::mCoroutine = nullptr
private

The coroutine handle instance.

This is used to resume the generator on operator++.


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