From 412abbace211e0571e698f1be077e6d63e2bc070 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 3 Jun 2025 16:14:13 +0200 Subject: [PATCH] clean-up: validate use of variadic seq with tuples and generators Most of the type-list and type-sequence related eccosystem can be just switched over, after having added the conversion variants for the new-style variadic type sequences Again this was used as opportunity to improve readability of related tests --- src/lib/meta/variadic-helper.hpp | 20 ++-- src/stage/interact/ui-location-solver.hpp | 2 +- tests/12metaprogramming.tests | 36 +------- .../meta/generator-combinations-test.cpp | 12 +-- tests/library/meta/tuple-helper-test.cpp | 34 ++++--- tests/library/meta/tuple-record-init-test.cpp | 41 +++++---- tests/library/meta/typelist-manip-test.cpp | 2 +- tests/library/meta/typeseq-manip-test.cpp | 91 ++++++++----------- wiki/thinkPad.ichthyo.mm | 43 ++++++--- 9 files changed, 141 insertions(+), 140 deletions(-) diff --git a/src/lib/meta/variadic-helper.hpp b/src/lib/meta/variadic-helper.hpp index 235905aa9..6f4eb57e2 100644 --- a/src/lib/meta/variadic-helper.hpp +++ b/src/lib/meta/variadic-helper.hpp @@ -94,22 +94,22 @@ namespace meta { template<> struct BuildIndexSeq<0> { - using Empty = IndexSeq<>; + using EmptySeq = IndexSeq<>; - using Ascending = Empty; - using Descending = Empty; + using Ascending = EmptySeq; + using Descending = EmptySeq; template - using OffsetBy = Empty; + using OffsetBy = EmptySeq; template - using FilledWith = Empty; + using FilledWith = EmptySeq; template - using First = Empty; + using First = EmptySeq; template - using After = Empty; + using After = EmptySeq; }; @@ -140,6 +140,7 @@ namespace meta { }; /** build an index number sequence from a type sequence */ + //////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #987 temporary WORKAROUND -- to be obsoleted template struct BuildIdxIter> { @@ -162,6 +163,11 @@ namespace meta { template using After = typename Builder::template After; }; + //////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #987 temporary WORKAROUND(END) + template + struct BuildIdxIter> + : BuildIdxIter + { }; diff --git a/src/stage/interact/ui-location-solver.hpp b/src/stage/interact/ui-location-solver.hpp index bef4a0c06..85efbaacc 100644 --- a/src/stage/interact/ui-location-solver.hpp +++ b/src/stage/interact/ui-location-solver.hpp @@ -277,7 +277,7 @@ namespace interact { // append ID of the new element to be created // unless it's already there (and thus exists) resolver.append (elementTypeID); - return move (resolver); //////////////////////////////////////////////////////////////////TICKET #1402 : need a better solution for the builder-terminal-op. (it collides with the templated UICoord ctor) + return move (resolver); //////////////////////////////////////////////////////////////////TICKET #1402 : need a better solution for the builder-terminal-op. (it collides with the templated UICoord ctor) |NOTE: the compiler waring is wrong here, the move() is essential // use the first suitable solution and exit } else diff --git a/tests/12metaprogramming.tests b/tests/12metaprogramming.tests index 38fa4fa8f..f0a54891b 100644 --- a/tests/12metaprogramming.tests +++ b/tests/12metaprogramming.tests @@ -374,36 +374,7 @@ return: 0 END -TEST "type sequence manipulation" TypeSeqManipl_test <-<2>-<3>-<7>-<8>-<9>- -out: Seq :-<1>-<2>-<3>-<7>-<8>-<9>- -out: SeqList :-<1>-<2>-<3>-<7>-<8>-<9>- -out: NulS :- -out: Prepend1 :-<5>-<1>-<2>-<3>- -out: Prepend2 :-<·>-<1>-<2>-<3>- -out: Prepend3 :-<5>- -out: Prepend4 :- -out: Seq_0 :-<7>-<8>-<9>-<1>-<2>-<3>- -out: Seq_1 :-<8>-<9>-<1>-<2>-<3>- -out: Seq_2 :-<9>-<1>-<2>-<3>- -out: Seq_3 :-<1>-<2>-<3>- -out: Seq_4 :-<2>-<3>- -out: Seq_5 :-<3>- -out: Seq_6 :- -out: Head_0 :-<7>- -out: Head_1 :-<8>- -out: Head_2 :-<9>- -out: Head_3 :-<1>- -out: Head_4 :-<2>- -out: Head_5 :-<3>- -out: Head_6 :- -out: Seq :-<1>-<2>-<3>-<7>-<8>-<9>- -out: List :-<1>-<2>-<3>-<7>-<8>-<9>- -out: First :-<1>- -out: Tail :-<2>-<3>-<7>-<8>-<9>- -out: Prefix :-<1>-<2>-<3>-<7>-<8>- -out: Last :-<9>- -out: HeadEnd :-<1>-<9>- +TEST "type sequence manipulation" TypeSeqManip_test <- out-lit: Tup1 :TUPLE-<1>-<3>-<5>- out-lit: Tup1() :«tuple, Num<3>, Num<5> >»──((1),(3),(5)) out-lit: tup1x :«tuple, Num<3>, Num<5> >»──({11},(3),{55}) -out-lit: T_L1 :TUPLE-<1>-<3>-<5>- -out-lit: Seq1 :-<1>-<3>-<5>- -out-lit: tup1 :«tuple, Num<3>, Num<5> >»──((1),(3),(5)) -out-lit: Prepend :TUPLE--<1>-<3>-<5>- -out-lit: prep :«tuple, Num<3>, Num<5> >»──(22,{11},{33},(5)) out-lit: «tuple, Num<3>, Num<5> >»──((1),(3),(5)) out-lit: «tuple, Num<3>, Num<5> >»──(22,{11},{33},(5)) out-lit: «tuple<>»──() diff --git a/tests/library/meta/generator-combinations-test.cpp b/tests/library/meta/generator-combinations-test.cpp index cdafc66db..e63e3423c 100644 --- a/tests/library/meta/generator-combinations-test.cpp +++ b/tests/library/meta/generator-combinations-test.cpp @@ -35,11 +35,11 @@ namespace test { namespace { // test cases and data.... - typedef TyOLD< Num<1> + typedef TySeq< Num<1> , Num<3> , Num<5> > Types1; - typedef TyOLD< Num<2> + typedef TySeq< Num<2> , Num<4> , Num<6> > Types2; @@ -95,7 +95,7 @@ namespace test { class GeneratorCombinations_test : public Test { virtual void - run (Arg) + run (Arg) { checkCartesian(); checkCaseInstantiation(); @@ -113,9 +113,9 @@ namespace test { void checkCaseInstantiation () { - typedef InstantiateChainedCombinations< Types1,Types2 - , TestCase - , IterationEnd > CombnationCases; + using CombnationCases = InstantiateChainedCombinations< Types1,Types2 + , TestCase + , IterationEnd >; cout << "All-Test-Combinations-" << CombnationCases::visitAll() << endl; } diff --git a/tests/library/meta/tuple-helper-test.cpp b/tests/library/meta/tuple-helper-test.cpp index deb020cf4..b26ac7967 100644 --- a/tests/library/meta/tuple-helper-test.cpp +++ b/tests/library/meta/tuple-helper-test.cpp @@ -29,10 +29,11 @@ #include "meta/tuple-diagnostics.hpp" #include "lib/format-cout.hpp" +#include -using ::test::Test; using lib::test::showSizeof; - +using util::toString; +using std::get; namespace lib { namespace meta { @@ -43,14 +44,14 @@ namespace test { namespace { // test data - typedef TyOLD< Num<1> + typedef TySeq< Num<1> , Num<3> , Num<5> > Types1; - typedef TyOLD< Num<2> + typedef TySeq< Num<2> , Num<4> > Types2; - typedef TyOLD< Num<7>> Types3; + typedef TySeq< Num<7>> Types3; @@ -97,6 +98,11 @@ namespace test { DISPLAY (Tup1); // prints the type DUMPVAL (Tup1()); // prints the contents DUMPVAL (tup1x); + + EXPECT (Types1, "-<1>-<3>-<5>-"); + EXPECT (Tup1, "TUPLE-<1>-<3>-<5>-"); + CHECK (get<2>(tup1x) == Num<5>{55}); + CHECK (toString(tup1x) == "«tuple, Num<3>, Num<5> >»──({11},(3),{55})"_expect); } @@ -113,23 +119,27 @@ namespace test { using T_L1 = Tuple; // derive a tuple type from this typelist using Seq1 = RebindTupleTypes::Seq; // extract the underlying type sequence - DISPLAY (T_L1); - DISPLAY (Seq1); + EXPECT (T_L1, "TUPLE-<1>-<3>-<5>-"); + EXPECT (Seq1, "-<1>-<3>-<5>-"); T_L1 tup1; // can be instantiated at runtime (and is just a std:tuple) - DUMPVAL (tup1); + CHECK (toString(tup1) == "«tuple, Num<3>, Num<5> >»──((1),(3),(5))"_expect); using Prepend = Tuple>; - DISPLAY (Prepend); // another ListType based tuple created by prepending + // another ListType based tuple created by prepending + EXPECT (Prepend, "TUPLE--<1>-<3>-<5>-"); Prepend prep (22, 11,33,Num<5>()); - DUMPVAL (prep); + CHECK (toString(prep) == "«tuple, Num<3>, Num<5> >»──(22,{11},{33},(5))"_expect); - using NulT = Tuple >; // plain-flat empty Tuple + using NulT = Tuple >; // plain-flat empty Tuple using NulL = Tuple; // list-style empty Tuple NulT nulT; // and these, too, can be instantiated NulL nulL; + CHECK (toString(nulT) == "«tuple<>»──()"_expect); + CHECK (toString(nulL) == "«tuple<>»──()"_expect); + CHECK ((is_same())); using S4 = struct{int a,b,c,d;}; // expect this to have the same memory layout CHECK (sizeof(S4) == sizeof(prep)); @@ -149,6 +159,8 @@ namespace test { << showSizeof(prep) <)+sizeof(Num<3>)+sizeof(Num<5>)); } }; diff --git a/tests/library/meta/tuple-record-init-test.cpp b/tests/library/meta/tuple-record-init-test.cpp index 171156913..64ffa64b3 100644 --- a/tests/library/meta/tuple-record-init-test.cpp +++ b/tests/library/meta/tuple-record-init-test.cpp @@ -31,7 +31,7 @@ using lib::idi::EntryID; using lib::diff::Rec; using lib::diff::MakeRec; using lib::diff::GenNode; -using lib::meta::TyOLD; +using lib::meta::TySeq; using lib::meta::Tuple; using lib::meta::buildTuple; using lib::time::Duration; @@ -82,8 +82,8 @@ namespace test { void show_simpleUsage() { - using NiceTypes = TyOLD; - using UgglyTypes = TyOLD, Symbol, int, int64_t, double, Duration>; // various conversions and an immutable type (Duration) + using NiceTypes = TySeq; + using UgglyTypes = TySeq, Symbol, int, int64_t, double, Duration>; // various conversions and an immutable type (Duration) Rec args = MakeRec().scope("lalü", 42); Rec urgs = MakeRec().scope("lalü", "lala", 12, 34, 5.6, Time(7,8,9)); @@ -91,8 +91,15 @@ namespace test { cout << args < (args) < (urgs) < (args); + auto urgT = buildTuple (urgs); + + cout << argT <(argT) == "lalü"_expect); + CHECK (get<0>(urgT) == "ID-lal"_expect); + CHECK (get<1>(urgT) == "lala"_expect); } @@ -101,19 +108,19 @@ namespace test { { Rec args = MakeRec().scope("surprise", 42); - using TooMany = TyOLD; + using TooMany = TySeq; VERIFY_ERROR (WRONG_TYPE, buildTuple (args)); // number of types in tuple exceeds capacity of the supplied argument record - using Unsigned = TyOLD; - using Floating = TyOLD; - using Narrowing = TyOLD; + using Unsigned = TySeq; + using Floating = TySeq; + using Narrowing = TySeq; VERIFY_ERROR (WRONG_TYPE, buildTuple (args)); // dangerous conversion from signed to unsigned int is prohibited VERIFY_ERROR (WRONG_TYPE, buildTuple (args)); // conversion from integral to floating point element is prohibited VERIFY_ERROR (WRONG_TYPE, buildTuple (args)); // narrowing conversion from int to short is prohibited // yet other (non-numeric) conversions are still possible Rec timeArg = MakeRec().scope(Time(1,2,3,4)); - using TupStr = TyOLD; + using TupStr = TySeq; Tuple tup = buildTuple (timeArg); CHECK (std::get (tup) == "4:03:02.001"); @@ -126,24 +133,24 @@ namespace test { VERIFY_ERROR (WRONG_TYPE, buildTuple (args)); VERIFY_ERROR (WRONG_TYPE, buildTuple (args)); - using ToSizeT = TyOLD; + using ToSizeT = TySeq; VERIFY_ERROR (WRONG_TYPE, (buildTuple (args))); // not even conversion to size_t is allowed - struct Dummy + struct Hashy { HashVal hash; - Dummy (LuidH const& luid) + Hashy (LuidH const& luid) : hash(luid) { } }; - using WithDummy = TyOLD; + using WithHashy = TySeq; - Tuple tup2 = buildTuple (hashArg); // while any type explicitly constructible from LUID are permitted. - VERIFY_ERROR (WRONG_TYPE, buildTuple (args)); // building a Dummy from int(42) is disallowed, of course + Tuple tup2 = buildTuple (hashArg); // while any type explicitly constructible from LUID are permitted. + VERIFY_ERROR (WRONG_TYPE, buildTuple (args)); // building a `Hashy` from int(42) is disallowed, of course - HashVal h = get(tup2).hash; + HashVal h = get(tup2).hash; CHECK (h == hashArg.child(1).data.get()); // note: the narrowing conversion happens within LuidH::operator HashVal() } }; diff --git a/tests/library/meta/typelist-manip-test.cpp b/tests/library/meta/typelist-manip-test.cpp index c251f93d3..1c76703e1 100644 --- a/tests/library/meta/typelist-manip-test.cpp +++ b/tests/library/meta/typelist-manip-test.cpp @@ -33,7 +33,6 @@ #include "lib/meta/generator.hpp" #include "lib/meta/typelist-manip.hpp" #include "meta/typelist-diagnostics.hpp" -#include "lib/test/diagnostic-output.hpp"/////////////////TODO #include @@ -383,6 +382,7 @@ namespace test { /** @test demonstrate special setup to enumerate case combinations * @remark can be used to pre-generate template instantiations * at compile time, for a complete configuration space + * @see GeneratorCombinations_test */ void verify_combine() diff --git a/tests/library/meta/typeseq-manip-test.cpp b/tests/library/meta/typeseq-manip-test.cpp index a2902a739..b1df48ced 100644 --- a/tests/library/meta/typeseq-manip-test.cpp +++ b/tests/library/meta/typeseq-manip-test.cpp @@ -14,7 +14,7 @@ /** @file typeseq-manip-test.cpp ** verify the proper working of simple type sequence manipulations. - ** Here, "type sequence" denotes an instance of the template Types from + ** Here, "type sequence" stands for an instance of the template Types from ** typelist.hpp . While this template is the entry point to type list metaprogramming, ** in many cases it is useful on its own for specifying a fixed collection of types, e.g. ** for building a tuple type. Thus, while more complicated manipulations typically rely @@ -32,7 +32,6 @@ #include "lib/meta/typeseq-util.hpp" #include "lib/meta/typelist-manip.hpp" #include "meta/typelist-diagnostics.hpp" -#include "lib/format-cout.hpp" using std::string; @@ -42,19 +41,17 @@ namespace meta { namespace test { - namespace { // test data + namespace { // type-sequences to test with - typedef TyOLD< Num<1> + typedef TySeq< Num<1> , Num<2> , Num<3> > Types1; - typedef TyOLD< Num<7> + typedef TySeq< Num<7> , Num<8> , Num<9> > Types2; - // see also the CountDown template in typelist-diagnostics.hpp... - } // (End) test data @@ -69,10 +66,10 @@ namespace test { * - create shifted sequences * - dissect a sequence to extract head, tail, prefix, last element */ - class TypeSeqManipl_test : public Test + class TypeSeqManip_test : public Test { virtual void - run (Arg) + run (Arg) { check_indexOf (); check_buildSeq(); @@ -97,32 +94,25 @@ namespace test { check_buildSeq () { using LL = Append::List; - DISPLAY (LL); + EXPECT (LL, "-<1>-<2>-<3>-<7>-<8>-<9>-"); - using Seq = TyOLD::Seq; + using Seq = TySeq::Seq; using SeqList = Seq::List; - DISPLAY (Seq); - DISPLAY (SeqList); + EXPECT (Seq, "-<1>-<2>-<3>-<7>-<8>-<9>-"); + EXPECT (SeqList, "-<1>-<2>-<3>-<7>-<8>-<9>-"); - using NulS = TyOLD::Seq; - DISPLAY (NulS); + using NulS = TySeq::Seq; + EXPECT (NulS, "-"); } void check_prepend () { - using Prepend1 = Prepend, Types1 >; - DISPLAY(Prepend1); - - using Prepend2 = Prepend; - DISPLAY(Prepend2); - - using Prepend3 = Prepend, TyOLD<>>; - DISPLAY(Prepend3); - - using Prepend4 = Prepend>; - DISPLAY(Prepend4); + using Prepend1 = Prepend, Types1 >; EXPECT (Prepend1, "-<5>-<1>-<2>-<3>-"); + using Prepend2 = Prepend; EXPECT (Prepend2, "-<·>-<1>-<2>-<3>-"); + using Prepend3 = Prepend, TySeq<>>; EXPECT (Prepend3, "-<5>-"); + using Prepend4 = Prepend>; EXPECT (Prepend4, "-"); } @@ -130,23 +120,23 @@ namespace test { check_shift () { using LL = Append::List; - using Seq = TyOLD::Seq; + using Seq = TySeq::Seq; - using Seq_0 = Shifted::Type; DISPLAY (Seq_0); - using Seq_1 = Shifted::Type; DISPLAY (Seq_1); - using Seq_2 = Shifted::Type; DISPLAY (Seq_2); - using Seq_3 = Shifted::Type; DISPLAY (Seq_3); - using Seq_4 = Shifted::Type; DISPLAY (Seq_4); - using Seq_5 = Shifted::Type; DISPLAY (Seq_5); - using Seq_6 = Shifted::Type; DISPLAY (Seq_6); + using Seq_0 = Shifted::Type; EXPECT (Seq_0, "-<7>-<8>-<9>-<1>-<2>-<3>-"); + using Seq_1 = Shifted::Type; EXPECT (Seq_1, "-<8>-<9>-<1>-<2>-<3>-"); + using Seq_2 = Shifted::Type; EXPECT (Seq_2, "-<9>-<1>-<2>-<3>-"); + using Seq_3 = Shifted::Type; EXPECT (Seq_3, "-<1>-<2>-<3>-"); + using Seq_4 = Shifted::Type; EXPECT (Seq_4, "-<2>-<3>-"); + using Seq_5 = Shifted::Type; EXPECT (Seq_5, "-<3>-"); + using Seq_6 = Shifted::Type; EXPECT (Seq_6, "-"); - using Head_0 = TyOLD::Head>; DISPLAY (Head_0); - using Head_1 = TyOLD::Head>; DISPLAY (Head_1); - using Head_2 = TyOLD::Head>; DISPLAY (Head_2); - using Head_3 = TyOLD::Head>; DISPLAY (Head_3); - using Head_4 = TyOLD::Head>; DISPLAY (Head_4); - using Head_5 = TyOLD::Head>; DISPLAY (Head_5); - using Head_6 = TyOLD::Head>; DISPLAY (Head_6); + using Head_0 = TySeq::Head>; EXPECT (Head_0, "-<7>-"); + using Head_1 = TySeq::Head>; EXPECT (Head_1, "-<8>-"); + using Head_2 = TySeq::Head>; EXPECT (Head_2, "-<9>-"); + using Head_3 = TySeq::Head>; EXPECT (Head_3, "-<1>-"); + using Head_4 = TySeq::Head>; EXPECT (Head_4, "-<2>-"); + using Head_5 = TySeq::Head>; EXPECT (Head_5, "-<3>-"); + using Head_6 = TySeq::Head>; EXPECT (Head_6, "-"); } @@ -154,19 +144,18 @@ namespace test { check_split () { using LL = Append::List; - using Seq = TyOLD::Seq; - DISPLAY (Seq); + using Seq = TySeq::Seq; EXPECT (Seq , "-<1>-<2>-<3>-<7>-<8>-<9>-"); - using List = Split::List; DISPLAY(List); - using First = Split::First; DISPLAY(First); - using Tail = Split::Tail; DISPLAY(Tail); - using Prefix = Split::Prefix; DISPLAY(Prefix); - using Last = Split::Last; DISPLAY(Last); + using List = Split::List; EXPECT (List , "-<1>-<2>-<3>-<7>-<8>-<9>-"); + using First = Split::First; EXPECT (First , "-<1>-" ); + using Tail = Split::Tail; EXPECT (Tail , "-<2>-<3>-<7>-<8>-<9>-" ); + using Prefix = Split::Prefix; EXPECT (Prefix, "-<1>-<2>-<3>-<7>-<8>-" ); + using Last = Split::Last; EXPECT (Last , "-<9>-" ); using Head = Split::Head; - using End = Split::End; + using End = Split::End; - using HeadEnd = TyOLD; DISPLAY(HeadEnd); + using HeadEnd = TySeq; EXPECT (HeadEnd, "-<1>-<9>-"); } @@ -174,7 +163,7 @@ namespace test { /** Register this test class... */ - LAUNCHER (TypeSeqManipl_test, "unit common"); + LAUNCHER (TypeSeqManip_test, "unit common"); diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index ce60d476e..04dab7a16 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -164294,8 +164294,11 @@ Since then others have made contributions, see the log for the history. - - + + + + + @@ -164337,8 +164340,13 @@ Since then others have made contributions, see the log for the history. - - + + + + + + + @@ -164348,7 +164356,13 @@ Since then others have made contributions, see the log for the history. - + + + + + + + @@ -164385,16 +164399,23 @@ Since then others have made contributions, see the log for the history. - - - - + + + + + + + + + + + + - - +