Library: RandomDraw - invent new scheme for dynamic configuration
...now using the reworked partial-application helper... ...bind to *this and then recursively re-invoke the adaptation process ...need also to copy-capture the previously existing mapping-function first test seems to work now
This commit is contained in:
parent
32b740cd40
commit
3808166494
3 changed files with 108 additions and 60 deletions
|
|
@ -302,6 +302,15 @@ namespace lib {
|
|||
|
||||
|
||||
private:
|
||||
template<class SIG>
|
||||
struct is_Manipulator
|
||||
: std::false_type { };
|
||||
|
||||
template<typename...ARGS>
|
||||
struct is_Manipulator<void(RandomDraw&, ARGS...)>
|
||||
: std::true_type { };
|
||||
|
||||
|
||||
/** @internal adapt input side of a given function to conform to the
|
||||
* global input arguments as defined in the Policy base function.
|
||||
* @return a function pre-fitted with a suitable Adapter from the Policy */
|
||||
|
|
@ -309,6 +318,7 @@ namespace lib {
|
|||
decltype(auto)
|
||||
adaptIn (FUN&& fun)
|
||||
{
|
||||
using lib::meta::func::applyFirst;
|
||||
using _Fun = lib::meta::_Fun<FUN>;
|
||||
static_assert (_Fun(), "Need something function-like.");
|
||||
|
||||
|
|
@ -320,6 +330,10 @@ namespace lib {
|
|||
if constexpr (std::is_same_v<Args, BaseIn>)
|
||||
// function accepts same arguments as this RandomDraw
|
||||
return forward<FUN> (fun); // pass-through directly
|
||||
else
|
||||
if constexpr (is_Manipulator<Sig>())
|
||||
// function wants to manipulate *this dynamically...
|
||||
return adaptIn (applyFirst(forward<FUN> (fun), *this));
|
||||
else
|
||||
return Adaptor::build (forward<FUN> (fun));
|
||||
}
|
||||
|
|
@ -356,17 +370,36 @@ namespace lib {
|
|||
,[this](double rand){ return limited(rand); }
|
||||
);
|
||||
else
|
||||
if constexpr (std::is_same_v<Res, RandomDraw>)// ◁────────────────────┨ function yields parametrised RandomDraw to invoke
|
||||
return [functor=std::forward<FUN>(fun), this]
|
||||
(auto&& ...inArgs) -> _FunRet<RandomDraw>
|
||||
{ // invoke with copy
|
||||
RandomDraw parametricDraw = functor(inArgs...);
|
||||
return parametricDraw (forward<decltype(inArgs)> (inArgs)...);
|
||||
}; // forward arguments
|
||||
if constexpr (std::is_same_v<Res, void>) // ◁──────────────────────────┨ function manipulates parameters by side-effect
|
||||
return [functor=std::forward<FUN>(fun)
|
||||
,processDraw=getCurrMapping()]
|
||||
(auto&& ...inArgs) mutable -> _FunRet<RandomDraw>
|
||||
{
|
||||
functor(inArgs...); // invoke manipulator with copy
|
||||
return processDraw (forward<decltype(inArgs)> (inArgs)...);
|
||||
}; // forward arguments to *this
|
||||
else
|
||||
static_assert (not sizeof(Res), "unable to adapt / handle result type");
|
||||
NOTREACHED("Handle based on return type");
|
||||
}
|
||||
|
||||
|
||||
/** @internal capture the current mapping processing-chain as function.
|
||||
* RandomDraw is-a function to process and map the input argument into a
|
||||
* limited and quantised output value. The actual chain can be re-configured.
|
||||
* This function picks up a snapshot copy of the current configuration; it is
|
||||
* used to build a chain of functions, which incorporates this current function.
|
||||
* If no function was configured yet, the default processing chain is returned.
|
||||
*/
|
||||
Fun
|
||||
getCurrMapping()
|
||||
{
|
||||
Fun& currentProcessingFunction = *this;
|
||||
if (not currentProcessingFunction)
|
||||
return Fun{adaptOut(POL::defaultSrc)};
|
||||
else
|
||||
return Fun{currentProcessingFunction};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ namespace test{
|
|||
build (FUN&& fun)
|
||||
{
|
||||
return [functor=std::forward<FUN>(fun)]
|
||||
(size_t hash) -> _FunRet<FUN>
|
||||
(size_t hash) mutable -> _FunRet<FUN>
|
||||
{
|
||||
return functor(uint(hash/64), uint(hash%64));
|
||||
};
|
||||
|
|
@ -731,53 +731,47 @@ namespace test{
|
|||
void
|
||||
verify_dynamicChange()
|
||||
{
|
||||
// auto d1 = Draw([](Draw& draw, uint cycle, uint){
|
||||
// draw.probability(cycle*0.2);
|
||||
// });
|
||||
//
|
||||
//SHOW_EXPR(int(d1( 0)));
|
||||
//SHOW_EXPR(int(d1( 1)));
|
||||
//SHOW_EXPR(int(d1( 2)));
|
||||
//SHOW_EXPR(int(d1( 16)));
|
||||
//SHOW_EXPR(int(d1( 32)));
|
||||
//SHOW_EXPR(int(d1( 48)));
|
||||
//SHOW_EXPR(int(d1( 63)));
|
||||
//SHOW_EXPR(int(d1( 64)));
|
||||
//SHOW_EXPR(int(d1( 64 +1)));
|
||||
//SHOW_EXPR(int(d1( 64 +2)));
|
||||
//SHOW_EXPR(int(d1( 64+16)));
|
||||
//SHOW_EXPR(int(d1( 64+32)));
|
||||
//SHOW_EXPR(int(d1( 64+48)));
|
||||
//SHOW_EXPR(int(d1( 64+64)));
|
||||
//SHOW_EXPR(int(d1(128 +16)));
|
||||
//SHOW_EXPR(int(d1(128 +32)));
|
||||
//SHOW_EXPR(int(d1(128 +48)));
|
||||
//SHOW_EXPR(int(d1(128 +64)));
|
||||
//SHOW_EXPR(int(d1(128+64+16)));
|
||||
//SHOW_EXPR(int(d1(128+64+32)));
|
||||
//SHOW_EXPR(int(d1(128+64+48)));
|
||||
//SHOW_EXPR(int(d1(128+64+64)));
|
||||
int yy = 99;
|
||||
float ff = 88;
|
||||
auto fuK = std::function{[](float& f, int& i, size_t s) -> double { return f + i + s; }};
|
||||
auto& f1 = fuK;
|
||||
auto f2 = lib::meta::func::applyFirst(f1, ff);
|
||||
using lib::meta::_Fun;
|
||||
using Sig1 = _Fun<decltype(f1)>::Sig;
|
||||
using Sig2 = _Fun<decltype(f2)>::Sig;
|
||||
yy = 22;
|
||||
ff = 42;
|
||||
SHOW_TYPE(Sig1)
|
||||
SHOW_TYPE(Sig2)
|
||||
SHOW_EXPR(f1 (ff,yy,33))
|
||||
SHOW_EXPR(f2 ( yy,33))
|
||||
SHOW_TYPE(decltype(f2 ( yy,33)))
|
||||
SHOW_TYPE(decltype(f2))
|
||||
auto d1 = Draw([](Draw& draw, uint cycle, uint){
|
||||
draw.probability((cycle+1)*0.25);
|
||||
});
|
||||
|
||||
fuK = [](float& f, int& i, size_t s) -> double { return f * i * s; };
|
||||
|
||||
SHOW_EXPR(f1 (ff,yy,33))
|
||||
SHOW_EXPR(f2 ( yy,33))
|
||||
SHOW_EXPR(int(d1( 0)));
|
||||
SHOW_EXPR(int(d1( 8)));
|
||||
SHOW_EXPR(int(d1( 16)));
|
||||
SHOW_EXPR(int(d1( 24)));
|
||||
SHOW_EXPR(int(d1( 32)));
|
||||
SHOW_EXPR(int(d1( 40)));
|
||||
SHOW_EXPR(int(d1( 48)));
|
||||
SHOW_EXPR(int(d1( 56)));
|
||||
SHOW_EXPR(int(d1( 63)));
|
||||
SHOW_EXPR(int(d1( 64 +0)));
|
||||
SHOW_EXPR(int(d1( 64 +8)));
|
||||
SHOW_EXPR(int(d1( 64+16)));
|
||||
SHOW_EXPR(int(d1( 64+24)));
|
||||
SHOW_EXPR(int(d1( 64+32)));
|
||||
SHOW_EXPR(int(d1( 64+40)));
|
||||
SHOW_EXPR(int(d1( 64+48)));
|
||||
SHOW_EXPR(int(d1( 64+56)));
|
||||
SHOW_EXPR(int(d1( 64+63)));
|
||||
SHOW_EXPR(int(d1(128 +0)));
|
||||
SHOW_EXPR(int(d1(128 +8)));
|
||||
SHOW_EXPR(int(d1(128 +16)));
|
||||
SHOW_EXPR(int(d1(128 +24)));
|
||||
SHOW_EXPR(int(d1(128 +32)));
|
||||
SHOW_EXPR(int(d1(128 +40)));
|
||||
SHOW_EXPR(int(d1(128 +48)));
|
||||
SHOW_EXPR(int(d1(128 +56)));
|
||||
SHOW_EXPR(int(d1(128 +63)));
|
||||
SHOW_EXPR(int(d1(128+64 +0)));
|
||||
SHOW_EXPR(int(d1(128+64 +8)));
|
||||
SHOW_EXPR(int(d1(128+64+16)));
|
||||
SHOW_EXPR(int(d1(128+64+24)));
|
||||
SHOW_EXPR(int(d1(128+64+32)));
|
||||
SHOW_EXPR(int(d1(128+64+40)));
|
||||
SHOW_EXPR(int(d1(128+64+48)));
|
||||
SHOW_EXPR(int(d1(128+64+56)));
|
||||
SHOW_EXPR(int(d1(128+64+63)));
|
||||
SHOW_EXPR(int(d1(128+64+64)));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -97271,17 +97271,35 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1700686650589" ID="ID_1320986357" MODIFIED="1700686659027" TEXT="adaptIn">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1700686611506" ID="ID_1055056344" MODIFIED="1700686621481" TEXT="partielle Anwendung anwenden">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1700686611506" ID="ID_1055056344" MODIFIED="1700689287526" TEXT="partielle Anwendung anwenden">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1700686662293" ID="ID_473080725" MODIFIED="1700689290635" TEXT="sich selbst damit rekursiv aufrufen">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node CREATED="1700693151634" ID="ID_543764264" MODIFIED="1700693171222" TEXT="alle Adapter müssen nun mutable sein...">
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#f0d5c5" COLOR="#990033" CREATED="1700693175075" ID="ID_1513609596" MODIFIED="1700693181849" TEXT="wie ist es dazu gekommen?">
|
||||
<icon BUILTIN="help"/>
|
||||
<node CREATED="1700693202666" ID="ID_814650434" MODIFIED="1700693213189" TEXT="hatte das für die partial-Application eingeführt"/>
|
||||
<node CREATED="1700693214680" ID="ID_985740260" MODIFIED="1700693228403" TEXT="es gab Probleme beim Binden eines Referenz-Arguments"/>
|
||||
<node CREATED="1700693240581" ID="ID_575005517" MODIFIED="1700693260979" TEXT="das habe ich weggebügelt, indem ich den neuen Functor mutable deklarierte"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1700686662293" ID="ID_473080725" MODIFIED="1700686674078" TEXT="sich selbst damit rekursiv aufrufen">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1700686675275" ID="ID_1836010727" MODIFIED="1700686690830" TEXT="adaptOut">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1700686680324" ID="ID_1784901789" MODIFIED="1700686688050" TEXT="neuer Zweig für void-Funktionen">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1700686680324" ID="ID_1784901789" MODIFIED="1700693190988" TEXT="neuer Zweig für void-Funktionen">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node BACKGROUND_COLOR="#e0ceaa" COLOR="#690f14" CREATED="1700693081579" ID="ID_1255600194" MODIFIED="1700693088337" TEXT="Endlos-Schleife">
|
||||
<icon BUILTIN="broken-line"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1700693091977" ID="ID_1659118434" MODIFIED="1700693195468" TEXT="muß die vorher bestehende proc-Function kopieren">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1700693108791" ID="ID_1579958101" MODIFIED="1700693196796" TEXT="...und in die neue λ-closure speichern">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1700686695792" ID="ID_1003013120" MODIFIED="1700686699584" TEXT="beide integriert">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
|
|
@ -97290,6 +97308,9 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1700686712454" ID="ID_194082456" MODIFIED="1700686717365" TEXT="im Test verifizieren">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1700693276905" ID="ID_925123517" MODIFIED="1700693285048" TEXT="erster Testfall sieht plausibel aus">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
|
|
|
|||
Loading…
Reference in a new issue