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
This commit is contained in:
parent
a175306f50
commit
a91025bfe0
2 changed files with 67 additions and 3 deletions
|
|
@ -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<class SIG, typename SRC =void>
|
||||
template<class FUN, typename SRC =void>
|
||||
struct _FunTraits
|
||||
{
|
||||
/** handle all regular "function-like" entities */
|
||||
|
|
@ -495,7 +495,7 @@ namespace lib {
|
|||
};
|
||||
|
||||
|
||||
using Sig = typename FunDetector<SIG>::Sig;
|
||||
using Sig = typename FunDetector<FUN>::Sig;
|
||||
using Arg = typename _Fun<Sig>::Args::List::Head; // assuming function with a single argument
|
||||
using Res = typename _Fun<Sig>::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<FUN> (rawFunctor); }
|
||||
};
|
||||
|
||||
/** adapt to a functor, which accepts the value type of the source sequence ("monadic" usage pattern) */
|
||||
|
|
@ -518,6 +520,8 @@ namespace lib {
|
|||
,__not_<is_convertible<IT, Arg>>>>> // 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<Sig> 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<Sig> rawFun) { return [rawFun](IT& iter) { return rawFun(*iter.source()); }; }
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -546,6 +552,13 @@ namespace lib {
|
|||
return boundFunction (accessArg (arg));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename IT>
|
||||
static auto
|
||||
adaptFunctor (FUN&& rawFunctor)
|
||||
{
|
||||
return function<Res(IT&)> {ArgAdapter<IT>::wrap (forward<FUN> (rawFunctor))};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -31269,7 +31269,7 @@
|
|||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1536441211468" ID="ID_435661366" MODIFIED="1536441216296" TEXT="Lösungs-Idee">
|
||||
<node CREATED="1536441211468" HGAP="84" ID="ID_435661366" MODIFIED="1536451220949" TEXT="Lösungs-Idee" VSHIFT="15">
|
||||
<node CREATED="1536441217427" ID="ID_1508660342" MODIFIED="1536441270931" TEXT="die Signatur im Builder konstruieren. Traits nur noch auf Signatur abstützen">
|
||||
<icon BUILTIN="full-1"/>
|
||||
</node>
|
||||
|
|
@ -31308,6 +31308,57 @@
|
|||
<node CREATED="1536441367354" ID="ID_1778093460" MODIFIED="1536441424596" TEXT="welcher eine gegebene Funktion in eine vorgegebene function<SIG> einpasst"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1536451222025" HGAP="9" ID="ID_389572303" MODIFIED="1536451229468" TEXT="Umbau" VSHIFT="5">
|
||||
<node COLOR="#338800" CREATED="1536451240308" ID="ID_241157222" MODIFIED="1536451273762" TEXT="den SRC-Parameter optional machen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1536451256034" ID="ID_645889218" MODIFIED="1536451285944" TEXT="FunTraits sind idempotent">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<icon BUILTIN="ksmiletris"/>
|
||||
<node CREATED="1536451303308" ID="ID_1343290323" MODIFIED="1536451313142" TEXT="man kann sie mit dem Funktor aufrufen -> Sig"/>
|
||||
<node CREATED="1536451313778" ID="ID_439029617" MODIFIED="1536451336475" TEXT="man kann sie mit Sig aufrufen -> Arg, Ret"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1536451345998" ID="ID_1853688774" MODIFIED="1536451360667" TEXT="Funktor-Konstruktor-Funktion">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node CREATED="1536451365731" ID="ID_552359289" MODIFIED="1536451394878" TEXT="für Aufruf aus dem Konstruktor-Kontext">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
...wo der volle Typ des Funktors FUN bekannt ist
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
</node>
|
||||
<node CREATED="1536451415725" ID="ID_1712691133" MODIFIED="1536451426247" TEXT="Bekommt SRC-Iterator als Template-Param"/>
|
||||
<node CREATED="1536451430508" ID="ID_224998497" MODIFIED="1536451471881" TEXT="wirft eine std::function<Ret(SRC&)> ab"/>
|
||||
<node CREATED="1536451473013" ID="ID_1179844665" MODIFIED="1536451543886" TEXT="in die der eigentliche Funktor geeignet adaptiert ist">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
...und in dem besonders wichtigen Fall,
|
||||
</p>
|
||||
<p>
|
||||
in dem der Funktor direkt den SRC-Iterator akzeptiert,
|
||||
</p>
|
||||
<p>
|
||||
wird er ohne Weiteres durchgereicht.
|
||||
</p>
|
||||
<p>
|
||||
In dem Fall dann <b>keine</b> doppelte Verpackung mehr!
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
|
|
|
|||
Loading…
Reference in a new issue