101 #ifndef LIB_ITER_ADAPTER_H 102 #define LIB_ITER_ADAPTER_H 116 _throwIterExhausted()
119 lumiera::error::LUMIERA_ERROR_ITER_EXHAUST);
124 #define ENABLE_USE_IN_STD_RANGE_FOR_LOOPS(ITER) \ 125 friend ITER begin (ITER const& it){ return it; } \ 126 friend ITER&& begin (ITER&& it) { return static_cast<ITER&&> (it); } \ 127 friend ITER end (ITER const&) { return ITER(); } \ 128 using iterator_category = std::input_iterator_tag; \ 129 using difference_type = size_t; 132 #define LIFT_PARENT_INCREMENT_OPERATOR(_BASECLASS_)\ 136 _BASECLASS_::operator++(); \ 184 template<
class POS,
class CON>
193 using value_type =
typename _ValTrait::value_type;
194 using reference =
typename _ValTrait::reference;
195 using pointer =
typename _ValTrait::pointer;
211 operator bool()
const 250 return not isValid();
264 return source_ && checkPoint (source_,pos_);
275 iterNext (source_,pos_);
283 using ConRef =
typename meta::RefTraits<CON>::Reference;
287 const ConRef
source()
const {
return unConst(
this)->source_; }
290 resetPos (POS otherPos)
301 _throwIterExhausted();
309 template<
class P1,
class P2,
class CX>
315 template<
class P1,
class P2,
class CON>
318 template<
class P1,
class P2,
class CON>
350 template<
typename T,
class ST =T>
357 typedef T& reference;
358 typedef T value_type;
361 : core_(std::forward<ST>(initialState))
365 : core_(initialState)
373 operator bool()
const 385 return core_.yield();
392 return & core_.yield();
406 return core_.checkPoint();
412 return not isValid();
420 ST
const& stateCore()
const {
return core_; }
423 __throw_if_empty()
const 426 _throwIterExhausted();
435 template<
class T1,
class T2,
class STX>
442 template<
class T1,
class T2,
class ST>
446 return (il.empty() and ir.empty())
447 or (il.isValid() and ir.isValid() and il.core_ == ir.core_);
450 template<
class T1,
class T2,
class ST>
454 return not (il == ir);
474 ,
"Lumiera Iterator required as source");
479 return unConst(*
this);
489 return bool(srcIter());
492 typename IT::reference
519 ,
"Adapted type must expose a »state core« API");
524 return unConst(*
this);
528 __throw_if_empty()
const 530 if (not checkPoint())
531 _throwIterExhausted();
538 template<
typename...ARGS>
540 : COR(
std::forward<ARGS>(init)...)
554 return _rawCore().checkPoint();
561 return _rawCore().yield();
568 _rawCore().iterNext();
598 template<
typename T,
class COR>
602 COR & _core() {
return static_cast<COR&
> (*this); }
603 COR
const& _core()
const {
return static_cast<COR const&
> (*this); }
607 __throw_if_empty()
const 610 _throwIterExhausted();
615 typedef T& reference;
616 typedef T value_type;
623 template<
typename...ARGS>
625 : COR(
std::forward<ARGS>(init)...)
637 explicit operator bool()
const {
return isValid(); }
642 return _core().yield();
648 return & _core().yield();
661 return _core().checkPoint();
667 return not isValid();
676 template<
class T1,
class T2>
680 return (il.empty() and ir.empty())
681 or (il.isValid() and ir.isValid() and il._core() == ir._core());
684 template<
class T1,
class T2>
688 return not (il == ir);
721 using pointer =
typename _ValTrait::pointer;
722 using reference =
typename _ValTrait::reference;
725 using value_type =
typename std::remove_reference<reference>::type;
728 RangeIter (IT
const& start, IT
const& end)
749 operator bool()
const 782 return (p_!= IT()) && (p_ != e_);
788 return not isValid();
794 const IT& getEnd()
const {
return e_; }
806 _throwIterExhausted();
813 template<
class I1,
class I2>
816 template<
class I1,
class I2>
831 template<
typename INT>
838 typedef const INT* pointer;
839 typedef const INT& reference;
840 typedef INT value_type;
849 : i_(std::forward<X>(start))
850 , e_(std::forward<X>(end))
861 operator bool()
const 895 return (i_!= INT()) && (i_ < e_);
901 return not isValid();
907 const INT& getEnd()
const {
return e_; }
918 _throwIterExhausted();
925 template<
class I1,
class I2>
928 template<
class I1,
class I2>
934 template<
typename INT>
954 template<
template<
class,
class>
class Iter,
class TY,
class CON>
957 typedef CON Container;
963 typedef Iter<T2,CON> Type;
989 typedef const typename IT::value_type value_type;
990 typedef const typename IT::pointer pointer;
991 typedef const typename IT::reference reference;
998 operator bool()
const 1016 return i_.operator->();
1035 return not isValid();
1052 template<
class I1,
class I2>
1055 template<
class I1,
class I2>
const IT & getPos() const
access wrapped STL iterator
ST & stateCore()
allow derived classes to access state representation
Helper for type rewritings: get the element type for an iterator like entity.
NumIter< INT > eachNum(INT start, INT end)
convenience function to iterate "each number"
CheckedCore(ARGS &&...init)
blindly pass-down any argument...
Adapter to add sanity checks to a »state core«.
Type re-binding helper template for custom containers and adapters.
IterableDecorator(ARGS &&...init)
by default, pass anything down for initialisation of the core.
#define ENABLE_USE_IN_STD_RANGE_FOR_LOOPS(ITER)
use a given Lumiera Forward Iterator in standard "range for loops"
ConRef source()
allow derived classes to access backing container
Adapter to dress up an existing »Lumiera Forward Iterator« as »state core«.
typename std::remove_reference< reference >::type value_type
Implementation namespace for support and library code.
Enumerate all "numbers" within a range.
friend bool operator==(IterAdapter< P1, CX > const &, IterAdapter< P2, CX > const &)
comparison is allowed to access impl iterator
Derived specific exceptions within Lumiera's exception hierarchy.
IT const & getBase() const
access the wrapped implementation iterator
const INT & getPos() const
access wrapped index elements
Another Lumiera Forward Iterator building block, based on incorporating a state type right into the i...
wrapper to expose values as const
RangeIter(I2 const &oIter)
allow copy, when the underlying iterators are compatible or convertible
Lumiera error handling (C++ interface).
IT i_
nested source iterator
bool check() const
ask the controlling container if this position is valid.
Decorator-Adapter to make a »state core« iterable as Lumiera Forward Iterator.
Accessing a STL element range through a Lumiera forward iterator, An instance of this iterator adapte...
void iterate()
ask the controlling container to yield the next position.
Adapter for building an implementation of the »Lumiera Forward Iterator« concept. ...