diff --git a/src/lib/meta/tuple-closure.hpp b/src/lib/meta/tuple-closure.hpp index e2a758bc1..b77d5fa02 100644 --- a/src/lib/meta/tuple-closure.hpp +++ b/src/lib/meta/tuple-closure.hpp @@ -29,7 +29,7 @@ ** to exert artistic control and will be supplied later, through automation. ** ** @see weaving-pattern-builder.hpp - ** @see NodeBuilder_test::build_Node_closedParam() + ** @see NodeBuilder_test::build_Node_closedParam() ** */ @@ -54,9 +54,10 @@ namespace meta{ template class TUP, typename...PARS> struct TupleClosureBuilder> { - using Params = TUP; + using Tuple = TUP; + using TupleBuilderSig = Tuple(PARS...); - static Params + static Tuple buildParam (PARS ...params) { return {params...}; @@ -66,13 +67,24 @@ namespace meta{ static auto closeFront (VALS ...vs) { - using lib::meta::_Fun; - using lib::meta::TySeq; - using lib::meta::func::PApply; using ClosedTypes = TySeq; - using ParamBuilderSig = Params(PARS...); - auto partialClosure = PApply::bindFront (buildParam, std::make_tuple(vs...)); - using RemainingArgs = typename _Fun::Args; + return wrapBuilder (func::PApply::bindFront (buildParam, std::make_tuple(vs...))); + } + + template + static auto + closeBack (VALS ...vs) + { + using ClosedTypes = TySeq; + return wrapBuilder (func::PApply::bindBack (buildParam, std::make_tuple(vs...))); + } + + private: + template + static auto + wrapBuilder (CLO partialClosure) + { + using RemainingArgs = typename _Fun::Args; using RemainingParams = typename lib::meta::RebindVariadic::Type; return [closure = move(partialClosure) ] diff --git a/tests/12metaprogramming.tests b/tests/12metaprogramming.tests index 8e2b5edbf..e07db6658 100644 --- a/tests/12metaprogramming.tests +++ b/tests/12metaprogramming.tests @@ -639,6 +639,11 @@ return: 0 END +PLANNED "tuple value pre-binding closure" TupleClosure_test <-<3>-<5>- out-lit: L2 :-<2>-<4>- diff --git a/tests/library/meta/tuple-closure-test.cpp b/tests/library/meta/tuple-closure-test.cpp new file mode 100644 index 000000000..8afc7327b --- /dev/null +++ b/tests/library/meta/tuple-closure-test.cpp @@ -0,0 +1,105 @@ +/* + TupleClosure(Test) - appending, mixing and filtering typelists + + Copyright (C) + 2025, Hermann Vosseler + +  **Lumiera** is free software; you can redistribute it and/or modify it +  under the terms of the GNU General Public License as published by the +  Free Software Foundation; either version 2 of the License, or (at your +  option) any later version. See the file COPYING for further details. + +* *****************************************************************/ + + +/** @file function-closure-test.cpp + ** Unit test \ref TupleClosure_test demonstrates how to pre-bind + ** some values for construction of _tuple-like_ objects. + ** @see function-closure.hpp + ** @see NodeBuilder_test::build_Node_closedParam() "usage example" + ** + */ + + +#include "lib/test/run.hpp" +#include "lib/test/test-helper.hpp" +#include "lib/meta/tuple-closure.hpp" +#include "lib/test/diagnostic-output.hpp"////////////////TODO + + + + +namespace lib { +namespace meta { +namespace test { + + using std::string; + using std::tuple; + using std::make_tuple; + using lib::meta::_Fun; + using lib::test::showType; + + + + + /*********************************************************************//** + * @test wrap the constructors for »tuple-like« records as functor + * and pre-bind some arguments immediately. + */ + class TupleClosure_test : public Test + { + virtual void + run (Arg) + { + tuple_bindFront(); + tuple_bindBack(); + } + + + /** @test use a regular tuple and pre-fix the first elements + */ + void + tuple_bindFront() + { + using Tup = tuple; + using Builder = TupleClosureBuilder; + + auto cons = Builder::closeFront (1,2.3); + using FunType = _Fun; + CHECK (FunType()); +SHOW_EXPR(showType()) + CHECK (showType() == "tuple (tuple)"_expect); + + Tup tup = cons("five"); + CHECK (tup == "«tuple»──(1,2.3,five)"_expect); + } + + + /** @test fix elements starting from the end of the tuple + */ + void + tuple_bindBack() + { + using Tup = tuple; + using Builder = TupleClosureBuilder; + + auto c1 = Builder::closeBack("π"); + CHECK (showType<_Fun::Sig>() == "tuple (tuple)"_expect); + + Tup t1 = c1(make_tuple (2,3.1415)); + CHECK (t1 == "«tuple»──(2,3.1415,π)"_expect); + auto c2 = Builder::closeBack(3.14159265,"pi"); + CHECK (showType<_Fun::Sig>() == "tuple (tuple)"_expect); + + Tup t2 = c2(make_tuple (-1)); + CHECK (t2 == "«tuple»──(-1,3.1415927,pi)"_expect); + } + }; + + + /** Register this test class... */ + LAUNCHER (TupleClosure_test, "unit common"); + + + +}}} // namespace lib::meta::test diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index c84b8a499..f95f556da 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -106019,14 +106019,16 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension) Das war vielleicht der größte Brocken, und ich hab mich da seit einigen Jahren nicht rangetraut, weil ich eine tagelange »Big Bang«-Aktion fürchtete. Nun mußte ich mir aber für dieses Thema die function-closure-Utils genauer anschauen, und hab verstanden, wie die Definitionen zusammenhängen. Hinzu kommt, daß inzwischen schon ein gewisses Kern-Ökosystem steht, das gleichermaßen mit den variadischen Sequenzen umgehen kann. Das hat mich auf die Idee gebracht, das Thema mit kreuzweisen Brücken zu entschärfen — bei genauerer Betrachtung zeigt sich nämlich, daß ein erheblicher Teil der eigentlichen Manipulations-Funktionen nicht explizit auf NullType angewiesen ist, sondern sich im Wesentlichen auf lib::meta::Prepend abstützt. Und da nun klar ist, daß in Zukunft einmal TySeq einfach die Rolle von Types übernehmen wird, per Umbenennung, ist es möglich, an vielen Stellen Spezialisierungen daneben zu stellen (markiert mit #987), die dann wieder über die richtige Brücke zurück führen. Habe nun gute Hoffnung, daß sich die explizit auf die alten Typlisten angewiesenen Verwendungen schritweise isolieren lassen

- - + + + +