Invocation: reorganise and add test
This commit is contained in:
parent
769060b9dd
commit
8bb332cc5e
4 changed files with 135 additions and 11 deletions
|
|
@ -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)
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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>-
|
||||
|
|
|
|||
105
tests/library/meta/tuple-closure-test.cpp
Normal file
105
tests/library/meta/tuple-closure-test.cpp
Normal 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
|
||||
|
|
@ -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
|
||||
</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 ⟹ 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>
|
||||
|
|
|
|||
Loading…
Reference in a new issue