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   static const size_t value = _I0;
29 };
30 
31 template <size_t _I0, size_t _I1, size_t... _In>
32 struct __static_max<_I0, _I1, _In...> {
33   static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value : __static_max<_I1, _In...>::value;
34 };
35 
36 template <size_t _Len, class _Type0, class... _Types>
37 struct _LIBCPP_DEPRECATED_IN_CXX23 aligned_union {
38   static const size_t alignment_value =
39       __static_max<_LIBCPP_PREFERRED_ALIGNOF(_Type0), _LIBCPP_PREFERRED_ALIGNOF(_Types)...>::value;
40   static const size_t __len = __static_max<_Len, sizeof(_Type0), sizeof(_Types)...>::value;
41   typedef typename aligned_storage<__len, alignment_value>::type type;
42 };
43 
44 #if _LIBCPP_STD_VER >= 14
45 template <size_t _Len, class... _Types>
46 using aligned_union_t _LIBCPP_DEPRECATED_IN_CXX23 = typename aligned_union<_Len, _Types...>::type;
47 #endif
48 
49 _LIBCPP_END_NAMESPACE_STD
50 
51 #endif // _LIBCPP___TYPE_TRAITS_ALIGNED_UNION_H
52