From fd3d6fb60e8ad7ebf62eaf5d8b19bce1e29e33bc Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 19 Nov 2017 02:28:48 +0100 Subject: [PATCH] TreeExplorer: first testcase, build either from Lumiera-Iterator or use StateCore TODO: also wrap any suitable STL iterable. we need a one-shot solution here --- src/lib/iter-tree-explorer.hpp | 18 ++++++++++--- tests/library/iter-tree-explorer-test.cpp | 32 +++++++++-------------- wiki/thinkPad.ichthyo.mm | 21 +++++++++++++++ 3 files changed, 48 insertions(+), 23 deletions(-) diff --git a/src/lib/iter-tree-explorer.hpp b/src/lib/iter-tree-explorer.hpp index f8b6c4dff..7afb82231 100644 --- a/src/lib/iter-tree-explorer.hpp +++ b/src/lib/iter-tree-explorer.hpp @@ -73,7 +73,7 @@ #include "lib/error.hpp" #include "lib/meta/trait.hpp" -//#include "lib/meta/function.hpp" +#include "lib/meta/duck-detector.hpp" #include "lib/iter-adapter.hpp" #include "lib/iter-stack.hpp" #include "lib/meta/trait.hpp" ////////////////TODO @@ -159,15 +159,24 @@ namespace lib { namespace { using meta::enable_if; + using meta::Yes_t; + using meta::No_t; using std::__and_; using std::__not_; using std::is_constructible; using meta::can_IterForEach; using meta::can_STL_ForEach; + META_DETECT_EXTENSION_POINT(checkPoint); + META_DETECT_EXTENSION_POINT(iterNext); + META_DETECT_EXTENSION_POINT(yield); + template struct is_StateCore - : is_constructible, SRC> + : __and_< HasExtensionPoint_checkPoint + , HasExtensionPoint_iterNext + , HasExtensionPoint_yield + > { }; template @@ -187,13 +196,14 @@ namespace lib { template struct _TreeExplorerTraits>> { - static_assert (!sizeof(SRC), "PLING: StateCore"); + using SrcVal = typename std::remove_reference()))>::type; + using SrcIter = IterStateWrapper; }; template struct _TreeExplorerTraits>> { - static_assert (!sizeof(SRC), "PLING: Lumi Iter"); + using SrcIter = typename std::remove_reference::type; }; template diff --git a/tests/library/iter-tree-explorer-test.cpp b/tests/library/iter-tree-explorer-test.cpp index a2402a39c..0ebd38b36 100644 --- a/tests/library/iter-tree-explorer-test.cpp +++ b/tests/library/iter-tree-explorer-test.cpp @@ -91,7 +91,7 @@ namespace test{ uint p,e; public: - State(uint start, uint end) + State(uint start =0, uint end =0) : p(start) , e(end) { } @@ -99,7 +99,7 @@ namespace test{ friend bool checkPoint (State const& st) { - return st.p < st.e; + return st.p > st.e; } friend uint& @@ -111,8 +111,8 @@ namespace test{ friend void iterNext (State & st) { - if (!checkPoint(st)) return; - ++st.p; + if (not checkPoint(st)) return; + --st.p; } }; @@ -248,12 +248,11 @@ namespace test{ void verify_wrappedState() { -#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #1117 - auto ii = treeExplore (State{1,5}); + auto ii = treeExplore (State{5,0}); CHECK (!isnil (ii)); - CHECK (1 == *ii); + CHECK (5 == *ii); ++ii; - CHECK (2 == *ii); + CHECK (4 == *ii); pullOut(ii); CHECK ( isnil (ii)); CHECK (!ii); @@ -261,14 +260,13 @@ namespace test{ VERIFY_ERROR (ITER_EXHAUST, *ii ); VERIFY_ERROR (ITER_EXHAUST, ++ii ); - ii = treeExplore (State{0,5}); - CHECK (materialise(ii) == "0-1-2-3-4-5"); - ii = treeExplore (State{5,7}); - CHECK (materialise(ii) == "5-6-7"); - ii = treeExplore (State{1,0}); + ii = treeExplore (State{5}); + CHECK (materialise(ii) == "5-4-3-2-1"); + ii = treeExplore (State{7,4}); + CHECK (materialise(ii) == "7-6-5"); + ii = treeExplore (State{}); CHECK ( isnil (ii)); CHECK (!ii); -#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #1117 } @@ -276,7 +274,6 @@ namespace test{ void verify_wrappedIterator() { -#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #1117 vector numz{1,-2,3,-5,8,-13}; auto ii = eachElm(numz); CHECK (!isnil (ii)); @@ -294,8 +291,7 @@ namespace test{ CHECK (-2 == *ii); CHECK (materialise(ii) == "-2-3--5-8--13"); - CHECK (materialise(jj) == "-3--5-8--13"); -#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #1117 + CHECK (materialise(jj) == "3--5-8--13"); } @@ -306,8 +302,6 @@ namespace test{ verify_mapOperation() { UNIMPLEMENTED("map function onto the results"); -#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #1117 -#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #1117 } diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index fd0416b6a..f09cb7284 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -5094,6 +5094,9 @@ + + + @@ -5102,6 +5105,24 @@ + + + + + + + + + + + + + + + + + +