From e29d9ae19e48dab84449f70d090c4ebc1dad3a78 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 2 Sep 2018 20:40:49 +0200 Subject: [PATCH] TreeExplorer: better package this very specific code as subclass while this is basically just code code cosmetics, at least it marks this as a very distinct special case, and keeps the API for the standard Filter layer clean. --- src/lib/iter-tree-explorer.hpp | 33 +++++++++++++++++++---- tests/library/iter-tree-explorer-test.cpp | 2 +- wiki/thinkPad.ichthyo.mm | 11 ++++++-- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/lib/iter-tree-explorer.hpp b/src/lib/iter-tree-explorer.hpp index da1d676b5..621f7b5be 100644 --- a/src/lib/iter-tree-explorer.hpp +++ b/src/lib/iter-tree-explorer.hpp @@ -863,6 +863,7 @@ namespace lib { using Res = typename _Traits::Res; static_assert(std::is_constructible::value, "Functor must be a predicate"); + protected: using FilterPredicate = typename _Traits::Functor; FilterPredicate predicate_; @@ -911,7 +912,7 @@ namespace lib { } - private: + protected: SRC& srcIter() const { @@ -927,7 +928,17 @@ namespace lib { while (srcIter() and not predicate_(srcIter())) ++srcIter(); } - + }; + + + + template + class MutableFilter + : public Filter + { + using _Base = Filter; + public: + using _Base::Filter; public: /* === API to Remould the Filter condition underway === */ @@ -957,13 +968,14 @@ namespace lib { using Res = typename _ChainTraits::Res; static_assert(std::is_constructible::value, "Chained Functor must be a predicate"); + using FilterPredicate = typename _Base::FilterPredicate; using ChainPredicate = typename _ChainTraits::Functor; - FilterPredicate& firstClause = this->predicate_; + FilterPredicate& firstClause = Filter::predicate_; ChainPredicate chainClause{forward (additionalClause)}; - predicate_ = FilterPredicate{buildCombinedClause (firstClause, chainClause)}; - pullFilter(); + _Base::predicate_ = FilterPredicate{buildCombinedClause (firstClause, chainClause)}; + _Base::pullFilter(); } }; @@ -1265,6 +1277,17 @@ namespace lib { } + template + auto + mutableFilter (FUN&& filterPredicate) + { + using ResCore = iter_explorer::MutableFilter; + using ResIter = typename _DecoratorTraits::SrcIter; + + return TreeExplorer (ResCore {move(*this), forward(filterPredicate)}); + } + + /** _terminal builder_ to package the processing pipeline as IterSource. * Invoking this function moves the whole iterator compound, as assembled by the preceding * builder calls, into heap allocated memory and returns a [iterator front-end](\ref IterExploreSource). diff --git a/tests/library/iter-tree-explorer-test.cpp b/tests/library/iter-tree-explorer-test.cpp index 6f25ed072..ea4bda8b5 100644 --- a/tests/library/iter-tree-explorer-test.cpp +++ b/tests/library/iter-tree-explorer-test.cpp @@ -853,7 +853,7 @@ namespace test{ verify_FilterChanges() { auto seq = treeExplore(CountDown{20}) - .filter([](uint){ return true; }); + .mutableFilter([](uint){ return true; }); auto takeEve = [](uint i){ return i%2 == 0; }; auto takeTrd = [](uint i){ return i%3 == 0; }; diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 13adccc8c..38890073b 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -30977,7 +30977,8 @@ - + + @@ -31051,10 +31052,16 @@ - + + + + + + +