From a91025bfe043edf95464aafc1d7433e1d00f89be Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 9 Sep 2018 02:09:38 +0200 Subject: [PATCH] TreeExplorer: perpare a builder for a suitably adapted, wrapped functor. This does not touch the existing code-path, but the idea is to use the _FunTraits directly from within the constructor of the respective processing layer, and to confine the knowledge of the actual FUN functor type to within that limited context. Only the generic signature of the resulting std::function need to be encoded into the type of the processing component, which should help to simplify the type signatures --- src/lib/iter-tree-explorer.hpp | 17 +++++++++-- wiki/thinkPad.ichthyo.mm | 53 +++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/lib/iter-tree-explorer.hpp b/src/lib/iter-tree-explorer.hpp index 7270a1683..2bf94e392 100644 --- a/src/lib/iter-tree-explorer.hpp +++ b/src/lib/iter-tree-explorer.hpp @@ -475,7 +475,7 @@ namespace lib { * passing the type `SRC&` as argument. This instantiation may fail (and abort compilation), * but when it succeeds, we can infer the result type `Res` from the generic lambda */ - template + template struct _FunTraits { /** handle all regular "function-like" entities */ @@ -495,7 +495,7 @@ namespace lib { }; - using Sig = typename FunDetector::Sig; + using Sig = typename FunDetector::Sig; using Arg = typename _Fun::Args::List::Head; // assuming function with a single argument using Res = typename _Fun::Ret; @@ -510,6 +510,8 @@ namespace lib { "the bound functor must accept the source iterator or state core as parameter"); static auto build() { return [](ARG& arg) -> ARG& { return arg; }; } + + static auto wrap (FUN&& rawFunctor) { return forward (rawFunctor); } }; /** adapt to a functor, which accepts the value type of the source sequence ("monadic" usage pattern) */ @@ -518,6 +520,8 @@ namespace lib { ,__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) { return rawFun(*srcIter); }; } }; /** adapt to a functor collaborating with an IterSource based iterator pipeline */ @@ -529,6 +533,8 @@ 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) { return rawFun(*iter.source()); }; } }; @@ -546,6 +552,13 @@ namespace lib { return boundFunction (accessArg (arg)); } }; + + template + static auto + adaptFunctor (FUN&& rawFunctor) + { + return function {ArgAdapter::wrap (forward (rawFunctor))}; + } }; diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index d66335796..a892bba72 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -31269,7 +31269,7 @@ - + @@ -31308,6 +31308,57 @@ + + + + + + + + + + + + + + + + + + +

+ ...wo der volle Typ des Funktors FUN bekannt ist +

+ + +
+
+ + + + + + + + +

+ ...und in dem besonders wichtigen Fall, +

+

+ in dem der Funktor direkt den SRC-Iterator akzeptiert, +

+

+ wird er ohne Weiteres durchgereicht. +

+

+ In dem Fall dann keine doppelte Verpackung mehr! +

+ + +
+
+
+