Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
20.meta.unary.cat.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#include <stddef.h>
39
40
42static void
43test_trait (int line,
44 const char* trait_name, const char* type_name,
45 size_t count, bool value)
46{
47 // verify that the expected trait is actually working
48
49 if (rw_assert (value != false, 0, line,
50 "%s<%s>::value was %b, expected true",
51 trait_name, type_name, value))
52 {
53
54 // [meta.unary.cat p3] for any given type T, exactly one of the
55 // primary type categories has a value member that evaluates to
56 // true
57
58 rw_assert (count == 1, 0, line,
59 "%s evaluated true for %zu traits, expected 1",
61 }
62}
63
64#define _TEST(Trait,Type) \
65 test_trait(__LINE__, #Trait, #Type, \
66 std::is_void<Type>::value \
67 + std::is_integral<Type>::value \
68 + std::is_floating_point<Type>::value \
69 + std::is_array<Type>::value \
70 + std::is_pointer<Type>::value \
71 + std::is_lvalue_reference<Type>::value \
72 + std::is_rvalue_reference<Type>::value \
73 + std::is_member_object_pointer<Type>::value \
74 + std::is_member_function_pointer<Type>::value \
75 + std::is_enum<Type>::value \
76 + std::is_union<Type>::value \
77 + std::is_class<Type>::value \
78 + std::is_function<Type>::value, \
79 Trait<Type>::value)
80
81#if 0
82
83#define TEST(Trait,Type) \
84 _TEST(Trait, Type); \
85 _TEST(Trait, std::add_const<Type>::type); \
86 _TEST(Trait, std::add_volatile<Type>::type); \
87 _TEST(Trait, std::add_cv<Type>::type)
88
89#else
90
91#define TEST(Trait,Type) \
92 _TEST(Trait, Type)
93
94#endif
95
96
98class class_t {
99 int i_; float f_;
100};
101
102struct struct_t {
103 int i_; float f_;
104};
105
106union union_t {
107 int i_; float f_;
108};
109
110enum enum_t {
113
114
116static void test_is_void ()
117{
118 TEST(std::is_void, void);
119}
120
121static void test_is_integral ()
122{
123 TEST(std::is_integral, bool);
124 TEST(std::is_integral, char);
125
126#ifndef _RWSTD_NO_WCHAR_T
127 TEST(std::is_integral, wchar_t);
128#endif // _RWSTD_NO_WCHAR_T
129
130 TEST(std::is_integral, signed char);
131 TEST(std::is_integral, unsigned char);
132
133 TEST(std::is_integral, signed short);
134 TEST(std::is_integral, unsigned short);
135
136 TEST(std::is_integral, signed int);
137 TEST(std::is_integral, unsigned int);
138
139 TEST(std::is_integral, signed long);
140 TEST(std::is_integral, unsigned long);
141
142#ifndef _RWSTD_NO_LONG_LONG
143 TEST(std::is_integral, signed long long);
144 TEST(std::is_integral, unsigned long long);
145#endif // _RWSTD_NO_LONG_LONG
146}
147
148static void test_is_floating_point ()
149{
150 TEST(std::is_floating_point, float);
151 TEST(std::is_floating_point, double);
152 TEST(std::is_floating_point, long double);
153}
154
155static void test_is_array ()
156{
157 TEST(std::is_array, char []);
158 TEST(std::is_array, char [10]);
159 TEST(std::is_array, char [][10]);
160 TEST(std::is_array, char [10][10]);
161}
162
163static void test_is_pointer ()
164{
165 TEST(std::is_pointer, char* const);
166 TEST(std::is_pointer, char const*);
167 TEST(std::is_pointer, const char*);
168
169 TEST(std::is_pointer, char*);
170 TEST(std::is_pointer, char (*)[]);
171 TEST(std::is_pointer, char (*)());
172}
173
174static void test_is_lvalue_reference ()
175{
176 TEST(std::is_lvalue_reference, char&); // reference
177
178 TEST(std::is_lvalue_reference, void (&)()); // function reference
179 TEST(std::is_lvalue_reference, void (&)(int)); // function reference
180
181#ifdef _ILL_FORMED
182 TEST(std::is_lvalue_reference, long (&)[]); // array reference
183 TEST(std::is_lvalue_reference, long (&)[][10]); // array reference
184#endif
185
186 TEST(std::is_lvalue_reference, long (&)[10]); // array reference
187 TEST(std::is_lvalue_reference, long (&)[10][10]); // array reference
188}
189
190static void test_is_rvalue_reference ()
191{
192#ifndef _RWSTD_NO_RVALUE_REFERENCES
193 TEST(std::is_rvalue_reference, char&&);
194#else
195 rw_warn (0, 0, __LINE__,
196 "test_is_rvalue_reference() disabled because "
197 "_RWSTD_NO_RVALUE_REFERENCES is defined");
198#endif // _RWSTD_NO_RVALUE_REFERENCES
199}
200
201static void test_is_member_object_pointer ()
202{
203 TEST (std::is_member_object_pointer, long (class_t::*));
204 TEST (std::is_member_object_pointer, long (struct_t::*));
205 TEST (std::is_member_object_pointer, long (union_t::*));
206}
207
208static void test_is_member_function_pointer ()
209{
210 // arity 0
211 TEST (std::is_member_function_pointer, long (class_t:: *)());
212 TEST (std::is_member_function_pointer, long (struct_t::*)());
213 TEST (std::is_member_function_pointer, long (union_t:: *)());
214
215 // arity 1
216 TEST (std::is_member_function_pointer, long (class_t:: *)(int));
217 TEST (std::is_member_function_pointer, long (struct_t::*)(int));
218 TEST (std::is_member_function_pointer, long (union_t:: *)(int));
219
220 // arity 2
221 TEST (std::is_member_function_pointer,
222 long (class_t:: *)(int, char));
223 TEST (std::is_member_function_pointer,
224 long (struct_t::*)(int, char));
225 TEST (std::is_member_function_pointer,
226 long (union_t:: *)(int, char));
227
228 // arity 12
229 TEST (std::is_member_function_pointer,
230 long (class_t:: *)(char, short, int, long, float, double,
231 char, short, int, long, float, double));
232 TEST (std::is_member_function_pointer,
233 long (struct_t::*)(char, short, int, long, float, double,
234 char, short, int, long, float, double));
235 TEST (std::is_member_function_pointer,
236 long (union_t:: *)(char, short, int, long, float, double,
237 char, short, int, long, float, double));
238}
239
240static void test_is_enum ()
241{
242 TEST (std::is_enum, enum_t);
243}
244
245static void test_is_union ()
246{
247#if !defined (_RWSTD_TT_IS_CLASS) && !defined (_RWSTD_TT_IS_UNION)
248
249 rw_warn (0, 0, __LINE__,
250 "test_is_union() disabled because neither of "
251 "_RWSTD_TT_IS_CLASS or _RWSTD_TT_IS_UNION is "
252 "defined");
253
254#else
255 TEST (std::is_union, union_t);
256#endif
257}
258
259static void test_is_class ()
260{
261 TEST (std::is_class, class_t);
262 TEST (std::is_class, struct_t);
263}
264
265static void test_is_function ()
266{
267 TEST (std::is_function, void ());
268 TEST (std::is_function, long (int));
269 TEST (std::is_function, long (int, char));
270 TEST (std::is_function, long (int, char));
271}
272
273
274
276static int run_test (int, char*[])
277{
278 test_is_void ();
279 test_is_integral ();
280 test_is_floating_point ();
281 test_is_array ();
282 test_is_pointer ();
283 test_is_lvalue_reference ();
284 test_is_rvalue_reference ();
285 test_is_member_object_pointer ();
286 test_is_member_function_pointer ();
287 test_is_enum ();
288 test_is_union ();
289 test_is_class ();
290 test_is_function ();
291
292 return 0;
293}
294
295
297#else // _RWSTD_NO_EXT_CXX_0X
298
299
301static int run_test (int, char*[])
302{
303 rw_warn (0, 0, __LINE__,
304 "test disabled because _RWSTD_NO_EXT_CXX_0X is defined");
305 return 0;
306}
307
308#endif // !_RWSTD_NO_EXT_CXX_0X
309
310
312int main (int argc, char *argv[])
313{
314 return rw_test (argc, argv, __FILE__,
315 "meta.unary.cat",
316 0 /* no comment */,
317 run_test,
318 0);
319}
320
void count(T, T, const U &,...)
#define line
Definition 17.names.cpp:490
enum_t
void test_trait(int line, bool value, bool expect, const char *trait, const char *typeT, const char *typeU)
#define TEST(Trait, Type)
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
T value(const T &val)
const char * type_name()
#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