2009-06-20 18:06:07 +02:00
|
|
|
|
/*
|
2016-01-17 23:55:41 +01:00
|
|
|
|
TupleHelper(Test) - verify helpers for working with tuples and type sequences
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**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.
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
* *****************************************************************/
|
2009-06-20 18:06:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
2017-04-02 04:22:51 +02:00
|
|
|
|
/** @file tuple-helper-test.cpp
|
2016-01-17 23:55:41 +01:00
|
|
|
|
** Interplay of typelists, type tuples and std::tuple.
|
2010-12-17 22:51:27 +01:00
|
|
|
|
**
|
2016-01-17 23:55:41 +01:00
|
|
|
|
** @see tuple-helper.hpp
|
2009-06-20 18:06:07 +02:00
|
|
|
|
** @see function-closure.hpp
|
|
|
|
|
|
** @see control::CmdClosure real world usage example
|
|
|
|
|
|
**
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
2016-01-20 01:25:40 +01:00
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2016-01-17 23:55:41 +01:00
|
|
|
|
#include "lib/meta/tuple-helper.hpp"
|
2009-06-20 18:06:07 +02:00
|
|
|
|
#include "meta/typelist-diagnostics.hpp"
|
2009-06-20 23:39:45 +02:00
|
|
|
|
#include "meta/tuple-diagnostics.hpp"
|
2016-01-20 01:25:40 +01:00
|
|
|
|
#include "lib/format-cout.hpp"
|
2009-06-20 18:06:07 +02:00
|
|
|
|
|
2025-06-03 16:14:13 +02:00
|
|
|
|
#include <string>
|
2009-06-20 18:06:07 +02:00
|
|
|
|
|
2016-01-20 01:25:40 +01:00
|
|
|
|
using lib::test::showSizeof;
|
2025-06-03 16:14:13 +02:00
|
|
|
|
using util::toString;
|
|
|
|
|
|
using std::get;
|
2009-06-20 18:06:07 +02:00
|
|
|
|
|
2011-12-03 02:56:50 +01:00
|
|
|
|
namespace lib {
|
|
|
|
|
|
namespace meta {
|
2009-06-20 18:06:07 +02:00
|
|
|
|
namespace test {
|
2010-12-17 22:51:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace { // test data
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-06-03 16:14:13 +02:00
|
|
|
|
typedef TySeq< Num<1>
|
2010-12-17 22:51:27 +01:00
|
|
|
|
, Num<3>
|
|
|
|
|
|
, Num<5>
|
2016-12-23 04:23:03 +01:00
|
|
|
|
> Types1;
|
2025-06-03 16:14:13 +02:00
|
|
|
|
typedef TySeq< Num<2>
|
2010-12-17 22:51:27 +01:00
|
|
|
|
, Num<4>
|
2016-12-23 04:23:03 +01:00
|
|
|
|
> Types2;
|
2025-06-03 16:14:13 +02:00
|
|
|
|
typedef TySeq< Num<7>> Types3;
|
2010-12-17 22:51:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // (End) test data
|
2009-06-20 23:18:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/*********************************************************************//**
|
2016-01-17 23:55:41 +01:00
|
|
|
|
* @test Cover various aspects of the integration of our type sequences
|
|
|
|
|
|
* with the tuple type from the standard library
|
|
|
|
|
|
* - verify our generic tuple access decorator
|
2016-01-20 01:25:40 +01:00
|
|
|
|
* - verify generating tuple types from type list processing
|
|
|
|
|
|
* - TODO more helpers to come
|
2009-06-20 18:06:07 +02:00
|
|
|
|
*/
|
2016-01-17 23:55:41 +01:00
|
|
|
|
class TupleHelper_test : public Test
|
2009-06-20 18:06:07 +02:00
|
|
|
|
{
|
|
|
|
|
|
virtual void
|
2010-12-10 02:55:40 +01:00
|
|
|
|
run (Arg)
|
2009-06-20 18:06:07 +02:00
|
|
|
|
{
|
2009-06-20 23:18:02 +02:00
|
|
|
|
check_diagnostics();
|
2016-01-20 01:25:40 +01:00
|
|
|
|
check_tuple_from_Typelist();
|
2009-06-20 18:06:07 +02:00
|
|
|
|
}
|
2009-06-20 23:18:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** verify the test input data
|
2016-01-20 01:25:40 +01:00
|
|
|
|
* @see TypeListManip_test::check_diagnostics()
|
2009-06-20 23:18:02 +02:00
|
|
|
|
* for an explanation of the DISPLAY macro
|
|
|
|
|
|
*/
|
|
|
|
|
|
void
|
|
|
|
|
|
check_diagnostics ()
|
|
|
|
|
|
{
|
|
|
|
|
|
typedef Types1::List L1;
|
|
|
|
|
|
typedef Types2::List L2;
|
|
|
|
|
|
typedef Types3::List L3;
|
|
|
|
|
|
|
|
|
|
|
|
DISPLAY (L1);
|
|
|
|
|
|
DISPLAY (L2);
|
|
|
|
|
|
DISPLAY (L3);
|
|
|
|
|
|
|
2009-06-20 23:39:45 +02:00
|
|
|
|
typedef Tuple<Types1> Tup1;
|
2016-01-20 01:25:40 +01:00
|
|
|
|
Tup1 tup1x (Num<1>(11), Num<3>(), 55);
|
2009-06-20 23:18:02 +02:00
|
|
|
|
|
2009-06-20 23:39:45 +02:00
|
|
|
|
DISPLAY (Tup1); // prints the type
|
|
|
|
|
|
DUMPVAL (Tup1()); // prints the contents
|
|
|
|
|
|
DUMPVAL (tup1x);
|
2025-06-03 16:14:13 +02:00
|
|
|
|
|
|
|
|
|
|
EXPECT (Types1, "-<1>-<3>-<5>-");
|
|
|
|
|
|
EXPECT (Tup1, "TUPLE-<1>-<3>-<5>-");
|
|
|
|
|
|
CHECK (get<2>(tup1x) == Num<5>{55});
|
|
|
|
|
|
CHECK (toString(tup1x) == "«tuple<Num<1>, Num<3>, Num<5> >»──({11},(3),{55})"_expect);
|
2009-06-20 23:18:02 +02:00
|
|
|
|
}
|
2009-06-21 02:03:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
2016-01-20 01:25:40 +01:00
|
|
|
|
/** @test verify the ability to generate tuple types from typelist metaprogramming
|
|
|
|
|
|
* - the resulting types are plain flat `std::tuple` instantiations
|
|
|
|
|
|
* - memory layout is identical to a POD, as expected
|
|
|
|
|
|
* - our generic string conversion is extended to work with tuples
|
|
|
|
|
|
*/
|
2009-06-21 02:03:22 +02:00
|
|
|
|
void
|
|
|
|
|
|
check_tuple_from_Typelist()
|
|
|
|
|
|
{
|
2023-08-01 14:52:20 +02:00
|
|
|
|
using L1 = Types1::List; // ... start from existing Typelist...
|
2009-06-21 02:03:22 +02:00
|
|
|
|
|
2023-08-01 14:52:20 +02:00
|
|
|
|
using T_L1 = Tuple<L1>; // derive a tuple type from this typelist
|
|
|
|
|
|
using Seq1 = RebindTupleTypes<T_L1>::Seq;
|
2017-12-10 02:41:05 +01:00
|
|
|
|
// extract the underlying type sequence
|
2025-06-03 16:14:13 +02:00
|
|
|
|
EXPECT (T_L1, "TUPLE-<1>-<3>-<5>-");
|
|
|
|
|
|
EXPECT (Seq1, "-<1>-<3>-<5>-");
|
2009-06-21 02:03:22 +02:00
|
|
|
|
|
2016-01-20 01:25:40 +01:00
|
|
|
|
T_L1 tup1; // can be instantiated at runtime (and is just a std:tuple)
|
2025-06-03 16:14:13 +02:00
|
|
|
|
CHECK (toString(tup1) == "«tuple<Num<1>, Num<3>, Num<5> >»──((1),(3),(5))"_expect);
|
2009-06-21 02:03:22 +02:00
|
|
|
|
|
2016-01-20 01:25:40 +01:00
|
|
|
|
using Prepend = Tuple<Node<int, L1>>;
|
2025-06-03 16:14:13 +02:00
|
|
|
|
// another ListType based tuple created by prepending
|
|
|
|
|
|
EXPECT (Prepend, "TUPLE-<i>-<1>-<3>-<5>-");
|
2009-06-21 02:03:22 +02:00
|
|
|
|
|
2016-01-20 01:25:40 +01:00
|
|
|
|
Prepend prep (22, 11,33,Num<5>());
|
2025-06-03 16:14:13 +02:00
|
|
|
|
CHECK (toString(prep) == "«tuple<int, Num<1>, Num<3>, Num<5> >»──(22,{11},{33},(5))"_expect);
|
2009-06-22 06:05:32 +02:00
|
|
|
|
|
2025-06-03 16:14:13 +02:00
|
|
|
|
using NulT = Tuple<TySeq<> >; // plain-flat empty Tuple
|
2025-06-02 17:46:40 +02:00
|
|
|
|
using NulL = Tuple<Nil>; // list-style empty Tuple
|
2009-06-22 06:05:32 +02:00
|
|
|
|
|
2016-01-20 01:25:40 +01:00
|
|
|
|
NulT nulT; // and these, too, can be instantiated
|
|
|
|
|
|
NulL nulL;
|
2025-06-03 16:14:13 +02:00
|
|
|
|
CHECK (toString(nulT) == "«tuple<>»──()"_expect);
|
|
|
|
|
|
CHECK (toString(nulL) == "«tuple<>»──()"_expect);
|
|
|
|
|
|
CHECK ((is_same<NulT, NulL>()));
|
2009-06-21 19:52:33 +02:00
|
|
|
|
|
2016-01-20 01:25:40 +01:00
|
|
|
|
using S4 = struct{int a,b,c,d;}; // expect this to have the same memory layout
|
|
|
|
|
|
CHECK (sizeof(S4) == sizeof(prep));
|
|
|
|
|
|
CHECK (1 == sizeof(nulL)); // ...minimal storage, as expected
|
2009-06-21 19:52:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
2016-01-20 01:25:40 +01:00
|
|
|
|
CHECK (is_Tuple<T_L1>());
|
|
|
|
|
|
CHECK (is_Tuple<Prepend>());
|
|
|
|
|
|
CHECK (is_Tuple<NulT>());
|
2025-06-02 17:46:40 +02:00
|
|
|
|
CHECK (not is_Tuple<Seq1>());
|
2009-06-21 19:52:33 +02:00
|
|
|
|
|
2016-01-20 01:25:40 +01:00
|
|
|
|
cout << tup1 <<endl // these automatically use our generic string conversion
|
|
|
|
|
|
<< prep <<endl
|
|
|
|
|
|
<< nulL <<endl;
|
2009-06-21 19:52:33 +02:00
|
|
|
|
|
2016-01-20 01:25:40 +01:00
|
|
|
|
cout << showSizeof(tup1) <<endl
|
|
|
|
|
|
<< showSizeof(prep) <<endl
|
|
|
|
|
|
<< showSizeof(nulT) <<endl
|
|
|
|
|
|
<< showSizeof(nulL) <<endl;
|
2025-06-03 16:14:13 +02:00
|
|
|
|
|
|
|
|
|
|
CHECK (sizeof(prep) == sizeof(int)+sizeof(Num<1>)+sizeof(Num<3>)+sizeof(Num<5>));
|
2009-06-21 02:03:22 +02:00
|
|
|
|
}
|
2009-06-20 18:06:07 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
2016-01-17 23:55:41 +01:00
|
|
|
|
LAUNCHER (TupleHelper_test, "unit meta");
|
2009-06-20 18:06:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-03 02:56:50 +01:00
|
|
|
|
}}} // namespace lib::meta::test
|