From 13d32916eecaf0867acf645591a1cb9d66d8f925 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 10 Dec 2017 00:24:36 +0100 Subject: [PATCH] TreeExplorer: implement simple auto-expansion ...just expand children instead of normal iteration; works out of the box, since expansion itself performs a iteration step. --- src/lib/iter-tree-explorer.hpp | 27 +++++++++++++++++++---- tests/library/iter-tree-explorer-test.cpp | 5 +++-- wiki/thinkPad.ichthyo.mm | 14 ++++++++---- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/lib/iter-tree-explorer.hpp b/src/lib/iter-tree-explorer.hpp index 20e036cc1..25bff8f7c 100644 --- a/src/lib/iter-tree-explorer.hpp +++ b/src/lib/iter-tree-explorer.hpp @@ -549,8 +549,6 @@ namespace lib { iterNext(); // consume current head element if (not isnil(expanded)) expansions_.push (move(expanded)); - - SRC::expandChildren(); } /** diagnostics: current level of nested child expansion */ @@ -593,6 +591,25 @@ namespace lib { + template + class AutoExpander + : public SRC + { + static_assert(is_StateCore::value, "need wrapped state as predecessor in pipeline"); + + public: + /** pass through ctor */ + using SRC::SRC; + + void + iterNext() + { + SRC::expandChildren(); + } + }; + + + /** * @internal Decorator for TreeExplorer to map a transformation function on all results. * The transformation function is invoked on demand, and only once per item to be treated, @@ -968,8 +985,10 @@ namespace lib { auto expandAll() { - UNIMPLEMENTED ("automatically expand all elements"); - return *this; + using ResCore = iter_explorer::AutoExpander; + using ResIter = typename _DecoratorTraits::SrcIter; + + return TreeExplorer (ResCore {move(*this)}); } diff --git a/tests/library/iter-tree-explorer-test.cpp b/tests/library/iter-tree-explorer-test.cpp index 1ab5ef475..96597c831 100644 --- a/tests/library/iter-tree-explorer-test.cpp +++ b/tests/library/iter-tree-explorer-test.cpp @@ -807,12 +807,13 @@ namespace test{ void verify_depthFirstExploration() { - cout << materialise( + CHECK (materialise( treeExplore(CountDown{4}) .expand([](uint j){ return CountDown{j-1}; }) .expandAll() .transform([](int i){ return i*10; }) - ) < + + + - - + + + + + @@ -6768,8 +6774,8 @@ - - + +