wwa-coro 0.0.1
Yet Another C++20 Coroutine Library
wwa::coro::generator< Result >::iterator Class Reference

An input iterator that produces values of type Result. More...

#include <generator.h>

+ Collaboration diagram for wwa::coro::generator< Result >::iterator:

Public Types

using difference_type = std::ptrdiff_t
 Difference between the addresses of any two elements in the controlled sequence.
 
using iterator_concept = std::input_iterator_tag
 The strongest iterator concept supported by the iterator.
 

Public Member Functions

 iterator () noexcept=default
 Default constructor.
 
promise_type::reference_type operator* () const
 Dereferences the iterator to obtain the current value.
 
iteratoroperator++ ()
 Advances the iterator to the next value.
 
void operator++ (int)
 Advances the iterator to the next value.
 
constexpr bool operator== (const iterator &other) const noexcept
 Compares two iterators.
 

Detailed Description

template<typename Result>
class wwa::coro::generator< Result >::iterator

An input iterator that produces values of type Result.

The iterator is used to traverse the values produced by the generator.

Example (range-based for):

//gen is an instance of sync_generator
for(auto value : gen) {
std::cout << *it << " ";
++it;
}

Example (manual iteration):

//gen is an instance of sync_generator
auto it = gen.begin();
while (it != gen.end()) {
std::cout << *it << " ";
++it;
}

Definition at line 224 of file generator.h.

Member Typedef Documentation

◆ difference_type

template<typename Result>
using wwa::coro::generator< Result >::iterator::difference_type = std::ptrdiff_t

Difference between the addresses of any two elements in the controlled sequence.

Note
This is required to satisfy the std::ranges::view concept. It does not really make sense for generators.

Definition at line 233 of file generator.h.

◆ iterator_concept

template<typename Result>
using wwa::coro::generator< Result >::iterator::iterator_concept = std::input_iterator_tag

The strongest iterator concept supported by the iterator.

Definition at line 227 of file generator.h.

Constructor & Destructor Documentation

◆ iterator()

template<typename Result>
wwa::coro::generator< Result >::iterator::iterator ( )
defaultnoexcept

Default constructor.

Constructs a sentinel iterator.

Note
This constructor is required to satisfy the std::ranges::view concept.

Member Function Documentation

◆ operator*()

template<typename Result>
promise_type::reference_type wwa::coro::generator< Result >::iterator::operator* ( ) const
inline

Dereferences the iterator to obtain the current value.

This method dereferences the iterator to obtain the current value produced by the generator.

Returns
An lvalue reference to the current value produced by the generator.
Exceptions
bad_result_accessAttempting to dereference the end of the generator.

Definition at line 321 of file generator.h.

◆ operator++() [1/2]

template<typename Result>
iterator & wwa::coro::generator< Result >::iterator::operator++ ( )
inline

Advances the iterator to the next value.

This method advances the iterator to the next value produced by the generator.

Returns
Reference to self (advanced iterator).
Exceptions
bad_result_accessAttempt to advance the iterator that has reached the end of the generator.

Definition at line 286 of file generator.h.

◆ operator++() [2/2]

template<typename Result>
void wwa::coro::generator< Result >::iterator::operator++ ( int )
inline

Advances the iterator to the next value.

This method advances the iterator to the next value produced by the generator. It is similar to the prefix increment operator but does not return a reference to the incremented iterator.

Note
Required to satisfy the std::ranges::view concept.

Definition at line 308 of file generator.h.

◆ operator==()

template<typename Result>
bool wwa::coro::generator< Result >::iterator::operator== ( const iterator & other) const
inlinenodiscardconstexprnoexcept

Compares two iterators.

Two iterators are equal if they point to the same coroutine or if they are both sentinel iterators.

Parameters
otherAnother iterator.
Returns
true if the iterators are equal, false otherwise.

Definition at line 269 of file generator.h.


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