Lumiera  0.pre.03
»edityourfreedom«
IterStateWrapper< T, ST > Class Template Reference

#include "lib/iter-adapter.hpp"

Description

template<typename T, class ST = T>
class lib::IterStateWrapper< T, ST >

Another Lumiera Forward Iterator building block, based on incorporating a state type right into the iterator.

Contrast this to IterAdapter, which refers to a managing container behind the scenes. Here, all of the state is assumed to live in the custom type embedded into this iterator, accessed and manipulated through a set of free functions, picked up through ADL.

Assumptions when building iterators based on IterStateWrapper
There is a custom state representation type ST.
  • default constructible
  • this default state represents the bottom (invalid) state.
  • copyable, because iterators are passed by value
  • this type needs to provide an iteration control API with the following operations
    1. checkPoint establishes if the given state element represents a valid state
    2. iterNext evolves this state by one step (sideeffect)
    3. yield realises the given state, yielding an element of result type T&
Template Parameters
Tnominal result type (maybe const, but without reference). The resulting iterator will yield a reference to this type T
STtype of the "state core", defaults to T. The resulting iterator will hold an instance of ST, which thus needs to be copyable and default constructible to the extent this is required for the iterator as such.
See also
IterExplorer an iterator monad built on top of IterStateWrapper
iter-explorer-test.hpp
iter-adaptor-test.cpp

Definition at line 338 of file iter-adapter.hpp.

Public Types

typedef T * pointer
 
typedef T & reference
 
typedef T value_type
 

Public Member Functions

 IterStateWrapper (ST &&initialState)
 
 IterStateWrapper (ST const &initialState)
 
 IterStateWrapper ()
 
bool empty () const
 
 ENABLE_USE_IN_STD_RANGE_FOR_LOOPS (IterStateWrapper)
 
bool isValid () const
 
 operator bool () const
 
reference operator* () const
 
IterStateWrapperoperator++ ()
 
pointer operator-> () const
 

Friends

template<class T1 , class T2 , class STX >
bool operator== (IterStateWrapper< T1, STX > const &, IterStateWrapper< T2, STX > const &)
 comparison is allowed to access state implementation core More...
 

Protected Member Functions

void __throw_if_empty () const
 
ST & stateCore ()
 allow derived classes to access state representation More...
 

Private Attributes

ST core_
 

Member Typedef Documentation

◆ pointer

typedef T* pointer

Definition at line 343 of file iter-adapter.hpp.

◆ reference

typedef T& reference

Definition at line 344 of file iter-adapter.hpp.

◆ value_type

typedef T value_type

Definition at line 345 of file iter-adapter.hpp.

Constructor & Destructor Documentation

◆ IterStateWrapper() [1/3]

IterStateWrapper ( ST &&  initialState)
inline

Definition at line 347 of file iter-adapter.hpp.

◆ IterStateWrapper() [2/3]

IterStateWrapper ( ST const &  initialState)
inline

Definition at line 351 of file iter-adapter.hpp.

◆ IterStateWrapper() [3/3]

IterStateWrapper ( )
inline

Definition at line 355 of file iter-adapter.hpp.

Member Function Documentation

◆ operator bool()

operator bool ( ) const
inlineexplicit

Definition at line 360 of file iter-adapter.hpp.

◆ operator*()

reference operator* ( ) const
inline

Definition at line 369 of file iter-adapter.hpp.

◆ operator->()

pointer operator-> ( ) const
inline

Definition at line 376 of file iter-adapter.hpp.

◆ operator++()

IterStateWrapper& operator++ ( )
inline

Definition at line 383 of file iter-adapter.hpp.

◆ isValid()

bool isValid ( ) const
inline

Definition at line 391 of file iter-adapter.hpp.

Referenced by Expander< SRC, RES >::invariant(), and lib::operator==().

+ Here is the caller graph for this function:

◆ empty()

bool empty ( ) const
inline

Definition at line 397 of file iter-adapter.hpp.

Referenced by lib::operator==().

+ Here is the caller graph for this function:

◆ stateCore()

ST& stateCore ( )
inlineprotected

allow derived classes to access state representation

Definition at line 407 of file iter-adapter.hpp.

◆ __throw_if_empty()

void __throw_if_empty ( ) const
inlineprotected

Definition at line 413 of file iter-adapter.hpp.

◆ ENABLE_USE_IN_STD_RANGE_FOR_LOOPS()

ENABLE_USE_IN_STD_RANGE_FOR_LOOPS ( IterStateWrapper< T, ST >  )

Member Data Documentation

◆ core_

ST core_
private

Definition at line 340 of file iter-adapter.hpp.

Referenced by lib::operator==().

Friends And Related Function Documentation

◆ operator==

bool operator== ( IterStateWrapper< T1, STX > const &  ,
IterStateWrapper< T2, STX > const &   
)
friend

comparison is allowed to access state implementation core

+ Inheritance diagram for IterStateWrapper< T, ST >:
+ Collaboration diagram for IterStateWrapper< T, ST >:

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