Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | 9bd9388 | 2021-11-17 16:25:01 -0500 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_CSTDDEF |
| 11 | #define _LIBCPP_CSTDDEF |
| 12 | |
| 13 | /* |
| 14 | cstddef synopsis |
| 15 | |
| 16 | Macros: |
| 17 | |
| 18 | offsetof(type,member-designator) |
| 19 | NULL |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 20 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | namespace std |
| 22 | { |
| 23 | |
| 24 | Types: |
| 25 | |
| 26 | ptrdiff_t |
| 27 | size_t |
Joerg Sonnenberger | 09c4ae5 | 2020-04-04 00:48:02 +0200 | [diff] [blame] | 28 | max_align_t // C++11 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 29 | nullptr_t |
Marshall Clow | cade1f7 | 2017-03-24 05:45:39 +0000 | [diff] [blame] | 30 | byte // C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 31 | |
| 32 | } // std |
| 33 | |
| 34 | */ |
| 35 | |
| 36 | #include <__config> |
Louis Dionne | 9bb7cf4 | 2021-09-08 12:57:58 -0400 | [diff] [blame] | 37 | #include <stddef.h> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 38 | #include <version> |
Howard Hinnant | 59ef87b | 2010-06-02 18:53:22 +0000 | [diff] [blame] | 39 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 40 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 41 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 42 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 43 | |
| 44 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 45 | |
Louis Dionne | 9bb7cf4 | 2021-09-08 12:57:58 -0400 | [diff] [blame] | 46 | using ::nullptr_t; |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 47 | using ::ptrdiff_t _LIBCPP_USING_IF_EXISTS; |
| 48 | using ::size_t _LIBCPP_USING_IF_EXISTS; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 49 | |
Joerg Sonnenberger | 09c4ae5 | 2020-04-04 00:48:02 +0200 | [diff] [blame] | 50 | #if !defined(_LIBCPP_CXX03_LANG) |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 51 | using ::max_align_t _LIBCPP_USING_IF_EXISTS; |
Chandler Carruth | 4dcf199 | 2014-02-21 08:37:30 +0000 | [diff] [blame] | 52 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 53 | |
Eric Fiselier | d2971c6 | 2020-02-14 17:34:46 +0100 | [diff] [blame] | 54 | template <class _Tp> struct __libcpp_is_integral { enum { value = 0 }; }; |
| 55 | template <> struct __libcpp_is_integral<bool> { enum { value = 1 }; }; |
| 56 | template <> struct __libcpp_is_integral<char> { enum { value = 1 }; }; |
| 57 | template <> struct __libcpp_is_integral<signed char> { enum { value = 1 }; }; |
| 58 | template <> struct __libcpp_is_integral<unsigned char> { enum { value = 1 }; }; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 59 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Eric Fiselier | d2971c6 | 2020-02-14 17:34:46 +0100 | [diff] [blame] | 60 | template <> struct __libcpp_is_integral<wchar_t> { enum { value = 1 }; }; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 61 | #endif |
Arthur O'Dwyer | afa5d5f | 2021-04-18 21:47:08 -0400 | [diff] [blame] | 62 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
Eric Fiselier | d2971c6 | 2020-02-14 17:34:46 +0100 | [diff] [blame] | 63 | template <> struct __libcpp_is_integral<char8_t> { enum { value = 1 }; }; |
| 64 | #endif |
| 65 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
| 66 | template <> struct __libcpp_is_integral<char16_t> { enum { value = 1 }; }; |
| 67 | template <> struct __libcpp_is_integral<char32_t> { enum { value = 1 }; }; |
Louis Dionne | 96fc5f5 | 2021-09-09 11:25:10 -0400 | [diff] [blame] | 68 | #endif |
Eric Fiselier | d2971c6 | 2020-02-14 17:34:46 +0100 | [diff] [blame] | 69 | template <> struct __libcpp_is_integral<short> { enum { value = 1 }; }; |
| 70 | template <> struct __libcpp_is_integral<unsigned short> { enum { value = 1 }; }; |
| 71 | template <> struct __libcpp_is_integral<int> { enum { value = 1 }; }; |
| 72 | template <> struct __libcpp_is_integral<unsigned int> { enum { value = 1 }; }; |
| 73 | template <> struct __libcpp_is_integral<long> { enum { value = 1 }; }; |
| 74 | template <> struct __libcpp_is_integral<unsigned long> { enum { value = 1 }; }; |
| 75 | template <> struct __libcpp_is_integral<long long> { enum { value = 1 }; }; |
| 76 | template <> struct __libcpp_is_integral<unsigned long long> { enum { value = 1 }; }; |
| 77 | #ifndef _LIBCPP_HAS_NO_INT128 |
| 78 | template <> struct __libcpp_is_integral<__int128_t> { enum { value = 1 }; }; |
| 79 | template <> struct __libcpp_is_integral<__uint128_t> { enum { value = 1 }; }; |
| 80 | #endif |
| 81 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 82 | _LIBCPP_END_NAMESPACE_STD |
| 83 | |
Marshall Clow | cade1f7 | 2017-03-24 05:45:39 +0000 | [diff] [blame] | 84 | #if _LIBCPP_STD_VER > 14 |
| 85 | namespace std // purposefully not versioned |
| 86 | { |
| 87 | enum class byte : unsigned char {}; |
| 88 | |
Eric Fiselier | d2971c6 | 2020-02-14 17:34:46 +0100 | [diff] [blame] | 89 | |
| 90 | template <bool> struct __enable_if_integral_imp {}; |
| 91 | template <> struct __enable_if_integral_imp<true> { using type = byte; }; |
| 92 | template <class _Tp> using _EnableByteOverload = typename __enable_if_integral_imp<__libcpp_is_integral<_Tp>::value>::type; |
| 93 | |
Marshall Clow | cade1f7 | 2017-03-24 05:45:39 +0000 | [diff] [blame] | 94 | constexpr byte operator| (byte __lhs, byte __rhs) noexcept |
Marshall Clow | 31c8f46 | 2017-11-14 01:14:53 +0000 | [diff] [blame] | 95 | { |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 96 | return static_cast<byte>( |
| 97 | static_cast<unsigned char>( |
| 98 | static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs) |
| 99 | )); |
Marshall Clow | 31c8f46 | 2017-11-14 01:14:53 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept |
| 103 | { return __lhs = __lhs | __rhs; } |
| 104 | |
| 105 | constexpr byte operator& (byte __lhs, byte __rhs) noexcept |
| 106 | { |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 107 | return static_cast<byte>( |
| 108 | static_cast<unsigned char>( |
| 109 | static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs) |
| 110 | )); |
Marshall Clow | 31c8f46 | 2017-11-14 01:14:53 +0000 | [diff] [blame] | 111 | } |
Marshall Clow | cade1f7 | 2017-03-24 05:45:39 +0000 | [diff] [blame] | 112 | |
| 113 | constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept |
Marshall Clow | 31c8f46 | 2017-11-14 01:14:53 +0000 | [diff] [blame] | 114 | { return __lhs = __lhs & __rhs; } |
| 115 | |
| 116 | constexpr byte operator^ (byte __lhs, byte __rhs) noexcept |
| 117 | { |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 118 | return static_cast<byte>( |
| 119 | static_cast<unsigned char>( |
| 120 | static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs) |
| 121 | )); |
Marshall Clow | 31c8f46 | 2017-11-14 01:14:53 +0000 | [diff] [blame] | 122 | } |
Marshall Clow | cade1f7 | 2017-03-24 05:45:39 +0000 | [diff] [blame] | 123 | |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 124 | constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept |
Marshall Clow | 31c8f46 | 2017-11-14 01:14:53 +0000 | [diff] [blame] | 125 | { return __lhs = __lhs ^ __rhs; } |
Marshall Clow | cade1f7 | 2017-03-24 05:45:39 +0000 | [diff] [blame] | 126 | |
| 127 | constexpr byte operator~ (byte __b) noexcept |
Marshall Clow | 31c8f46 | 2017-11-14 01:14:53 +0000 | [diff] [blame] | 128 | { |
| 129 | return static_cast<byte>( |
| 130 | static_cast<unsigned char>( |
| 131 | ~static_cast<unsigned int>(__b) |
| 132 | )); |
| 133 | } |
Eric Fiselier | d2971c6 | 2020-02-14 17:34:46 +0100 | [diff] [blame] | 134 | template <class _Integer> |
| 135 | constexpr _EnableByteOverload<_Integer> & |
| 136 | operator<<=(byte& __lhs, _Integer __shift) noexcept |
| 137 | { return __lhs = __lhs << __shift; } |
Marshall Clow | cade1f7 | 2017-03-24 05:45:39 +0000 | [diff] [blame] | 138 | |
Eric Fiselier | d2971c6 | 2020-02-14 17:34:46 +0100 | [diff] [blame] | 139 | template <class _Integer> |
| 140 | constexpr _EnableByteOverload<_Integer> |
| 141 | operator<< (byte __lhs, _Integer __shift) noexcept |
| 142 | { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); } |
| 143 | |
| 144 | template <class _Integer> |
| 145 | constexpr _EnableByteOverload<_Integer> & |
| 146 | operator>>=(byte& __lhs, _Integer __shift) noexcept |
| 147 | { return __lhs = __lhs >> __shift; } |
| 148 | |
| 149 | template <class _Integer> |
| 150 | constexpr _EnableByteOverload<_Integer> |
| 151 | operator>> (byte __lhs, _Integer __shift) noexcept |
| 152 | { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); } |
| 153 | |
| 154 | template <class _Integer, class = _EnableByteOverload<_Integer> > |
Arthur O'Dwyer | 108facb | 2021-04-05 14:56:03 -0400 | [diff] [blame] | 155 | _LIBCPP_NODISCARD_EXT constexpr _Integer |
Eric Fiselier | d2971c6 | 2020-02-14 17:34:46 +0100 | [diff] [blame] | 156 | to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); } |
Nikolas Klauser | cfa3156 | 2022-02-01 18:11:49 +0100 | [diff] [blame] | 157 | |
| 158 | } // namespace std |
Marshall Clow | cade1f7 | 2017-03-24 05:45:39 +0000 | [diff] [blame] | 159 | |
Marshall Clow | cade1f7 | 2017-03-24 05:45:39 +0000 | [diff] [blame] | 160 | #endif |
| 161 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 162 | #endif // _LIBCPP_CSTDDEF |