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
27template <class _Tp>
28using __make_signed_t _LIBCPP_NODEBUG = __make_signed(_Tp);
29
30#else
31using __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
43template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
44struct __make_signed{};
45
46template <class _Tp>
47struct __make_signed<_Tp, true> {
48 typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
49};
50
51// clang-format off
52template <> struct __make_signed<bool, true> {};
53template <> struct __make_signed< signed short, true> {typedef short type;};
54template <> struct __make_signed<unsigned short, true> {typedef short type;};
55template <> struct __make_signed< signed int, true> {typedef int type;};
56template <> struct __make_signed<unsigned int, true> {typedef int type;};
57template <> struct __make_signed< signed long, true> {typedef long type;};
58template <> struct __make_signed<unsigned long, true> {typedef long type;};
59template <> struct __make_signed< signed long long, true> {typedef long long type;};
60template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
61# if _LIBCPP_HAS_INT128
62template <> struct __make_signed<__int128_t, true> {typedef __int128_t type;};
63template <> struct __make_signed<__uint128_t, true> {typedef __int128_t type;};
64# endif
65// clang-format on
66
67template <class _Tp>
68using __make_signed_t = __copy_cv_t<_Tp, typename __make_signed<__remove_cv_t<_Tp> >::type>;
69
70#endif // __has_builtin(__make_signed)
71
72template <class _Tp>
73struct _LIBCPP_NO_SPECIALIZATIONS make_signed {
74 using type _LIBCPP_NODEBUG = __make_signed_t<_Tp>;
75};
76
77#if _LIBCPP_STD_VER >= 14
78template <class _Tp>
79using 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.

source code of libcxx/include/__type_traits/make_signed.h