From 604ffbf73c123715f6bfe2e426e23f3f87596618 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 3 Sep 2018 01:52:07 +0200 Subject: [PATCH] TreeExplorer: fix a bug and finish the feature we did an unnecessary copy of the argument, which was uncovered by the test case manipulating the state core. Whew. Now we have a beautiful new overengineered solution --- src/lib/iter-tree-explorer.hpp | 12 +++--- tests/library/iter-tree-explorer-test.cpp | 27 +++++++----- wiki/thinkPad.ichthyo.mm | 50 ++++++++++++++--------- 3 files changed, 54 insertions(+), 35 deletions(-) diff --git a/src/lib/iter-tree-explorer.hpp b/src/lib/iter-tree-explorer.hpp index eaad1db79..07d9c9a75 100644 --- a/src/lib/iter-tree-explorer.hpp +++ b/src/lib/iter-tree-explorer.hpp @@ -988,7 +988,7 @@ namespace lib { remouldFilter (forward (conjunctiveClause) ,[](auto first, auto chain) { - return [=](auto val) + return [=](auto& val) { return first(val) and chain(val); @@ -1004,7 +1004,7 @@ namespace lib { remouldFilter (forward (conjunctiveClause) ,[](auto first, auto chain) { - return [=](auto val) + return [=](auto& val) { return first(val) and not chain(val); @@ -1020,7 +1020,7 @@ namespace lib { remouldFilter (forward (disjunctiveClause) ,[](auto first, auto chain) { - return [=](auto val) + return [=](auto& val) { return first(val) or chain(val); @@ -1036,7 +1036,7 @@ namespace lib { remouldFilter (forward (disjunctiveClause) ,[](auto first, auto chain) { - return [=](auto val) + return [=](auto& val) { return first(val) or not chain(val); @@ -1052,7 +1052,7 @@ namespace lib { remouldFilter (dummy ,[](auto currentFilter, auto) { - return [=](auto val) + return [=](auto& val) { return not currentFilter(val); }; @@ -1067,7 +1067,7 @@ namespace lib { remouldFilter (forward (entirelyDifferentPredicate) ,[](auto, auto chain) { - return [=](auto val) + return [=](auto& val) { return chain(val); }; diff --git a/tests/library/iter-tree-explorer-test.cpp b/tests/library/iter-tree-explorer-test.cpp index 48f4b951b..601cf5f3c 100644 --- a/tests/library/iter-tree-explorer-test.cpp +++ b/tests/library/iter-tree-explorer-test.cpp @@ -848,7 +848,7 @@ namespace test{ - /** @test the filter layer can be re-configured on the fly */ + /** @test a special filter layer which can be re-configured on the fly */ void verify_FilterChanges() { @@ -869,7 +869,7 @@ namespace test{ CHECK (16 == *seq); seq.andFilter (takeTrd); - CHECK (12 == *seq); + CHECK (12 == *seq); // is divisible (by 2 AND by 3) seq.flipFilter(); CHECK (11 == *seq); // not divisible (by 2 AND by 3) @@ -884,22 +884,29 @@ namespace test{ seq.orNotFilter (takeEve); CHECK ( 6 == *seq); ++seq; - CHECK ( 5 == *seq); + CHECK ( 5 == *seq); // disjunctive condition actually weakens the filter ++seq; CHECK ( 3 == *seq); + // NOTE: arbitrary functors can be used/combined, + // since they are adapted individually. + // To demonstrate this, we use a functor accessing and + // manipulating the state core by side effect... string buff{"."}; seq.andNotFilter ([&](CountDown& core) { buff += util::toString(core.p) + "."; - --core.p; - return core.p % 2; + --core.p; // manipulate state core + return core.p % 2; // return a number, not bool }); - cout << "URGS: "<<*seq<< " ..."< - - + + @@ -30856,7 +30856,7 @@ - + @@ -30927,7 +30927,7 @@ - + @@ -30977,7 +30977,7 @@ - + @@ -30995,7 +30995,7 @@ - + @@ -31051,9 +31051,10 @@ - - - + + + + @@ -31081,15 +31082,26 @@ Typischerweise wird dieser ja sogar beim Aufruf des getemplateteten Funtions-Operators geInlined

- - +
- - + + - - + + + + + + +

+ der Aufruf vom äußeren in den inneren Wrapper ist 1:1 und sollte vom Compiler wegoptimiert werden +

+ +
+
+ + @@ -31109,13 +31121,13 @@
- - + + - - + +