1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// type_traits
10
11// is_union
12
13#include <type_traits>
14#include <cstddef> // for std::nullptr_t
15#include "test_macros.h"
16
17template <class T>
18void test_is_union()
19{
20 static_assert( std::is_union<T>::value, "");
21 static_assert( std::is_union<const T>::value, "");
22 static_assert( std::is_union<volatile T>::value, "");
23 static_assert( std::is_union<const volatile T>::value, "");
24#if TEST_STD_VER > 14
25 static_assert( std::is_union_v<T>, "");
26 static_assert( std::is_union_v<const T>, "");
27 static_assert( std::is_union_v<volatile T>, "");
28 static_assert( std::is_union_v<const volatile T>, "");
29#endif
30}
31
32template <class T>
33void test_is_not_union()
34{
35 static_assert(!std::is_union<T>::value, "");
36 static_assert(!std::is_union<const T>::value, "");
37 static_assert(!std::is_union<volatile T>::value, "");
38 static_assert(!std::is_union<const volatile T>::value, "");
39#if TEST_STD_VER > 14
40 static_assert(!std::is_union_v<T>, "");
41 static_assert(!std::is_union_v<const T>, "");
42 static_assert(!std::is_union_v<volatile T>, "");
43 static_assert(!std::is_union_v<const volatile T>, "");
44#endif
45}
46
47class Empty
48{
49};
50
51class NotEmpty
52{
53 virtual ~NotEmpty();
54};
55
56union Union {};
57
58struct bit_zero
59{
60 int : 0;
61};
62
63class Abstract
64{
65 virtual ~Abstract() = 0;
66};
67
68enum Enum {zero, one};
69struct incomplete_type;
70
71typedef void (*FunctionPtr)();
72
73int main(int, char**)
74{
75 test_is_union<Union>();
76
77 test_is_not_union<std::nullptr_t>();
78 test_is_not_union<void>();
79 test_is_not_union<int>();
80 test_is_not_union<int&>();
81 test_is_not_union<int&&>();
82 test_is_not_union<int*>();
83 test_is_not_union<double>();
84 test_is_not_union<const int*>();
85 test_is_not_union<char[3]>();
86 test_is_not_union<char[]>();
87 test_is_not_union<Enum>();
88 test_is_not_union<FunctionPtr>();
89 test_is_not_union<Empty>();
90 test_is_not_union<bit_zero>();
91 test_is_not_union<NotEmpty>();
92 test_is_not_union<Abstract>();
93 test_is_not_union<incomplete_type>();
94
95 return 0;
96}
97

source code of libcxx/test/std/utilities/meta/meta.unary/meta.unary.cat/is_union.pass.cpp