Lumiera  0.pre.03
»edit your freedom«
tuple-helper-test.cpp
Go to the documentation of this file.
1 /*
2  TupleHelper(Test) - verify helpers for working with tuples and type sequences
3 
4  Copyright (C) Lumiera.org
5  2009, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
34 #include "lib/test/run.hpp"
35 #include "lib/test/test-helper.hpp"
39 #include "lib/format-cout.hpp"
40 
41 
42 using ::test::Test;
43 using lib::test::showSizeof;
44 
45 
46 namespace lib {
47 namespace meta {
48 namespace test {
49 
50 
51 
52  namespace { // test data
53 
54 
55  typedef Types< Num<1>
56  , Num<3>
57  , Num<5>
58  > Types1;
59  typedef Types< Num<2>
60  , Num<4>
61  > Types2;
62  typedef Types< Num<7>> Types3;
63 
64 
65 
66  } // (End) test data
67 
68 
69 
70 
71  /*********************************************************************/
78  class TupleHelper_test : public Test
79  {
80  virtual void
81  run (Arg)
82  {
85  }
86 
87 
92  void
94  {
95  typedef Types1::List L1;
96  typedef Types2::List L2;
97  typedef Types3::List L3;
98 
99  DISPLAY (L1);
100  DISPLAY (L2);
101  DISPLAY (L3);
102 
103  typedef Tuple<Types1> Tup1;
104  Tup1 tup1x (Num<1>(11), Num<3>(), 55);
105 
106  DISPLAY (Tup1); // prints the type
107  DUMPVAL (Tup1()); // prints the contents
108  DUMPVAL (tup1x);
109  }
110 
111 
117  void
119  {
120  using L1 = Types1::List; // ... start from existing Typelist...
121 
122  using T_L1 = Tuple<L1>; // derive a tuple type from this typelist
123  using Seq1 = RebindTupleTypes<T_L1>::Seq;
124  // extract the underlying type sequence
125  DISPLAY (T_L1);
126  DISPLAY (Seq1);
127 
128  T_L1 tup1; // can be instantiated at runtime (and is just a std:tuple)
129  DUMPVAL (tup1);
130 
131  using Prepend = Tuple<Node<int, L1>>;
132  DISPLAY (Prepend); // another ListType based tuple created by prepending
133 
134  Prepend prep (22, 11,33,Num<5>());
135  DUMPVAL (prep);
136 
137  typedef Tuple<Types<> > NulT; // plain-flat empty Tuple
138  typedef Tuple<NullType> NulL; // list-style empty Tuple
139 
140  NulT nulT; // and these, too, can be instantiated
141  NulL nulL;
142 
143  using S4 = struct{int a,b,c,d;}; // expect this to have the same memory layout
144  CHECK (sizeof(S4) == sizeof(prep));
145  CHECK (1 == sizeof(nulL)); // ...minimal storage, as expected
146 
147 
148  CHECK (is_Tuple<T_L1>());
149  CHECK (is_Tuple<Prepend>());
150  CHECK (is_Tuple<NulT>());
151  CHECK (!is_Tuple<Seq1>());
152 
153  cout << tup1 <<endl // these automatically use our generic string conversion
154  << prep <<endl
155  << nulL <<endl;
156 
157  cout << showSizeof(tup1) <<endl
158  << showSizeof(prep) <<endl
159  << showSizeof(nulT) <<endl
160  << showSizeof(nulL) <<endl;
161  }
162  };
163 
164 
166  LAUNCHER (TupleHelper_test, "unit meta");
167 
168 
169 
170 }}} // namespace lib::meta::test
Automatically use custom string conversion in C++ stream output.
trait to detect tuple types
typename BuildTupleType< TYPES >::Type Tuple
Build a std::tuple from types given as type sequence.
Definition: run.hpp:49
Helper: prepend a type to an existing type sequence, thus shifting all elements within the sequence t...
Implementation namespace for support and library code.
Metaprogramming with tuples-of-types and the std::tuple record.
void check_diagnostics()
verify the test input data
Simple test class runner.
A collection of frequently used helper functions to support unit testing.
an extension to typelist-diagnostics.hpp, allowing to dump the contents of a Tuple datatype...
Support for writing metaprogramming unit-tests dealing with typelists and flags.
constant-wrapper type for debugging purposes, usable for generating lists of distinguishable types ...