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_MAKE_32_64_OR_128_BIT_H
10 #define _LIBCPP___TYPE_TRAITS_MAKE_32_64_OR_128_BIT_H
11 
12 #include <__config>
13 #include <__type_traits/conditional.h>
14 #include <__type_traits/is_same.h>
15 #include <__type_traits/is_signed.h>
16 #include <__type_traits/is_unsigned.h>
17 #include <__type_traits/make_unsigned.h>
18 #include <cstdint>
19 
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 #  pragma GCC system_header
22 #endif
23 
24 _LIBCPP_BEGIN_NAMESPACE_STD
25 
26 /// Helper to promote an integral to smallest 32, 64, or 128 bit representation.
27 ///
28 /// The restriction is the same as the integral version of to_char.
29 template <class _Tp>
30 #if _LIBCPP_STD_VER > 17
31   requires (is_signed_v<_Tp> || is_unsigned_v<_Tp> || is_same_v<_Tp, char>)
32 #endif
33 using __make_32_64_or_128_bit_t =
34   __copy_unsigned_t<_Tp,
35     __conditional_t<sizeof(_Tp) <= sizeof(int32_t),    int32_t,
36     __conditional_t<sizeof(_Tp) <= sizeof(int64_t),    int64_t,
37 #ifndef _LIBCPP_HAS_NO_INT128
38     __conditional_t<sizeof(_Tp) <= sizeof(__int128_t), __int128_t,
39     /* else */                                         void>
40 #else
41     /* else */                                         void
42 #endif
43     > >
44   >;
45 
46 _LIBCPP_END_NAMESPACE_STD
47 
48 #endif // _LIBCPP___TYPE_TRAITS_MAKE_32_64_OR_128_BIT_H
49