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_INTEGER_TRAITS_H
10#define _LIBCPP___TYPE_TRAITS_INTEGER_TRAITS_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20// This trait is to determine whether a type is a /signed integer type/
21// See [basic.fundamental]/p1
22template <class _Tp>
23inline const bool __is_signed_integer_v = false;
24template <>
25inline const bool __is_signed_integer_v<signed char> = true;
26template <>
27inline const bool __is_signed_integer_v<signed short> = true;
28template <>
29inline const bool __is_signed_integer_v<signed int> = true;
30template <>
31inline const bool __is_signed_integer_v<signed long> = true;
32template <>
33inline const bool __is_signed_integer_v<signed long long> = true;
34#if _LIBCPP_HAS_INT128
35template <>
36inline const bool __is_signed_integer_v<__int128_t> = true;
37#endif
38
39// This trait is to determine whether a type is an /unsigned integer type/
40// See [basic.fundamental]/p2
41template <class _Tp>
42inline const bool __is_unsigned_integer_v = false;
43template <>
44inline const bool __is_unsigned_integer_v<unsigned char> = true;
45template <>
46inline const bool __is_unsigned_integer_v<unsigned short> = true;
47template <>
48inline const bool __is_unsigned_integer_v<unsigned int> = true;
49template <>
50inline const bool __is_unsigned_integer_v<unsigned long> = true;
51template <>
52inline const bool __is_unsigned_integer_v<unsigned long long> = true;
53#if _LIBCPP_HAS_INT128
54template <>
55inline const bool __is_unsigned_integer_v<__uint128_t> = true;
56#endif
57
58#if _LIBCPP_STD_VER >= 20
59template <class _Tp>
60concept __signed_integer = __is_signed_integer_v<_Tp>;
61
62template <class _Tp>
63concept __unsigned_integer = __is_unsigned_integer_v<_Tp>;
64
65// This isn't called __integer, because an integer type according to [basic.fundamental]/p11 is the same as an integral
66// type. An integral type is _not_ the same set of types as signed and unsigned integer types combined.
67template <class _Tp>
68concept __signed_or_unsigned_integer = __signed_integer<_Tp> || __unsigned_integer<_Tp>;
69#endif
70
71_LIBCPP_END_NAMESPACE_STD
72
73#endif // _LIBCPP___TYPE_TRAITS_INTEGER_TRAITS_H
74

Warning: This file is not a C or C++ file. It does not have highlighting.

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