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_SIGNED_H
10 #define _LIBCPP___TYPE_TRAITS_MAKE_SIGNED_H
11 
12 #include <__config>
13 #include <__type_traits/apply_cv.h>
14 #include <__type_traits/is_enum.h>
15 #include <__type_traits/is_integral.h>
16 #include <__type_traits/nat.h>
17 #include <__type_traits/remove_cv.h>
18 #include <__type_traits/type_list.h>
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 typedef
27     __type_list<signed char,
28     __type_list<signed short,
29     __type_list<signed int,
30     __type_list<signed long,
31     __type_list<signed long long,
32 #ifndef _LIBCPP_HAS_NO_INT128
33     __type_list<__int128_t,
34 #endif
35     __nat
36 #ifndef _LIBCPP_HAS_NO_INT128
37     >
38 #endif
39     > > > > > __signed_types;
40 
41 template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
42 struct __make_signed {};
43 
44 template <class _Tp>
45 struct __make_signed<_Tp, true>
46 {
47     typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
48 };
49 
50 template <> struct __make_signed<bool,               true> {};
51 template <> struct __make_signed<  signed short,     true> {typedef short     type;};
52 template <> struct __make_signed<unsigned short,     true> {typedef short     type;};
53 template <> struct __make_signed<  signed int,       true> {typedef int       type;};
54 template <> struct __make_signed<unsigned int,       true> {typedef int       type;};
55 template <> struct __make_signed<  signed long,      true> {typedef long      type;};
56 template <> struct __make_signed<unsigned long,      true> {typedef long      type;};
57 template <> struct __make_signed<  signed long long, true> {typedef long long type;};
58 template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
59 #ifndef _LIBCPP_HAS_NO_INT128
60 template <> struct __make_signed<__int128_t,         true> {typedef __int128_t type;};
61 template <> struct __make_signed<__uint128_t,        true> {typedef __int128_t type;};
62 #endif
63 
64 template <class _Tp>
65 struct _LIBCPP_TEMPLATE_VIS make_signed
66 {
67     typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
68 };
69 
70 #if _LIBCPP_STD_VER > 11
71 template <class _Tp> using make_signed_t = typename make_signed<_Tp>::type;
72 #endif
73 
74 _LIBCPP_END_NAMESPACE_STD
75 
76 #endif // _LIBCPP___TYPE_TRAITS_MAKE_SIGNED_H
77