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)
5  2009, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
14 
25 #include "lib/test/run.hpp"
26 #include "lib/test/test-helper.hpp"
30 #include "lib/format-cout.hpp"
31 
32 
33 using ::test::Test;
34 using lib::test::showSizeof;
35 
36 
37 namespace lib {
38 namespace meta {
39 namespace test {
40 
41 
42 
43  namespace { // test data
44 
45 
46  typedef Types< Num<1>
47  , Num<3>
48  , Num<5>
49  > Types1;
50  typedef Types< Num<2>
51  , Num<4>
52  > Types2;
53  typedef Types< Num<7>> Types3;
54 
55 
56 
57  } // (End) test data
58 
59 
60 
61 
62  /*********************************************************************/
69  class TupleHelper_test : public Test
70  {
71  virtual void
72  run (Arg)
73  {
76  }
77 
78 
83  void
85  {
86  typedef Types1::List L1;
87  typedef Types2::List L2;
88  typedef Types3::List L3;
89 
90  DISPLAY (L1);
91  DISPLAY (L2);
92  DISPLAY (L3);
93 
94  typedef Tuple<Types1> Tup1;
95  Tup1 tup1x (Num<1>(11), Num<3>(), 55);
96 
97  DISPLAY (Tup1); // prints the type
98  DUMPVAL (Tup1()); // prints the contents
99  DUMPVAL (tup1x);
100  }
101 
102 
108  void
110  {
111  using L1 = Types1::List; // ... start from existing Typelist...
112 
113  using T_L1 = Tuple<L1>; // derive a tuple type from this typelist
114  using Seq1 = RebindTupleTypes<T_L1>::Seq;
115  // extract the underlying type sequence
116  DISPLAY (T_L1);
117  DISPLAY (Seq1);
118 
119  T_L1 tup1; // can be instantiated at runtime (and is just a std:tuple)
120  DUMPVAL (tup1);
121 
122  using Prepend = Tuple<Node<int, L1>>;
123  DISPLAY (Prepend); // another ListType based tuple created by prepending
124 
125  Prepend prep (22, 11,33,Num<5>());
126  DUMPVAL (prep);
127 
128  typedef Tuple<Types<> > NulT; // plain-flat empty Tuple
129  typedef Tuple<NullType> NulL; // list-style empty Tuple
130 
131  NulT nulT; // and these, too, can be instantiated
132  NulL nulL;
133 
134  using S4 = struct{int a,b,c,d;}; // expect this to have the same memory layout
135  CHECK (sizeof(S4) == sizeof(prep));
136  CHECK (1 == sizeof(nulL)); // ...minimal storage, as expected
137 
138 
139  CHECK (is_Tuple<T_L1>());
140  CHECK (is_Tuple<Prepend>());
141  CHECK (is_Tuple<NulT>());
142  CHECK (!is_Tuple<Seq1>());
143 
144  cout << tup1 <<endl // these automatically use our generic string conversion
145  << prep <<endl
146  << nulL <<endl;
147 
148  cout << showSizeof(tup1) <<endl
149  << showSizeof(prep) <<endl
150  << showSizeof(nulT) <<endl
151  << showSizeof(nulL) <<endl;
152  }
153  };
154 
155 
157  LAUNCHER (TupleHelper_test, "unit meta");
158 
159 
160 
161 }}} // 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:40
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
Simplistic 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 ...