Invocation: reorganise and add test

This commit is contained in:
Fischlurch 2025-02-16 23:40:43 +01:00
parent 769060b9dd
commit 8bb332cc5e
4 changed files with 135 additions and 11 deletions

View file

@ -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<template<typename...> class TUP, typename...PARS>
struct TupleClosureBuilder<TUP<PARS...>>
{
using Params = TUP<PARS...>;
using Tuple = TUP<PARS...>;
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<VALS...>;
using ParamBuilderSig = Params(PARS...);
auto partialClosure = PApply<ParamBuilderSig, ClosedTypes>::bindFront (buildParam, std::make_tuple(vs...));
using RemainingArgs = typename _Fun<decltype(partialClosure)>::Args;
return wrapBuilder (func::PApply<TupleBuilderSig, ClosedTypes>::bindFront (buildParam, std::make_tuple(vs...)));
}
template<typename...VALS>
static auto
closeBack (VALS ...vs)
{
using ClosedTypes = TySeq<VALS...>;
return wrapBuilder (func::PApply<TupleBuilderSig, ClosedTypes>::bindBack (buildParam, std::make_tuple(vs...)));
}
private:
template<class CLO>
static auto
wrapBuilder (CLO partialClosure)
{
using RemainingArgs = typename _Fun<CLO>::Args;
using RemainingParams = typename lib::meta::RebindVariadic<TUP, RemainingArgs>::Type;
return [closure = move(partialClosure)
]

View file

@ -639,6 +639,11 @@ return: 0
END
PLANNED "tuple value pre-binding closure" TupleClosure_test <<END
return: 0
END
TEST "tuple metaprogramming helpers" TupleHelper_test <<END
out-lit: L1 :-<1>-<3>-<5>-
out-lit: L2 :-<2>-<4>-

View file

@ -0,0 +1,105 @@
/*
TupleClosure(Test) - appending, mixing and filtering typelists
Copyright (C)
2025, Hermann Vosseler <Ichthyostega@web.de>
  **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<int,double,string>;
using Builder = TupleClosureBuilder<Tup>;
auto cons = Builder::closeFront (1,2.3);
using FunType = _Fun<decltype(cons)>;
CHECK (FunType());
SHOW_EXPR(showType<FunType::Sig>())
CHECK (showType<FunType::Sig>() == "tuple<int, double, string> (tuple<string>)"_expect);
Tup tup = cons("five");
CHECK (tup == "«tuple<int, double, string>»──(1,2.3,five)"_expect);
}
/** @test fix elements starting from the end of the tuple
*/
void
tuple_bindBack()
{
using Tup = tuple<int,double,string>;
using Builder = TupleClosureBuilder<Tup>;
auto c1 = Builder::closeBack("π");
CHECK (showType<_Fun<decltype(c1)>::Sig>() == "tuple<int, double, string> (tuple<int, double>)"_expect);
Tup t1 = c1(make_tuple (2,3.1415));
CHECK (t1 == "«tuple<int, double, string>»──(2,3.1415,π)"_expect);
auto c2 = Builder::closeBack(3.14159265,"pi");
CHECK (showType<_Fun<decltype(c2)>::Sig>() == "tuple<int, double, string> (tuple<int>)"_expect);
Tup t2 = c2(make_tuple (-1));
CHECK (t2 == "«tuple<int, double, string>»──(-1,3.1415927,pi)"_expect);
}
};
/** Register this test class... */
LAUNCHER (TupleClosure_test, "unit common");
}}} // namespace lib::meta::test

View file

@ -106019,14 +106019,16 @@ StM_bind(Builder&lt;R1&gt; b1, Extension&lt;R1,R2&gt; extension)
Das war vielleicht der gr&#246;&#223;te Brocken, und ich hab mich da seit einigen Jahren nicht rangetraut, weil ich eine tagelange &#187;Big Bang&#171;-Aktion f&#252;rchtete. Nun mu&#223;te ich mir aber f&#252;r dieses Thema die function-closure-Utils genauer anschauen, und hab verstanden, wie die Definitionen zusammenh&#228;ngen. Hinzu kommt, da&#223; inzwischen schon ein gewisses Kern-&#214;kosystem steht, das gleicherma&#223;en mit den variadischen Sequenzen umgehen kann. Das hat mich auf die Idee gebracht, das Thema mit kreuzweisen Br&#252;cken zu entsch&#228;rfen &#8212; bei genauerer Betrachtung zeigt sich n&#228;mlich, da&#223; ein erheblicher Teil der eigentlichen Manipulations-Funktionen nicht explizit auf NullType angewiesen ist, sondern sich im Wesentlichen auf lib::meta::Prepend abst&#252;tzt. Und da nun klar ist, da&#223; in Zukunft einmal TySeq einfach die Rolle von Types &#252;bernehmen wird, per Umbenennung, ist es m&#246;glich, an vielen Stellen Spezialisierungen daneben zu stellen (markiert mit #987), die dann wieder &#252;ber die richtige Br&#252;cke zur&#252;ck f&#252;hren. Habe nun gute Hoffnung, da&#223; sich die explizit auf die alten Typlisten angewiesenen Verwendungen schritweise isolieren lassen
</p>
</body>
</html>
</richcontent>
</html></richcontent>
<icon BUILTIN="ksmiletris"/>
</node>
</node>
<node COLOR="#435e98" CREATED="1739743706096" ID="ID_1310970069" MODIFIED="1739743735573" TEXT="das ist eigentlich generisch &#x27f9; umziehen in lib::meta::TupleClosureBuilder">
<icon BUILTIN="yes"/>
</node>
<node COLOR="#338800" CREATED="1739752776321" ID="ID_376565948" MODIFIED="1739752785816" TEXT="TupleClosure_test zur Dokumentation">
<icon BUILTIN="button_ok"/>
</node>
</node>
</node>
</node>