Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
20.meta.trans.cv.cpp
Go to the documentation of this file.
1// -*- C++ -*-
2
30#include <rw_driver.h>
31#include <rw/_defs.h>
32
33// compile out all test code if extensions disabled
34#ifndef _RWSTD_NO_EXT_CXX_0X
35
36#include <type_traits>
37
38
40template <class T, class U>
41struct test_is_same
42{
43 enum { value = 0 };
44};
45
46template <class T>
47struct test_is_same<T,T>
48{
49 enum { value = 1 };
50};
51
52
54void test_trait (int line, bool same,
55 const char* trait,
56 const char* typeT,
57 const char* typeU)
58{
59 rw_assert (same, 0, line,
60 "%s<%s>::type is %{?}exactly%{:}not%{;} %s",
61 trait, typeT, same, typeU);
62}
63
64#define TEST(Trait,TypeT,TypeU) \
65 test_trait(__LINE__, \
66 std::is_same<Trait<TypeT>::type, TypeU>::value, \
67 #Trait, #TypeT, #TypeU)
68
69
71#define C const
72#define V volatile
73#define CV const volatile
74
75
77static void test_remove_const ()
78{
79 TEST (std::remove_const, int, int);
80 TEST (std::remove_const, C int, int);
81 TEST (std::remove_const, V int, V int);
82 TEST (std::remove_const, CV int, V int);
83
84 TEST (std::remove_const, int*, int*);
85 TEST (std::remove_const, C int*, C int*);
86 TEST (std::remove_const, V int*, V int*);
87 TEST (std::remove_const, CV int*, CV int*);
88
89 TEST (std::remove_const, int* C , int* );
90 TEST (std::remove_const, int* V, int* V);
91 TEST (std::remove_const, int* CV, int* V);
92
93 TEST (std::remove_const, C int* C , C int* );
94 TEST (std::remove_const, C int* V, C int* V);
95 TEST (std::remove_const, C int* CV, C int* V);
96
97 TEST (std::remove_const, V int* C , V int* );
98 TEST (std::remove_const, V int* V, V int* V);
99 TEST (std::remove_const, V int* CV, V int* V);
100
101 TEST (std::remove_const, CV int* C , CV int* );
102 TEST (std::remove_const, CV int* V, CV int* V);
103 TEST (std::remove_const, CV int* CV, CV int* V);
104}
105
106static void test_remove_volatile ()
107{
108 TEST (std::remove_volatile, int, int);
109 TEST (std::remove_volatile, C int, C int);
110 TEST (std::remove_volatile, V int, int);
111 TEST (std::remove_volatile, CV int, C int);
112
113 TEST (std::remove_volatile, int*, int*);
114 TEST (std::remove_volatile, C int*, C int*);
115 TEST (std::remove_volatile, V int*, V int*);
116 TEST (std::remove_volatile, CV int*, CV int*);
117
118 TEST (std::remove_volatile, int* C , int* C);
119 TEST (std::remove_volatile, int* V, int* );
120 TEST (std::remove_volatile, int* CV, int* C);
121
122 TEST (std::remove_volatile, C int* C , C int* C);
123 TEST (std::remove_volatile, C int* V, C int* );
124 TEST (std::remove_volatile, C int* CV, C int* C);
125
126 TEST (std::remove_volatile, V int* C , V int* C);
127 TEST (std::remove_volatile, V int* V, V int* );
128 TEST (std::remove_volatile, V int* CV, V int* C);
129
130 TEST (std::remove_volatile, CV int* C , CV int* C);
131 TEST (std::remove_volatile, CV int* V, CV int* );
132 TEST (std::remove_volatile, CV int* CV, CV int* C);
133}
134
135static void test_remove_cv ()
136{
137 TEST (std::remove_cv, int, int);
138 TEST (std::remove_cv, C int, int);
139 TEST (std::remove_cv, V int, int);
140 TEST (std::remove_cv, CV int, int);
141
142 TEST (std::remove_cv, int*, int*);
143 TEST (std::remove_cv, C int*, C int*);
144 TEST (std::remove_cv, V int*, V int*);
145 TEST (std::remove_cv, CV int*, CV int*);
146
147 TEST (std::remove_cv, int* C , int*);
148 TEST (std::remove_cv, int* V, int*);
149 TEST (std::remove_cv, int* CV, int*);
150
151 TEST (std::remove_cv, C int* C , C int*);
152 TEST (std::remove_cv, C int* V, C int*);
153 TEST (std::remove_cv, C int* CV, C int*);
154
155 TEST (std::remove_cv, V int* C , V int*);
156 TEST (std::remove_cv, V int* V, V int*);
157 TEST (std::remove_cv, V int* CV, V int*);
158
159 TEST (std::remove_cv, CV int* C , CV int*);
160 TEST (std::remove_cv, CV int* V, CV int*);
161 TEST (std::remove_cv, CV int* CV, CV int*);
162}
163
164
166static void test_add_const ()
167{
168 TEST (std::add_const, int, C int);
169 TEST (std::add_const, C int, C int);
170 TEST (std::add_const, V int, CV int);
171 TEST (std::add_const, CV int, CV int);
172
173 TEST (std::add_const, int*, int* C);
174 TEST (std::add_const, C int*, C int* C);
175 TEST (std::add_const, V int*, V int* C);
176 TEST (std::add_const, CV int*, CV int* C);
177
178 TEST (std::add_const, int* C , int* C);
179 TEST (std::add_const, int* V, int* CV);
180 TEST (std::add_const, int* CV, int* CV);
181
182 TEST (std::add_const, C int* C , C int* C );
183 TEST (std::add_const, C int* V, C int* CV);
184 TEST (std::add_const, C int* CV, C int* CV);
185
186 TEST (std::add_const, V int* C , V int* C );
187 TEST (std::add_const, V int* V, V int* CV);
188 TEST (std::add_const, V int* CV, V int* CV);
189
190 TEST (std::add_const, CV int* C , CV int* C );
191 TEST (std::add_const, CV int* V, CV int* CV);
192 TEST (std::add_const, CV int* CV, CV int* CV);
193
194 TEST (std::add_const, void (*)(), void (*C)());
195
196 // if T is a reference, then type shall be the same as T
197 TEST (std::add_const, int&, int&);
198 TEST (std::add_const, C int&, C int&);
199 TEST (std::add_const, V int&, V int&);
200 TEST (std::add_const, CV int&, CV int&);
201
202 TEST (std::add_const, void (&)(), void (&)());
203
204 // if T is a function, then type shall be the same as T
205 TEST (std::add_const, void (), void ());
206}
207
208static void test_add_volatile ()
209{
210 TEST (std::add_volatile, int, V int);
211 TEST (std::add_volatile, C int, CV int);
212 TEST (std::add_volatile, V int, V int);
213 TEST (std::add_volatile, CV int, CV int);
214
215 TEST (std::add_volatile, int*, int* V);
216 TEST (std::add_volatile, C int*, C int* V);
217 TEST (std::add_volatile, V int*, V int* V);
218 TEST (std::add_volatile, CV int*, CV int* V);
219
220 TEST (std::add_volatile, int* C , int* CV);
221 TEST (std::add_volatile, int* V, int* V);
222 TEST (std::add_volatile, int* CV, int* CV);
223
224 TEST (std::add_volatile, C int* C , C int* CV);
225 TEST (std::add_volatile, C int* V, C int* V);
226 TEST (std::add_volatile, C int* CV, C int* CV);
227
228 TEST (std::add_volatile, V int* C , V int* CV);
229 TEST (std::add_volatile, V int* V, V int* V);
230 TEST (std::add_volatile, V int* CV, V int* CV);
231
232 TEST (std::add_volatile, CV int* C , CV int* CV);
233 TEST (std::add_volatile, CV int* V, CV int* V);
234 TEST (std::add_volatile, CV int* CV, CV int* CV);
235
236 TEST (std::add_volatile, void (*)(), void (*V)());
237
238 // if T is a reference, then type shall be the same as T
239 TEST (std::add_volatile, int&, int&);
240 TEST (std::add_volatile, C int&, C int&);
241 TEST (std::add_volatile, V int&, V int&);
242 TEST (std::add_volatile, CV int&, CV int&);
243
244 TEST (std::add_volatile, void (&)(), void (&)());
245
246 // if T is a function, then type shall be the same as T
247 TEST (std::add_volatile, void (), void ());
248}
249
250static void test_add_cv ()
251{
252 TEST (std::add_cv, int, CV int);
253 TEST (std::add_cv, C int, CV int);
254 TEST (std::add_cv, V int, CV int);
255 TEST (std::add_cv, CV int, CV int);
256
257 TEST (std::add_cv, int*, int* CV);
258 TEST (std::add_cv, C int*, C int* CV);
259 TEST (std::add_cv, V int*, V int* CV);
260 TEST (std::add_cv, CV int*, CV int* CV);
261
262 TEST (std::add_cv, int* C , int* CV);
263 TEST (std::add_cv, int* V, int* CV);
264 TEST (std::add_cv, int* CV, int* CV);
265
266 TEST (std::add_cv, C int* C , C int* CV);
267 TEST (std::add_cv, C int* V, C int* CV);
268 TEST (std::add_cv, C int* CV, C int* CV);
269
270 TEST (std::add_cv, V int* C , V int* CV);
271 TEST (std::add_cv, V int* V, V int* CV);
272 TEST (std::add_cv, V int* CV, V int* CV);
273
274 TEST (std::add_cv, CV int* C , CV int* CV);
275 TEST (std::add_cv, CV int* V, CV int* CV);
276 TEST (std::add_cv, CV int* CV, CV int* CV);
277
278 TEST (std::add_cv, void (*)(), void (*CV)());
279
280 // if T is a reference, then type shall be the same as T
281 TEST (std::add_cv, int&, int&);
282 TEST (std::add_cv, C int&, C int&);
283 TEST (std::add_cv, V int&, V int&);
284 TEST (std::add_cv, CV int&, CV int&);
285
286 TEST (std::add_cv, void (&)(), void (&)());
287
288 // if T is a function, then type shall be the same as T
289 TEST (std::add_cv, void (), void ());
290}
291
292
294static int run_test (int, char*[])
295{
296 test_remove_const();
297 test_remove_volatile();
298 test_remove_cv();
299
300 test_add_const();
301 test_add_volatile();
302 test_add_cv();
303
304 return 0;
305}
306
307
309#else // _RWSTD_NO_EXT_CXX_0X
310
311
313static int run_test (int, char*[])
314{
315 rw_warn (0, 0, __LINE__,
316 "test disabled because _RWSTD_NO_EXT_CXX_0X is defined");
317 return 0;
318}
319
320#endif // !_RWSTD_NO_EXT_CXX_0X
321
322
324int main (int argc, char *argv[])
325{
326 return rw_test (argc, argv, __FILE__,
327 "meta.trans.cv",
328 0 /* no comment */,
329 run_test,
330 0);
331}
#define T
Definition 17.names.cpp:163
#define line
Definition 17.names.cpp:490
void test_trait(int line, bool same, const char *trait, const char *typeT, const char *typeU)
#define CV
#define TEST(Trait, TypeT, TypeU)
#define V
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define main
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630
_TEST_EXPORT int rw_warn(int, const char *, int, const char *,...)
Definition driver.cpp:1647