diff --git a/src/lib/iter-chain-search.hpp b/src/lib/iter-chain-search.hpp index 4065cccd2..e839d37cf 100644 --- a/src/lib/iter-chain-search.hpp +++ b/src/lib/iter-chain-search.hpp @@ -93,10 +93,8 @@ namespace iter { struct _IterChainSetup { using Filter = decltype( buildSearchFilter(std::declval()).asIterator() ); - using StepFunctor = std::function; - using StepWrapper = typename iter_explorer::_FunTraits::Functor; - // ^^^^^^^^^^^^^ used as argument on generic lambda + using Pipeline = decltype( buildExplorer (std::declval(), std::declval()) ); static Pipeline @@ -130,7 +128,7 @@ namespace iter { using Value = typename _Base::value_type; using Filter = typename _Trait::Filter; - using Step = typename _Trait::StepWrapper; + using Step = typename _Trait::StepFunctor; std::vector stepChain_; diff --git a/src/lib/iter-tree-explorer.hpp b/src/lib/iter-tree-explorer.hpp index 671184b90..bd3007278 100644 --- a/src/lib/iter-tree-explorer.hpp +++ b/src/lib/iter-tree-explorer.hpp @@ -465,10 +465,10 @@ namespace lib { * accepts the iterator or state core itself (the "opaque state manipulation" usage pattern). * - we generate a suitable argument accessor function and build the function composition * of this accessor and the provided _expansion functor_. - * - the resulting, combined functor is stored into a std::function, but wired in a way to - * keep the argument-accepting front-end still generic (templated `operator()`). This - * special adapter supports the case when the _expansion functor_ yields a child sequence - * type different but compatible to the original source sequence embedded in TreeExplorer. + * - the resulting, combined functor is stored into a std::function, thereby abstracting + * from the actual adapting mechanism. This allows to combine different kinds of functors + * within the same processing step; and in addition, it allows the processing step to + * remain agnostic with respect to the adaptation and concrete type of the functor/lambda. * @tparam FUN either the signature, or something _"function-like"_ passed as functor to be bound * @tparam SRC (optional) but need to specify the source iterator type to apply when passing * a generic lambda or template as FUN. Such a generic functor will be _instantiated_ @@ -509,9 +509,11 @@ namespace lib { static_assert (std::is_convertible::value, "the bound functor must accept the source iterator or state core as parameter"); - static auto build() { return [](ARG& arg) -> ARG& { return arg; }; } - - static decltype(auto) wrap (FUN&& rawFunctor) { return forward (rawFunctor); } + static decltype(auto) + wrap (FUN&& rawFunctor) ///< actually pass-through the raw functor unaltered + { + return forward (rawFunctor); + } }; /** adapt to a functor, which accepts the value type of the source sequence ("monadic" usage pattern) */ @@ -519,9 +521,11 @@ namespace lib { struct ArgAdapter ,__not_>>>> // need to exclude the latter, since IterableDecorator { // often seems to accept IT::value_type (while in fact it doesn't) - static auto build() { return [](auto& iter) { return *iter; }; } - - static auto wrap (function rawFun) { return [rawFun](IT& srcIter) -> Res { return rawFun(*srcIter); }; } + static auto + wrap (function rawFun) ///< adapt by dereferencing the source iterator + { + return [rawFun](IT& srcIter) -> Res { return rawFun(*srcIter); }; + } }; /** adapt to a functor collaborating with an IterSource based iterator pipeline */ @@ -532,27 +536,16 @@ namespace lib { { using Source = typename IT::Source; - static auto build() { return [](auto& iter) -> Source& { return iter.source(); }; } - - static auto wrap (function rawFun) { return [rawFun](IT& iter) -> Res { return rawFun(iter.source()); }; } - }; - - - /** holder for the suitably adapted _expansion functor_ */ - struct Functor - { - function boundFunction; - - template - Res - operator() (ARG& arg) const + static auto + wrap (function rawFun) ///< extract the (abstracted) IterSource { - auto accessArg = ArgAdapter::build(); - - return boundFunction (accessArg (arg)); + return [rawFun](IT& iter) -> Res { return rawFun(iter.source()); }; } }; + + + /** builder to create a nested/wrapping functor, suitably adapting the arguments */ template static auto adaptFunctor (FUN&& rawFunctor) @@ -618,7 +611,10 @@ namespace lib { * the source iterator wrapped by this decorator. * @remark since we allow a lot of leeway regarding the actual form and definition of the * _expansion functor_, there is a lot of minute technical details, mostly confined - * within the _FunTraits traits. + * within the _FunTraits traits. For the same reason, we need to prepare two different + * bindings of the passed raw functor, one to work on the source sequence, and the other + * one to work on the result sequence of a recursive child expansions; these two sequences + * need not be implemented in the same way, which simplifies the definition of algorithms. * @tparam SRC the wrapped source iterator, typically a TreeExplorer or nested decorator. * @tparam FUN the concrete type of the functor passed. Will be dissected to find the signature */ @@ -653,6 +649,7 @@ namespace lib { { } + /** core operation: expand current head element */ void expandChildren() @@ -1189,6 +1186,7 @@ namespace lib { using Parent = WrappedLumieraIter; using Val = typename SRC::value_type; ///////////////////////////////////TICKET #1125 : get rid of Val + ~PackagedTreeExplorerSource() { } public: using Parent::Parent; diff --git a/tests/library/iter-tree-explorer-test.cpp b/tests/library/iter-tree-explorer-test.cpp index 08c3f799b..418a33f2f 100644 --- a/tests/library/iter-tree-explorer-test.cpp +++ b/tests/library/iter-tree-explorer-test.cpp @@ -428,8 +428,6 @@ namespace test{ .expand([](CountDown core){ return NumberSequence{ core.yield() - 1}; }) // expand-functor: StateCore -> Iter ); -#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1118 : GDB Segfault on loading the inferior - /////////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1118 : Generated code works just fine and passes Test though verify_treeExpandingIterator( treeExplore(CountDown{5}) .expand([](auto & it){ return CountDown{ *it - 1}; }) // generic Lambda: Iter& -> StateCore @@ -439,7 +437,6 @@ namespace test{ treeExplore(CountDown{5}) .expand([](auto it){ return decltype(it){ *it - 1}; }) // generic Lambda: Iter -> Iter ); -#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1118 : GDB Segfault on loading the inferior } diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 2aff97a52..3ad762420 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -30795,8 +30795,8 @@ - - + + @@ -30834,8 +30834,8 @@ - - + + @@ -31040,8 +31040,8 @@ - - + + @@ -31079,9 +31079,9 @@ - - - + + + @@ -31091,10 +31091,10 @@ - - + + - + @@ -31133,10 +31133,10 @@ - - - - + + + + @@ -31211,8 +31211,8 @@ - - + + @@ -31230,7 +31230,8 @@ - + + @@ -31282,7 +31283,8 @@ - + + @@ -31319,8 +31321,9 @@ - + + @@ -31386,7 +31389,7 @@ - + @@ -31504,8 +31507,11 @@ - - + + + + + @@ -31564,8 +31570,8 @@ - - + + @@ -32095,8 +32101,8 @@ - - + +