Lumiera  0.pre.03
»edit your freedom«
typeseq-manip-test.cpp
Go to the documentation of this file.
1 /*
2  TypeSeqManip(Test) - simple manipulations on type sequences
3 
4  Copyright (C)
5  2008, 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 
31 #include "lib/test/run.hpp"
35 #include "lib/format-cout.hpp"
36 
37 using std::string;
38 
39 
40 namespace lib {
41 namespace meta {
42 namespace test {
43 
44 
45  namespace { // test data
46 
47  typedef Types< Num<1>
48  , Num<2>
49  , Num<3>
50  > Types1;
51  typedef Types< Num<7>
52  , Num<8>
53  , Num<9>
54  > Types2;
55 
56  // see also the CountDown template in typelist-diagnostics.hpp...
57 
58  } // (End) test data
59 
60 
61 
62 
63 
64 
65  /**********************************************************************/
72  class TypeSeqManipl_test : public Test
73  {
74  virtual void
75  run (Arg)
76  {
77  check_indexOf ();
78  check_buildSeq();
79  check_prepend ();
80  check_shift ();
81  check_split ();
82  }
83 
84 
85  void
86  check_indexOf()
87  {
88  CHECK ((0 == indexOfType<int, int, string, string>()));
89  CHECK ((1 == indexOfType<string, int, string, string>()));
90  CHECK ((2 == indexOfType<int, string, string, int>()));
91 // indexOfType<int>();
92 // indexOfType<int,long,long>(); // does not compile...
93  }
94 
95 
96  void
97  check_buildSeq ()
98  {
100  DISPLAY (LL);
101 
102  typedef Types<LL>::Seq Seq;
103  typedef Seq::List SeqList;
104  DISPLAY (Seq);
105  DISPLAY (SeqList);
106 
107  typedef Types<NodeNull>::Seq NulS;
108  DISPLAY (NulS);
109  }
110 
111 
112  void
113  check_prepend ()
114  {
115  typedef Prepend<Num<5>, Types1> Prepend1;
116  DISPLAY(Prepend1);
117 
118  typedef Prepend<NullType, Types1> Prepend2;
119  DISPLAY(Prepend2);
120 
121  typedef Prepend<Num<5>, Types<> > Prepend3;
122  DISPLAY(Prepend3);
123 
124  typedef Prepend<NullType, Types<> > Prepend4;
125  DISPLAY(Prepend4);
126  }
127 
128 
129  void
130  check_shift ()
131  {
133  typedef Types<LL>::Seq Seq;
134 
135  typedef Shifted<Seq,0>::Type Seq_0; DISPLAY (Seq_0);
136  typedef Shifted<Seq,1>::Type Seq_1; DISPLAY (Seq_1);
137  typedef Shifted<Seq,2>::Type Seq_2; DISPLAY (Seq_2);
138  typedef Shifted<Seq,3>::Type Seq_3; DISPLAY (Seq_3);
139  typedef Shifted<Seq,4>::Type Seq_4; DISPLAY (Seq_4);
140  typedef Shifted<Seq,5>::Type Seq_5; DISPLAY (Seq_5);
141  typedef Shifted<Seq,6>::Type Seq_6; DISPLAY (Seq_6);
142 
143  typedef Types<Shifted<Seq,0>::Head> Head_0; DISPLAY (Head_0);
144  typedef Types<Shifted<Seq,1>::Head> Head_1; DISPLAY (Head_1);
145  typedef Types<Shifted<Seq,2>::Head> Head_2; DISPLAY (Head_2);
146  typedef Types<Shifted<Seq,3>::Head> Head_3; DISPLAY (Head_3);
147  typedef Types<Shifted<Seq,4>::Head> Head_4; DISPLAY (Head_4);
148  typedef Types<Shifted<Seq,5>::Head> Head_5; DISPLAY (Head_5);
149  typedef Types<Shifted<Seq,6>::Head> Head_6; DISPLAY (Head_6);
150  }
151 
152 
153  void
154  check_split ()
155  {
157  typedef Types<LL>::Seq Seq;
158  DISPLAY (Seq);
159 
160  typedef Split<Seq>::List List; DISPLAY(List);
161  typedef Split<Seq>::First First; DISPLAY(First);
162  typedef Split<Seq>::Tail Tail; DISPLAY(Tail);
163  typedef Split<Seq>::Prefix Prefix; DISPLAY(Prefix);
164  typedef Split<Seq>::Last Last; DISPLAY(Last);
165 
166  typedef Split<Seq>::Head Head;
167  typedef Split<Seq>::End End;
168 
169  typedef Types<Head,End> HeadEnd; DISPLAY(HeadEnd);
170  }
171 
172 
173  };
174 
175 
177  LAUNCHER (TypeSeqManipl_test, "unit common");
178 
179 
180 
181 }}} // namespace lib::meta::test
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:40
Some basic facilities for manipulating type sequences.
Helper: prepend a type to an existing type sequence, thus shifting all elements within the sequence t...
Implementation namespace for support and library code.
Simplistic test class runner.
Helper: separate parts of a type sequence.
Support for writing metaprogramming unit-tests dealing with typelists and flags.
Metaprogramming: Helpers for manipulating lists-of-types.
constant-wrapper type for debugging purposes, usable for generating lists of distinguishable types ...