103#ifndef LIB_ITER_ADAPTER_H
104#define LIB_ITER_ADAPTER_H
129 lumiera::error::LUMIERA_ERROR_ITER_EXHAUST);
134#define ENABLE_USE_IN_STD_RANGE_FOR_LOOPS(ITER) \
135 friend ITER begin (ITER const& it){ return it; } \
136 friend ITER&& begin (ITER&& it) { return static_cast<ITER&&> (it); } \
137 friend ITER end (ITER const&) { return ITER(); } \
138 using iterator_category = std::input_iterator_tag; \
139 using difference_type = size_t;
142#define LIFT_PARENT_INCREMENT_OPERATOR(_BASECLASS_)\
146 _BASECLASS_::operator++(); \
154 using Yield =
decltype(std::declval<IT>().operator*());
158 using CoreYield =
decltype(std::declval<COR>().yield());
206 template<
class POS,
class CON>
233 operator bool()
const
323 _throwIterExhausted();
331 template<
class P1,
class P2,
class CX>
337 template<
class P1,
class P2,
class CON>
340 template<
class P1,
class P2,
class CON>
373 template<
class ST,
typename T =iter::CoreYield<ST>>
384 :
core_(
std::forward<ST>(initialState))
388 :
core_(initialState)
396 operator bool()
const
408 return core_.yield();
417 return &
core_.yield();
420 static_assert (!
sizeof(T),
421 "can not provide operator-> "
422 "since iterator pipeline generates a value");
436 return core_.checkPoint();
456 _throwIterExhausted();
465 template<
class STX,
class T1,
class T2>
472 template<
class ST,
class T1,
class T2>
480 template<
class ST,
class T1,
class T2>
484 return not (il == ir);
504 ,
"Lumiera Iterator required as source");
549 ,
"Adapted type must expose a »state core« API");
561 _throwIterExhausted();
568 template<
typename...ARGS>
570 : COR(
std::forward<ARGS>(init)...)
623 : CON(
std::forward<CON>(container))
634 return p_ != CON::end();
684 COR &
_core() {
return static_cast<COR&
> (*this); }
685 COR
const&
_core()
const {
return static_cast<COR const&
> (*this); }
692 _throwIterExhausted();
707 template<
typename...ARGS>
709 : COR(
std::forward<ARGS>(init)...)
721 explicit operator bool()
const {
return isValid(); }
726 return _core().yield();
733 return &
_core().yield();
735 static_assert (!
sizeof(COR),
736 "can not provide operator-> "
737 "since iterator pipeline generates a value");
750 return _core().checkPoint();
774 return not (il == ir);
834 operator bool()
const
867 return (
p_!= IT()) and (
p_ !=
e_);
891 _throwIterExhausted();
898 template<
class I1,
class I2>
901 template<
class I1,
class I2>
919 template<
typename INT>
937 :
i_(
std::forward<X>(start))
938 ,
e_(
std::forward<X>(end))
949 operator bool()
const
1004 _throwIterExhausted();
1014 template<
typename INT>
1016 eachNum (INT start = std::numeric_limits<INT>::min()
1017 ,INT end = std::numeric_limits<INT>::max())
1035 template<
template<
class,
class>
class Iter,
class TY,
class CON>
1079 operator bool()
const
1097 return i_.operator->();
1133 template<
class I1,
class I2>
1136 template<
class I1,
class I2>
Adapter to add sanity checks to a »state core«.
CheckedCore(ARGS &&...init)
blindly pass-down any argument...
decltype(auto) yield() const
void __throw_if_empty() const
CheckedCore & operator=(CheckedCore &&)=default
CheckedCore(CheckedCore const &)=default
COR TAG_CheckedCore_Raw
marker to allow unwrapping the raw core
CheckedCore(CheckedCore &&)=default
wrapper to expose values as const
ENABLE_USE_IN_STD_RANGE_FOR_LOOPS(ConstIter)
const IT::value_type value_type
IT const & getBase() const
access the wrapped implementation iterator
const IT::reference reference
reference operator*() const
IT i_
nested source iterator
const IT::pointer pointer
pointer operator->() const
Adapter to »piggy-back« a STL iterable container inline and expose it as »state core«.
decltype(auto) yield() const
ContainerCore(CON &&container)
Adapter for building an implementation of the »Lumiera Forward Iterator« concept.
meta::ValueTypeBinding< std::remove_pointer_t< POS > > _ValTrait
ENABLE_USE_IN_STD_RANGE_FOR_LOOPS(IterAdapter)
ConRef source()
allow derived classes to access backing container
IterAdapter & operator++()
void iterate()
ask the controlling container to yield the next position.
void _maybe_throw() const
const ConRef source() const
IterAdapter(CON src, POS const &startpos)
meta::RefTraits< CON >::Reference ConRef
_ValTrait::pointer pointer
bool check() const
ask the controlling container if this position is valid.
friend bool operator==(IterAdapter< P1, CX > const &, IterAdapter< P2, CX > const &)
comparison is allowed to access impl iterator
void resetPos(POS otherPos)
_ValTrait::value_type value_type
reference operator*() const
_ValTrait::reference reference
pointer operator->() const
Adapter to dress up an existing »Lumiera Forward Iterator« as »state core«.
IT::reference yield() const
Another Lumiera Forward Iterator building block, based on incorporating a state type as »*State Core*...
ENABLE_USE_IN_STD_RANGE_FOR_LOOPS(IterStateWrapper)
IterStateWrapper(ST &&initialState)
friend bool operator==(IterStateWrapper< STX, T1 > const &, IterStateWrapper< STX, T2 > const &)
comparison is allowed to access state implementation core
void __throw_if_empty() const
IterStateWrapper(ST const &initialState)
meta::RefTraits< T >::Pointer pointer
ST const & stateCore() const
meta::RefTraits< T >::Reference reference
ST & stateCore()
allow derived classes to access state representation
pointer operator->() const
IterStateWrapper & operator++()
meta::RefTraits< T >::Value value_type
Decorator-Adapter to make a »*State Core*« iterable as Lumiera Forward Iterator.
IterableDecorator & operator=(IterableDecorator &&)=default
YieldRes operator*() const
ENABLE_USE_IN_STD_RANGE_FOR_LOOPS(IterableDecorator)
void __throw_if_empty() const
iter::CoreYield< COR > YieldRes
IterableDecorator & operator++()
meta::RefTraits< YieldRes >::Reference reference
IterableDecorator(ARGS &&...init)
by default, pass anything down for initialisation of the core.
friend bool operator!=(IterableDecorator const &il, IterableDecorator const &ir)
meta::RefTraits< YieldRes >::Value value_type
COR const & _core() const
meta::RefTraits< YieldRes >::Pointer pointer
IterableDecorator(IterableDecorator &&)=default
IterableDecorator()=default
pointer operator->() const
IterableDecorator(IterableDecorator const &)=default
friend bool operator==(IterableDecorator const &il, IterableDecorator const &ir)
Supporting equality comparisons of equivalent iterators (equivalent state core)...
Enumerate all "numbers" within a range.
void _maybe_throw() const
bool operator!=(NumIter const &o) const
Supporting equality comparisons...
INT & getPos() const
access wrapped index elements
value_type operator*() const
ENABLE_USE_IN_STD_RANGE_FOR_LOOPS(NumIter)
bool operator==(NumIter const &o) const
NumIter(INT start, INT end)
NumIter(X &&start, X &&end)
Accessing a STL element range through a Lumiera forward iterator, An instance of this iterator adapte...
ENABLE_USE_IN_STD_RANGE_FOR_LOOPS(RangeIter)
RangeIter(I2 const &oIter)
allow copy, when the underlying iterators are compatible or convertible
const IT & getEnd() const
void _maybe_throw() const
std::remove_reference< reference >::type value_type
_ValTrait::pointer pointer
meta::ValueTypeBinding< meta::remove_pointer_t< IT > > _ValTrait
reference operator*() const
_ValTrait::reference reference
RangeIter(IT const &start, IT const &end)
const IT & getPos() const
access wrapped STL iterator
pointer operator->() const
Lumiera error handling (C++ interface).
void _throwIterExhausted()
decltype(std::declval< IT >().operator*()) Yield
type binding helper: an iterato's actual result type
decltype(std::declval< COR >().yield()) CoreYield
the result type yielded by a »state core«
Implementation namespace for support and library code.
bool operator==(PtrDerefIter< I1 > const &il, PtrDerefIter< I2 > const &ir)
Supporting equality comparisons...
bool operator!=(PtrDerefIter< I1 > const &il, PtrDerefIter< I2 > const &ir)
NumIter< INT > eachNum(INT start=std::numeric_limits< INT >::min(), INT end=std::numeric_limits< INT >::max())
convenience function to iterate "each number"
Helper for type rewritings: get the element type for an iterator like entity.
LumieraError< LERR_(INVALID)> Invalid
OBJ * unConst(const OBJ *)
shortcut to save some typing when having to define const and non-const variants of member functions
RangeIter< WrappedIter > Type
IterType< IT >::template SimilarIter< T2 >::Type WrappedIter
Type re-binding helper template for custom containers and adapters.