Warning: This file is not a C or C++ file. It does not have highlighting.
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/copy_cv.h> |
14 | #include <__type_traits/is_enum.h> |
15 | #include <__type_traits/is_integral.h> |
16 | #include <__type_traits/remove_cv.h> |
17 | #include <__type_traits/type_list.h> |
18 | |
19 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
20 | # pragma GCC system_header |
21 | #endif |
22 | |
23 | _LIBCPP_BEGIN_NAMESPACE_STD |
24 | |
25 | #if __has_builtin(__make_signed) |
26 | |
27 | template <class _Tp> |
28 | using __make_signed_t _LIBCPP_NODEBUG = __make_signed(_Tp); |
29 | |
30 | #else |
31 | using __signed_types = |
32 | __type_list<signed char, |
33 | signed short, |
34 | signed int, |
35 | signed long, |
36 | signed long long |
37 | # if _LIBCPP_HAS_INT128 |
38 | , |
39 | __int128_t |
40 | # endif |
41 | >; |
42 | |
43 | template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value> |
44 | struct __make_signed{}; |
45 | |
46 | template <class _Tp> |
47 | struct __make_signed<_Tp, true> { |
48 | typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type; |
49 | }; |
50 | |
51 | // clang-format off |
52 | template <> struct __make_signed<bool, true> {}; |
53 | template <> struct __make_signed< signed short, true> {typedef short type;}; |
54 | template <> struct __make_signed<unsigned short, true> {typedef short type;}; |
55 | template <> struct __make_signed< signed int, true> {typedef int type;}; |
56 | template <> struct __make_signed<unsigned int, true> {typedef int type;}; |
57 | template <> struct __make_signed< signed long, true> {typedef long type;}; |
58 | template <> struct __make_signed<unsigned long, true> {typedef long type;}; |
59 | template <> struct __make_signed< signed long long, true> {typedef long long type;}; |
60 | template <> struct __make_signed<unsigned long long, true> {typedef long long type;}; |
61 | # if _LIBCPP_HAS_INT128 |
62 | template <> struct __make_signed<__int128_t, true> {typedef __int128_t type;}; |
63 | template <> struct __make_signed<__uint128_t, true> {typedef __int128_t type;}; |
64 | # endif |
65 | // clang-format on |
66 | |
67 | template <class _Tp> |
68 | using __make_signed_t = __copy_cv_t<_Tp, typename __make_signed<__remove_cv_t<_Tp> >::type>; |
69 | |
70 | #endif // __has_builtin(__make_signed) |
71 | |
72 | template <class _Tp> |
73 | struct _LIBCPP_NO_SPECIALIZATIONS make_signed { |
74 | using type _LIBCPP_NODEBUG = __make_signed_t<_Tp>; |
75 | }; |
76 | |
77 | #if _LIBCPP_STD_VER >= 14 |
78 | template <class _Tp> |
79 | using make_signed_t = __make_signed_t<_Tp>; |
80 | #endif |
81 | |
82 | _LIBCPP_END_NAMESPACE_STD |
83 | |
84 | #endif // _LIBCPP___TYPE_TRAITS_MAKE_SIGNED_H |
85 |
Warning: This file is not a C or C++ file. It does not have highlighting.