extend the protocol of the itertools core, abstracting the increment
This commit is contained in:
parent
a1448ed6f6
commit
a86517bd4f
1 changed files with 19 additions and 13 deletions
|
|
@ -98,17 +98,23 @@ namespace lib {
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
IT&
|
IT&
|
||||||
source ()
|
pipe ()
|
||||||
{
|
{
|
||||||
return source_;
|
return source_;
|
||||||
}
|
}
|
||||||
|
|
||||||
IT const&
|
IT const&
|
||||||
source () const
|
pipe () const
|
||||||
{
|
{
|
||||||
return source_;
|
return source_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
advance ()
|
||||||
|
{
|
||||||
|
++source_;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
evaluate () const
|
evaluate () const
|
||||||
{
|
{
|
||||||
|
|
@ -146,11 +152,11 @@ namespace lib {
|
||||||
bool
|
bool
|
||||||
iterate ()
|
iterate ()
|
||||||
{
|
{
|
||||||
if (!core_.source()) return false;
|
if (!core_.pipe()) return false;
|
||||||
|
|
||||||
do ++core_.source();
|
do core_.advance();
|
||||||
while (core_.source() && !core_.evaluate());
|
while (core_.pipe() && !core_.evaluate());
|
||||||
return core_.source();
|
return core_.pipe();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -182,14 +188,14 @@ namespace lib {
|
||||||
operator*() const
|
operator*() const
|
||||||
{
|
{
|
||||||
_maybe_throw();
|
_maybe_throw();
|
||||||
return *core_.source();
|
return *core_.pipe();
|
||||||
}
|
}
|
||||||
|
|
||||||
pointer
|
pointer
|
||||||
operator->() const
|
operator->() const
|
||||||
{
|
{
|
||||||
_maybe_throw();
|
_maybe_throw();
|
||||||
return core_.source();
|
return core_.pipe();
|
||||||
}
|
}
|
||||||
|
|
||||||
IterTool&
|
IterTool&
|
||||||
|
|
@ -213,7 +219,7 @@ namespace lib {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// comparison is allowed to access the source iterator
|
/// comparison is allowed to access the feed pipe from core
|
||||||
template<class CX>
|
template<class CX>
|
||||||
friend bool operator== (IterTool<CX> const& it1, IterTool<CX> const& it2);
|
friend bool operator== (IterTool<CX> const& it1, IterTool<CX> const& it2);
|
||||||
};
|
};
|
||||||
|
|
@ -223,8 +229,8 @@ namespace lib {
|
||||||
inline bool
|
inline bool
|
||||||
operator== (IterTool<CX> const& it1, IterTool<CX> const& it2)
|
operator== (IterTool<CX> const& it1, IterTool<CX> const& it2)
|
||||||
{
|
{
|
||||||
return it1.isValid() == it2.isValid()
|
return it1.isValid() == it2.isValid()
|
||||||
&& it1.core_.source() == it2.core_.source()
|
&& it1.core_.pipe() == it2.core_.pipe()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -261,8 +267,8 @@ namespace lib {
|
||||||
bool
|
bool
|
||||||
evaluate () const
|
evaluate () const
|
||||||
{
|
{
|
||||||
return _Par::source()
|
return _Par::pipe()
|
||||||
&& predicate_(*_Par::source());
|
&& predicate_(*_Par::pipe());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue