1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <experimental/type_traits>
11
12 #include <experimental/type_traits>
13
14 #if _LIBCPP_STD_VER > 11
15
16 namespace ex = std::experimental;
17
non_literal_typenon_literal_type18 struct non_literal_type { non_literal_type() {} };
19 struct empty_type {};
20
21 struct polymorphic_type
22 {
foopolymorphic_type23 virtual void foo() {}
24 };
25
26 struct abstract_type
27 {
28 virtual void foo() = 0;
29 };
30
31 struct final_type final {};
32
33 struct virtual_dtor_type
34 {
~virtual_dtor_typevirtual_dtor_type35 virtual ~virtual_dtor_type() {}
36 };
37
type_properties_test()38 void type_properties_test()
39 {
40 {
41 typedef const int T;
42 static_assert(ex::is_const_v<T>, "");
43 static_assert(std::is_same<decltype(ex::is_const_v<T>), const bool>::value, "");
44 static_assert(ex::is_const_v<T> == std::is_const<T>::value, "");
45 }
46 {
47 typedef int T;
48 static_assert(!ex::is_const_v<T>, "");
49 static_assert(ex::is_const_v<T> == std::is_const<T>::value, "");
50 }
51 {
52 typedef volatile int T;
53 static_assert(ex::is_volatile_v<T>, "");
54 static_assert(std::is_same<decltype(ex::is_volatile_v<T>), const bool>::value, "");
55 static_assert(ex::is_volatile_v<T> == std::is_volatile<T>::value, "");
56 }
57 {
58 typedef int T;
59 static_assert(!ex::is_volatile_v<T>, "");
60 static_assert(ex::is_volatile_v<T> == std::is_volatile<T>::value, "");
61 }
62 {
63 typedef int T;
64 static_assert(ex::is_trivial_v<T>, "");
65 static_assert(std::is_same<decltype(ex::is_trivial_v<T>), const bool>::value, "");
66 static_assert(ex::is_trivial_v<T> == std::is_trivial<T>::value, "");
67 }
68 {
69 typedef int & T;
70 static_assert(!ex::is_trivial_v<T>, "");
71 static_assert(ex::is_trivial_v<T> == std::is_trivial<T>::value, "");
72 }
73 {
74 typedef int T;
75 static_assert(ex::is_trivially_copyable_v<T>, "");
76 static_assert(std::is_same<decltype(ex::is_trivially_copyable_v<T>), const bool>::value, "");
77 static_assert(ex::is_trivially_copyable_v<T> == std::is_trivially_copyable<T>::value, "");
78 }
79 {
80 typedef int & T;
81 static_assert(!ex::is_trivially_copyable_v<T>, "");
82 static_assert(ex::is_trivially_copyable_v<T> == std::is_trivially_copyable<T>::value, "");
83 }
84 {
85 typedef int T;
86 static_assert(ex::is_standard_layout_v<T>, "");
87 static_assert(std::is_same<decltype(ex::is_standard_layout_v<T>), const bool>::value, "");
88 static_assert(ex::is_standard_layout_v<T> == std::is_standard_layout<T>::value, "");
89 }
90 {
91 typedef int & T;
92 static_assert(!ex::is_standard_layout_v<T>, "");
93 static_assert(ex::is_standard_layout_v<T> == std::is_standard_layout<T>::value, "");
94 }
95 {
96 typedef int T;
97 static_assert(ex::is_pod_v<T>, "");
98 static_assert(std::is_same<decltype(ex::is_pod_v<T>), const bool>::value, "");
99 static_assert(ex::is_pod_v<T> == std::is_pod<T>::value, "");
100 }
101 {
102 typedef int & T;
103 static_assert(!ex::is_pod_v<T>, "");
104 static_assert(ex::is_pod_v<T> == std::is_pod<T>::value, "");
105 }
106 {
107 typedef int T;
108 static_assert(ex::is_literal_type_v<T>, "");
109 static_assert(std::is_same<decltype(ex::is_literal_type_v<T>), const bool>::value, "");
110 static_assert(ex::is_literal_type_v<T> == std::is_literal_type<T>::value, "");
111 }
112 {
113 typedef non_literal_type T;
114 static_assert(!ex::is_literal_type_v<T>, "");
115 static_assert(ex::is_literal_type_v<T> == std::is_literal_type<T>::value, "");
116 }
117 {
118 typedef empty_type T;
119 static_assert(ex::is_empty_v<T>, "");
120 static_assert(std::is_same<decltype(ex::is_empty_v<T>), const bool>::value, "");
121 static_assert(ex::is_empty_v<T> == std::is_empty<T>::value, "");
122 }
123 {
124 typedef int T;
125 static_assert(!ex::is_empty_v<T>, "");
126 static_assert(ex::is_empty_v<T> == std::is_empty<T>::value, "");
127 }
128 {
129 typedef polymorphic_type T;
130 static_assert(ex::is_polymorphic_v<T>, "");
131 static_assert(std::is_same<decltype(ex::is_polymorphic_v<T>), const bool>::value, "");
132 static_assert(ex::is_polymorphic_v<T> == std::is_polymorphic<T>::value, "");
133 }
134 {
135 typedef int T;
136 static_assert(!ex::is_polymorphic_v<T>, "");
137 static_assert(ex::is_polymorphic_v<T> == std::is_polymorphic<T>::value, "");
138 }
139 {
140 typedef abstract_type T;
141 static_assert(ex::is_abstract_v<T>, "");
142 static_assert(std::is_same<decltype(ex::is_abstract_v<T>), const bool>::value, "");
143 static_assert(ex::is_abstract_v<T> == std::is_abstract<T>::value, "");
144 }
145 {
146 typedef int T;
147 static_assert(!ex::is_abstract_v<T>, "");
148 static_assert(ex::is_abstract_v<T> == std::is_abstract<T>::value, "");
149 }
150 {
151 typedef final_type T;
152 static_assert(ex::is_final_v<T>, "");
153 static_assert(std::is_same<decltype(ex::is_final_v<T>), const bool>::value, "");
154 static_assert(ex::is_final_v<T> == std::is_final<T>::value, "");
155 }
156 {
157 typedef int T;
158 static_assert(!ex::is_final_v<T>, "");
159 static_assert(ex::is_final_v<T> == std::is_final<T>::value, "");
160 }
161 {
162 typedef int T;
163 static_assert(ex::is_signed_v<T>, "");
164 static_assert(std::is_same<decltype(ex::is_signed_v<T>), const bool>::value, "");
165 static_assert(ex::is_signed_v<T> == std::is_signed<T>::value, "");
166 }
167 {
168 typedef unsigned T;
169 static_assert(!ex::is_signed_v<T>, "");
170 static_assert(ex::is_signed_v<T> == std::is_signed<T>::value, "");
171 }
172 {
173 typedef unsigned T;
174 static_assert(ex::is_unsigned_v<T>, "");
175 static_assert(std::is_same<decltype(ex::is_unsigned_v<T>), const bool>::value, "");
176 static_assert(ex::is_unsigned_v<T> == std::is_unsigned<T>::value, "");
177 }
178 {
179 typedef int T;
180 static_assert(!ex::is_unsigned_v<T>, "");
181 static_assert(ex::is_unsigned_v<T> == std::is_unsigned<T>::value, "");
182 }
183 }
184
is_constructible_and_assignable_test()185 void is_constructible_and_assignable_test()
186 {
187 {
188 typedef int T;
189 static_assert(ex::is_constructible_v<T, int>, "");
190 static_assert(std::is_same<decltype(ex::is_constructible_v<T, int>), const bool>::value, "");
191 static_assert(ex::is_constructible_v<T, int> == std::is_constructible<T, int>::value, "");
192 }
193 {
194 typedef void T;
195 static_assert(!ex::is_constructible_v<T, int>, "");
196 static_assert(ex::is_constructible_v<T, int> == std::is_constructible<T, int>::value, "");
197 }
198 {
199 typedef int T;
200 static_assert(ex::is_default_constructible_v<T>, "");
201 static_assert(std::is_same<decltype(ex::is_default_constructible_v<T>), const bool>::value, "");
202 static_assert(ex::is_default_constructible_v<T> == std::is_default_constructible<T>::value, "");
203 }
204 {
205 typedef int & T;
206 static_assert(!ex::is_default_constructible_v<T>, "");
207 static_assert(ex::is_default_constructible_v<T> == std::is_default_constructible<T>::value, "");
208 }
209 {
210 typedef int T;
211 static_assert(ex::is_copy_constructible_v<T>, "");
212 static_assert(std::is_same<decltype(ex::is_copy_constructible_v<T>), const bool>::value, "");
213 static_assert(ex::is_copy_constructible_v<T> == std::is_copy_constructible<T>::value, "");
214 }
215 {
216 typedef void T;
217 static_assert(!ex::is_copy_constructible_v<T>, "");
218 static_assert(ex::is_copy_constructible_v<T> == std::is_copy_constructible<T>::value, "");
219 }
220 {
221 typedef int T;
222 static_assert(ex::is_move_constructible_v<T>, "");
223 static_assert(std::is_same<decltype(ex::is_move_constructible_v<T>), const bool>::value, "");
224 static_assert(ex::is_move_constructible_v<T> == std::is_move_constructible<T>::value, "");
225 }
226 {
227 typedef void T;
228 static_assert(!ex::is_move_constructible_v<T>, "");
229 static_assert(ex::is_move_constructible_v<T> == std::is_move_constructible<T>::value, "");
230 }
231 {
232 typedef int & T;
233 typedef int U;
234 static_assert(ex::is_assignable_v<T, U>, "");
235 static_assert(std::is_same<decltype(ex::is_assignable_v<T, U>), const bool>::value, "");
236 static_assert(ex::is_assignable_v<T, U> == std::is_assignable<T, U>::value, "");
237 }
238 {
239 typedef int & T;
240 typedef void U;
241 static_assert(!ex::is_assignable_v<T, U>, "");
242 static_assert(ex::is_assignable_v<T, U> == std::is_assignable<T, U>::value, "");
243 }
244 {
245 typedef int T;
246 static_assert(ex::is_copy_assignable_v<T>, "");
247 static_assert(std::is_same<decltype(ex::is_copy_assignable_v<T>), const bool>::value, "");
248 static_assert(ex::is_copy_assignable_v<T> == std::is_copy_assignable<T>::value, "");
249 }
250 {
251 typedef void T;
252 static_assert(!ex::is_copy_assignable_v<T>, "");
253 static_assert(ex::is_copy_assignable_v<T> == std::is_copy_assignable<T>::value, "");
254 }
255 {
256 typedef int T;
257 static_assert(ex::is_move_assignable_v<T>, "");
258 static_assert(std::is_same<decltype(ex::is_move_assignable_v<T>), const bool>::value, "");
259 static_assert(ex::is_move_assignable_v<T> == std::is_move_assignable<T>::value, "");
260 }
261 {
262 typedef void T;
263 static_assert(!ex::is_move_assignable_v<T>, "");
264 static_assert(ex::is_move_assignable_v<T> == std::is_move_assignable<T>::value, "");
265 }
266 {
267 typedef int T;
268 static_assert(ex::is_destructible_v<T>, "");
269 static_assert(std::is_same<decltype(ex::is_destructible_v<T>), const bool>::value, "");
270 static_assert(ex::is_destructible_v<T> == std::is_destructible<T>::value, "");
271 }
272 {
273 typedef void T;
274 static_assert(!ex::is_destructible_v<T>, "");
275 static_assert(ex::is_destructible_v<T> == std::is_destructible<T>::value, "");
276 }
277 }
278
is_trivially_constructible_and_assignable_test()279 void is_trivially_constructible_and_assignable_test()
280 {
281 {
282 typedef int T;
283 static_assert(ex::is_trivially_constructible_v<T, int>, "");
284 static_assert(std::is_same<decltype(ex::is_trivially_constructible_v<T, int>), const bool>::value, "");
285 static_assert(ex::is_trivially_constructible_v<T, int> == std::is_constructible<T, int>::value, "");
286 }
287 {
288 typedef void T;
289 static_assert(!ex::is_trivially_constructible_v<T, int>, "");
290 static_assert(ex::is_trivially_constructible_v<T, int> == std::is_constructible<T, int>::value, "");
291 }
292 {
293 typedef int T;
294 static_assert(ex::is_trivially_default_constructible_v<T>, "");
295 static_assert(std::is_same<decltype(ex::is_trivially_default_constructible_v<T>), const bool>::value, "");
296 static_assert(ex::is_trivially_default_constructible_v<T> == std::is_default_constructible<T>::value, "");
297 }
298 {
299 typedef int & T;
300 static_assert(!ex::is_trivially_default_constructible_v<T>, "");
301 static_assert(ex::is_trivially_default_constructible_v<T> == std::is_default_constructible<T>::value, "");
302 }
303 {
304 typedef int T;
305 static_assert(ex::is_trivially_copy_constructible_v<T>, "");
306 static_assert(std::is_same<decltype(ex::is_trivially_copy_constructible_v<T>), const bool>::value, "");
307 static_assert(ex::is_trivially_copy_constructible_v<T> == std::is_copy_constructible<T>::value, "");
308 }
309 {
310 typedef void T;
311 static_assert(!ex::is_trivially_copy_constructible_v<T>, "");
312 static_assert(ex::is_trivially_copy_constructible_v<T> == std::is_copy_constructible<T>::value, "");
313 }
314 {
315 typedef int T;
316 static_assert(ex::is_trivially_move_constructible_v<T>, "");
317 static_assert(std::is_same<decltype(ex::is_trivially_move_constructible_v<T>), const bool>::value, "");
318 static_assert(ex::is_trivially_move_constructible_v<T> == std::is_move_constructible<T>::value, "");
319 }
320 {
321 typedef void T;
322 static_assert(!ex::is_trivially_move_constructible_v<T>, "");
323 static_assert(ex::is_trivially_move_constructible_v<T> == std::is_move_constructible<T>::value, "");
324 }
325 {
326 typedef int & T;
327 typedef int U;
328 static_assert(ex::is_trivially_assignable_v<T, U>, "");
329 static_assert(std::is_same<decltype(ex::is_trivially_assignable_v<T, U>), const bool>::value, "");
330 static_assert(ex::is_trivially_assignable_v<T, U> == std::is_assignable<T, U>::value, "");
331 }
332 {
333 typedef int & T;
334 typedef void U;
335 static_assert(!ex::is_trivially_assignable_v<T, U>, "");
336 static_assert(ex::is_trivially_assignable_v<T, U> == std::is_assignable<T, U>::value, "");
337 }
338 {
339 typedef int T;
340 static_assert(ex::is_trivially_copy_assignable_v<T>, "");
341 static_assert(std::is_same<decltype(ex::is_trivially_copy_assignable_v<T>), const bool>::value, "");
342 static_assert(ex::is_trivially_copy_assignable_v<T> == std::is_copy_assignable<T>::value, "");
343 }
344 {
345 typedef void T;
346 static_assert(!ex::is_trivially_copy_assignable_v<T>, "");
347 static_assert(ex::is_trivially_copy_assignable_v<T> == std::is_copy_assignable<T>::value, "");
348 }
349 {
350 typedef int T;
351 static_assert(ex::is_trivially_move_assignable_v<T>, "");
352 static_assert(std::is_same<decltype(ex::is_trivially_move_assignable_v<T>), const bool>::value, "");
353 static_assert(ex::is_trivially_move_assignable_v<T> == std::is_move_assignable<T>::value, "");
354 }
355 {
356 typedef void T;
357 static_assert(!ex::is_trivially_move_assignable_v<T>, "");
358 static_assert(ex::is_trivially_move_assignable_v<T> == std::is_move_assignable<T>::value, "");
359 }
360 {
361 typedef int T;
362 static_assert(ex::is_trivially_destructible_v<T>, "");
363 static_assert(std::is_same<decltype(ex::is_trivially_destructible_v<T>), const bool>::value, "");
364 static_assert(ex::is_trivially_destructible_v<T> == std::is_destructible<T>::value, "");
365 }
366 {
367 typedef void T;
368 static_assert(!ex::is_trivially_destructible_v<T>, "");
369 static_assert(ex::is_trivially_destructible_v<T> == std::is_destructible<T>::value, "");
370 }
371 }
372
373
374
is_nothrow_constructible_and_assignable_test()375 void is_nothrow_constructible_and_assignable_test()
376 {
377 {
378 typedef int T;
379 static_assert(ex::is_nothrow_constructible_v<T, int>, "");
380 static_assert(std::is_same<decltype(ex::is_nothrow_constructible_v<T, int>), const bool>::value, "");
381 static_assert(ex::is_nothrow_constructible_v<T, int> == std::is_constructible<T, int>::value, "");
382 }
383 {
384 typedef void T;
385 static_assert(!ex::is_nothrow_constructible_v<T, int>, "");
386 static_assert(ex::is_nothrow_constructible_v<T, int> == std::is_constructible<T, int>::value, "");
387 }
388 {
389 typedef int T;
390 static_assert(ex::is_nothrow_default_constructible_v<T>, "");
391 static_assert(std::is_same<decltype(ex::is_nothrow_default_constructible_v<T>), const bool>::value, "");
392 static_assert(ex::is_nothrow_default_constructible_v<T> == std::is_default_constructible<T>::value, "");
393 }
394 {
395 typedef int & T;
396 static_assert(!ex::is_nothrow_default_constructible_v<T>, "");
397 static_assert(ex::is_nothrow_default_constructible_v<T> == std::is_default_constructible<T>::value, "");
398 }
399 {
400 typedef int T;
401 static_assert(ex::is_nothrow_copy_constructible_v<T>, "");
402 static_assert(std::is_same<decltype(ex::is_nothrow_copy_constructible_v<T>), const bool>::value, "");
403 static_assert(ex::is_nothrow_copy_constructible_v<T> == std::is_copy_constructible<T>::value, "");
404 }
405 {
406 typedef void T;
407 static_assert(!ex::is_nothrow_copy_constructible_v<T>, "");
408 static_assert(ex::is_nothrow_copy_constructible_v<T> == std::is_copy_constructible<T>::value, "");
409 }
410 {
411 typedef int T;
412 static_assert(ex::is_nothrow_move_constructible_v<T>, "");
413 static_assert(std::is_same<decltype(ex::is_nothrow_move_constructible_v<T>), const bool>::value, "");
414 static_assert(ex::is_nothrow_move_constructible_v<T> == std::is_move_constructible<T>::value, "");
415 }
416 {
417 typedef void T;
418 static_assert(!ex::is_nothrow_move_constructible_v<T>, "");
419 static_assert(ex::is_nothrow_move_constructible_v<T> == std::is_move_constructible<T>::value, "");
420 }
421 {
422 typedef int & T;
423 typedef int U;
424 static_assert(ex::is_nothrow_assignable_v<T, U>, "");
425 static_assert(std::is_same<decltype(ex::is_nothrow_assignable_v<T, U>), const bool>::value, "");
426 static_assert(ex::is_nothrow_assignable_v<T, U> == std::is_assignable<T, U>::value, "");
427 }
428 {
429 typedef int & T;
430 typedef void U;
431 static_assert(!ex::is_nothrow_assignable_v<T, U>, "");
432 static_assert(ex::is_nothrow_assignable_v<T, U> == std::is_assignable<T, U>::value, "");
433 }
434 {
435 typedef int T;
436 static_assert(ex::is_nothrow_copy_assignable_v<T>, "");
437 static_assert(std::is_same<decltype(ex::is_nothrow_copy_assignable_v<T>), const bool>::value, "");
438 static_assert(ex::is_nothrow_copy_assignable_v<T> == std::is_copy_assignable<T>::value, "");
439 }
440 {
441 typedef void T;
442 static_assert(!ex::is_nothrow_copy_assignable_v<T>, "");
443 static_assert(ex::is_nothrow_copy_assignable_v<T> == std::is_copy_assignable<T>::value, "");
444 }
445 {
446 typedef int T;
447 static_assert(ex::is_nothrow_move_assignable_v<T>, "");
448 static_assert(std::is_same<decltype(ex::is_nothrow_move_assignable_v<T>), const bool>::value, "");
449 static_assert(ex::is_nothrow_move_assignable_v<T> == std::is_move_assignable<T>::value, "");
450 }
451 {
452 typedef void T;
453 static_assert(!ex::is_nothrow_move_assignable_v<T>, "");
454 static_assert(ex::is_nothrow_move_assignable_v<T> == std::is_move_assignable<T>::value, "");
455 }
456 {
457 typedef int T;
458 static_assert(ex::is_nothrow_destructible_v<T>, "");
459 static_assert(std::is_same<decltype(ex::is_nothrow_destructible_v<T>), const bool>::value, "");
460 static_assert(ex::is_nothrow_destructible_v<T> == std::is_destructible<T>::value, "");
461 }
462 {
463 typedef void T;
464 static_assert(!ex::is_nothrow_destructible_v<T>, "");
465 static_assert(ex::is_nothrow_destructible_v<T> == std::is_destructible<T>::value, "");
466 }
467 }
468
main()469 int main()
470 {
471 type_properties_test();
472 is_constructible_and_assignable_test();
473 is_trivially_constructible_and_assignable_test();
474 is_nothrow_constructible_and_assignable_test();
475 {
476 typedef virtual_dtor_type T;
477 static_assert(ex::has_virtual_destructor_v<T>, "");
478 static_assert(std::is_same<decltype(ex::has_virtual_destructor_v<T>), const bool>::value, "");
479 static_assert(ex::has_virtual_destructor_v<T> == std::has_virtual_destructor<T>::value, "");
480 }
481 {
482 typedef int T;
483 static_assert(!ex::has_virtual_destructor_v<T>, "");
484 static_assert(ex::has_virtual_destructor_v<T> == std::has_virtual_destructor<T>::value, "");
485 }
486 }
487 #else /* _LIBCPP_STD_VER <= 11 */
main()488 int main() {}
489 #endif /* _LIBCPP_STD_VER > 11 */
490