103 #ifndef LIB_ITER_ADAPTER_H 104 #define LIB_ITER_ADAPTER_H 125 _throwIterExhausted()
128 lumiera::error::LUMIERA_ERROR_ITER_EXHAUST);
133 #define ENABLE_USE_IN_STD_RANGE_FOR_LOOPS(ITER) \ 134 friend ITER begin (ITER const& it){ return it; } \ 135 friend ITER&& begin (ITER&& it) { return static_cast<ITER&&> (it); } \ 136 friend ITER end (ITER const&) { return ITER(); } \ 137 using iterator_category = std::input_iterator_tag; \ 138 using difference_type = size_t; 141 #define LIFT_PARENT_INCREMENT_OPERATOR(_BASECLASS_)\ 145 _BASECLASS_::operator++(); \ 153 using Yield = decltype(std::declval<IT>().
operator*());
157 using CoreYield = decltype(std::declval<COR>().yield());
205 template<
class POS,
class CON>
214 using value_type =
typename _ValTrait::value_type;
215 using reference =
typename _ValTrait::reference;
216 using pointer =
typename _ValTrait::pointer;
232 operator bool()
const 271 return not isValid();
285 return source_ && checkPoint (source_,pos_);
296 iterNext (source_,pos_);
304 using ConRef =
typename meta::RefTraits<CON>::Reference;
308 const ConRef source()
const {
return unConst(
this)->source_; }
311 resetPos (POS otherPos)
322 _throwIterExhausted();
330 template<
class P1,
class P2,
class CX>
336 template<
class P1,
class P2,
class CON>
339 template<
class P1,
class P2,
class CON>
372 template<
class ST,
typename T =iter::CoreYield<ST>>
378 using value_type =
typename meta::RefTraits<T>::Value;
379 using reference =
typename meta::RefTraits<T>::Reference;
380 using pointer =
typename meta::RefTraits<T>::Pointer;
383 : core_(std::forward<ST>(initialState))
387 : core_(initialState)
395 operator bool()
const 407 return core_.yield();
413 if constexpr (meta::isLRef_v<T>)
416 return & core_.yield();
419 static_assert (!
sizeof(T),
420 "can not provide operator-> " 421 "since iterator pipeline generates a value");
435 return core_.checkPoint();
441 return not isValid();
449 ST
const& stateCore()
const {
return core_; }
452 __throw_if_empty()
const 455 _throwIterExhausted();
464 template<
class STX,
class T1,
class T2>
471 template<
class ST,
class T1,
class T2>
475 return (il.empty() and ir.empty())
476 or (il.isValid() and ir.isValid() and il.core_ == ir.core_);
479 template<
class ST,
class T1,
class T2>
483 return not (il == ir);
503 ,
"Lumiera Iterator required as source");
508 return util::unConst(*
this);
518 return bool(srcIter());
521 typename IT::reference
548 ,
"Adapted type must expose a »state core« API");
553 return util::unConst(*
this);
557 __throw_if_empty()
const 559 if (not checkPoint())
560 _throwIterExhausted();
567 template<
typename...ARGS>
569 : COR(
std::forward<ARGS>(init)...)
585 return _rawCore().checkPoint();
592 return _rawCore().yield();
599 _rawCore().iterNext();
616 using Iter =
typename CON::iterator;
622 : CON(std::forward<CON>(container))
633 return p_ != CON::end();
683 COR & _core() {
return static_cast<COR&
> (*this); }
684 COR
const& _core()
const {
return static_cast<COR const&
> (*this); }
688 __throw_if_empty()
const 691 _throwIterExhausted();
695 using YieldRes = iter::CoreYield<COR>;
696 using value_type =
typename meta::RefTraits<YieldRes>::Value;
697 using reference =
typename meta::RefTraits<YieldRes>::Reference;
698 using pointer =
typename meta::RefTraits<YieldRes>::Pointer;
706 template<
typename...ARGS>
708 : COR(
std::forward<ARGS>(init)...)
720 explicit operator bool()
const {
return isValid(); }
725 return _core().yield();
731 if constexpr (meta::isLRef_v<YieldRes>)
732 return & _core().yield();
734 static_assert (!
sizeof(COR),
735 "can not provide operator-> " 736 "since iterator pipeline generates a value");
749 return _core().checkPoint();
755 return not isValid();
767 return (il.empty() and ir.empty())
768 or (il.isValid() and ir.isValid() and il._core() == ir._core());
773 return not (il == ir);
805 using pointer =
typename _ValTrait::pointer;
806 using reference =
typename _ValTrait::reference;
809 using value_type =
typename std::remove_reference<reference>::type;
812 RangeIter (IT
const& start, IT
const& end)
833 operator bool()
const 866 return (p_!= IT()) && (p_ != e_);
872 return not isValid();
878 const IT& getEnd()
const {
return e_; }
890 _throwIterExhausted();
897 template<
class I1,
class I2>
900 template<
class I1,
class I2>
918 template<
typename INT>
925 typedef INT* pointer;
926 typedef INT& reference;
927 typedef INT value_type;
936 : i_(std::forward<X>(start))
937 , e_(std::forward<X>(end))
948 operator bool()
const 981 return not isValid();
987 INT& getEnd()
const {
return e_; }
996 or (i_ == o.i_ and e_ == o.e_); }
1000 _maybe_throw()
const 1003 _throwIterExhausted();
1013 template<
typename INT>
1015 eachNum (INT start = std::numeric_limits<INT>::min()
1016 ,INT end = std::numeric_limits<INT>::max())
1034 template<
template<
class,
class>
class Iter,
class TY,
class CON>
1037 typedef CON Container;
1038 typedef TY ElemType;
1043 typedef Iter<T2,CON> Type;
1069 typedef const typename IT::value_type value_type;
1070 typedef const typename IT::pointer pointer;
1071 typedef const typename IT::reference reference;
1078 operator bool()
const 1096 return i_.operator->();
1115 return not isValid();
1132 template<
class I1,
class I2>
1135 template<
class I1,
class I2>
OBJ * unConst(const OBJ *)
shortcut to save some typing when having to define const and non-const variants of member functions ...
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.
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.
bool operator==(ConstIter< I1 > const &il, ConstIter< I2 > const &ir)
Supporting equality comparisons...
Derived specific exceptions within Lumiera's exception hierarchy.
COR TAG_CheckedCore_Raw
marker to allow unwrapping the raw core
IT const & getBase() const
access the wrapped implementation iterator
Another Lumiera Forward Iterator building block, based on incorporating a state type as »*State Core*...
wrapper to expose values as const
RangeIter(I2 const &oIter)
allow copy, when the underlying iterators are compatible or convertible
decltype(std::declval< IT >().operator*()) Yield
type binding helper: an iterato's actual result type
Lumiera error handling (C++ interface).
INT & getPos() const
access wrapped index elements
IT i_
nested source iterator
decltype(std::declval< COR >().yield()) CoreYield
the result type yielded by a »state core«
Adapter to »piggy-back« a STL iterable container inline and expose it as »state core«.
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. ...
NumIter< INT > eachNum(INT start=std::numeric_limits< INT >::min(), INT end=std::numeric_limits< INT >::max())
convenience function to iterate "each number"