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 #ifndef _LIBCPP___TYPE_TRAITS_ALIGNED_UNION_H
10 #define _LIBCPP___TYPE_TRAITS_ALIGNED_UNION_H
11 
12 #include <__config>
13 #include <__type_traits/aligned_storage.h>
14 #include <__type_traits/integral_constant.h>
15 #include <cstddef>
16 
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 #  pragma GCC system_header
19 #endif
20 
21 _LIBCPP_BEGIN_NAMESPACE_STD
22 
23 template <size_t _I0, size_t ..._In>
24 struct __static_max;
25 
26 template <size_t _I0>
27 struct __static_max<_I0>
28 {
29     static const size_t value = _I0;
30 };
31 
32 template <size_t _I0, size_t _I1, size_t ..._In>
33 struct __static_max<_I0, _I1, _In...>
34 {
35     static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value :
36                                              __static_max<_I1, _In...>::value;
37 };
38 
39 template <size_t _Len, class _Type0, class ..._Types>
40 struct aligned_union
41 {
42     static const size_t alignment_value = __static_max<_LIBCPP_PREFERRED_ALIGNOF(_Type0),
43                                                        _LIBCPP_PREFERRED_ALIGNOF(_Types)...>::value;
44     static const size_t __len = __static_max<_Len, sizeof(_Type0),
45                                              sizeof(_Types)...>::value;
46     typedef typename aligned_storage<__len, alignment_value>::type type;
47 };
48 
49 #if _LIBCPP_STD_VER > 11
50 template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
51 #endif
52 
53 _LIBCPP_END_NAMESPACE_STD
54 
55 #endif // _LIBCPP___TYPE_TRAITS_ALIGNED_UNION_H
56