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 #if __has_builtin(__make_signed) 27 28 template <class _Tp> 29 using __make_signed_t = __make_signed(_Tp); 30 31 #else 32 typedef 33 __type_list<signed char, 34 __type_list<signed short, 35 __type_list<signed int, 36 __type_list<signed long, 37 __type_list<signed long long, 38 # ifndef _LIBCPP_HAS_NO_INT128 39 __type_list<__int128_t, 40 # endif 41 __nat 42 # ifndef _LIBCPP_HAS_NO_INT128 43 > 44 # endif 45 > > > > > __signed_types; 46 47 template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value> 48 struct __make_signed {}; 49 50 template <class _Tp> 51 struct __make_signed<_Tp, true> 52 { 53 typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type; 54 }; 55 56 template <> struct __make_signed<bool, true> {}; 57 template <> struct __make_signed< signed short, true> {typedef short type;}; 58 template <> struct __make_signed<unsigned short, true> {typedef short type;}; 59 template <> struct __make_signed< signed int, true> {typedef int type;}; 60 template <> struct __make_signed<unsigned int, true> {typedef int type;}; 61 template <> struct __make_signed< signed long, true> {typedef long type;}; 62 template <> struct __make_signed<unsigned long, true> {typedef long type;}; 63 template <> struct __make_signed< signed long long, true> {typedef long long type;}; 64 template <> struct __make_signed<unsigned long long, true> {typedef long long type;}; 65 # ifndef _LIBCPP_HAS_NO_INT128 66 template <> struct __make_signed<__int128_t, true> {typedef __int128_t type;}; 67 template <> struct __make_signed<__uint128_t, true> {typedef __int128_t type;}; 68 # endif 69 70 template <class _Tp> 71 using __make_signed_t = typename __apply_cv<_Tp, typename __make_signed<__remove_cv_t<_Tp> >::type>::type; 72 73 #endif // __has_builtin(__make_signed) 74 75 template <class _Tp> 76 struct make_signed { 77 using type _LIBCPP_NODEBUG = __make_signed_t<_Tp>; 78 }; 79 80 #if _LIBCPP_STD_VER > 11 81 template <class _Tp> using make_signed_t = __make_signed_t<_Tp>; 82 #endif 83 84 _LIBCPP_END_NAMESPACE_STD 85 86 #endif // _LIBCPP___TYPE_TRAITS_MAKE_SIGNED_H 87