From a86517bd4f3671e013c66166ca008734a1573191 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 13 Nov 2009 01:02:31 +0100 Subject: [PATCH] extend the protocol of the itertools core, abstracting the increment --- src/lib/itertools.hpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/lib/itertools.hpp b/src/lib/itertools.hpp index 3c541242a..2e730634f 100644 --- a/src/lib/itertools.hpp +++ b/src/lib/itertools.hpp @@ -98,17 +98,23 @@ namespace lib { { } IT& - source () + pipe () { return source_; } IT const& - source () const + pipe () const { return source_; } + void + advance () + { + ++source_; + } + bool evaluate () const { @@ -146,11 +152,11 @@ namespace lib { bool iterate () { - if (!core_.source()) return false; + if (!core_.pipe()) return false; - do ++core_.source(); - while (core_.source() && !core_.evaluate()); - return core_.source(); + do core_.advance(); + while (core_.pipe() && !core_.evaluate()); + return core_.pipe(); } void @@ -182,14 +188,14 @@ namespace lib { operator*() const { _maybe_throw(); - return *core_.source(); + return *core_.pipe(); } pointer operator->() const { _maybe_throw(); - return core_.source(); + return core_.pipe(); } 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 friend bool operator== (IterTool const& it1, IterTool const& it2); }; @@ -223,8 +229,8 @@ namespace lib { inline bool operator== (IterTool const& it1, IterTool const& it2) { - return it1.isValid() == it2.isValid() - && it1.core_.source() == it2.core_.source() + return it1.isValid() == it2.isValid() + && it1.core_.pipe() == it2.core_.pipe() ; } @@ -261,8 +267,8 @@ namespace lib { bool evaluate () const { - return _Par::source() - && predicate_(*_Par::source()); + return _Par::pipe() + && predicate_(*_Par::pipe()); }