Pirama Arumuga Nainar | d285ad0 | 2022-02-08 09:26:56 -0800 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 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 |
| 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 |
| 20 | |
| 21 | namespace std |
| 22 | { |
| 23 | |
| 24 | Types: |
| 25 | |
| 26 | ptrdiff_t |
| 27 | size_t |
| 28 | max_align_t // C++11 |
| 29 | nullptr_t |
| 30 | byte // C++17 |
| 31 | |
| 32 | } // std |
| 33 | |
| 34 | */ |
| 35 | |
| 36 | #include <__config> |
| 37 | #include <version> |
| 38 | |
| 39 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 40 | #pragma GCC system_header |
| 41 | #endif |
| 42 | |
| 43 | // Don't include our own <stddef.h>; we don't want to declare ::nullptr_t. |
| 44 | #include_next <stddef.h> |
| 45 | #include <__nullptr> |
| 46 | |
| 47 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 48 | |
| 49 | using ::ptrdiff_t _LIBCPP_USING_IF_EXISTS; |
| 50 | using ::size_t _LIBCPP_USING_IF_EXISTS; |
| 51 | |
| 52 | #if !defined(_LIBCPP_CXX03_LANG) |
| 53 | using ::max_align_t _LIBCPP_USING_IF_EXISTS; |
| 54 | #endif |
| 55 | |
| 56 | template <class _Tp> struct __libcpp_is_integral { enum { value = 0 }; }; |
| 57 | template <> struct __libcpp_is_integral<bool> { enum { value = 1 }; }; |
| 58 | template <> struct __libcpp_is_integral<char> { enum { value = 1 }; }; |
| 59 | template <> struct __libcpp_is_integral<signed char> { enum { value = 1 }; }; |
| 60 | template <> struct __libcpp_is_integral<unsigned char> { enum { value = 1 }; }; |
| 61 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 62 | template <> struct __libcpp_is_integral<wchar_t> { enum { value = 1 }; }; |
| 63 | #endif |
| 64 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
| 65 | template <> struct __libcpp_is_integral<char8_t> { enum { value = 1 }; }; |
| 66 | #endif |
| 67 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
| 68 | template <> struct __libcpp_is_integral<char16_t> { enum { value = 1 }; }; |
| 69 | template <> struct __libcpp_is_integral<char32_t> { enum { value = 1 }; }; |
| 70 | #endif |
| 71 | template <> struct __libcpp_is_integral<short> { enum { value = 1 }; }; |
| 72 | template <> struct __libcpp_is_integral<unsigned short> { enum { value = 1 }; }; |
| 73 | template <> struct __libcpp_is_integral<int> { enum { value = 1 }; }; |
| 74 | template <> struct __libcpp_is_integral<unsigned int> { enum { value = 1 }; }; |
| 75 | template <> struct __libcpp_is_integral<long> { enum { value = 1 }; }; |
| 76 | template <> struct __libcpp_is_integral<unsigned long> { enum { value = 1 }; }; |
| 77 | template <> struct __libcpp_is_integral<long long> { enum { value = 1 }; }; |
| 78 | template <> struct __libcpp_is_integral<unsigned long long> { enum { value = 1 }; }; |
| 79 | #ifndef _LIBCPP_HAS_NO_INT128 |
| 80 | template <> struct __libcpp_is_integral<__int128_t> { enum { value = 1 }; }; |
| 81 | template <> struct __libcpp_is_integral<__uint128_t> { enum { value = 1 }; }; |
| 82 | #endif |
| 83 | |
| 84 | _LIBCPP_END_NAMESPACE_STD |
| 85 | |
| 86 | #if _LIBCPP_STD_VER > 14 |
| 87 | namespace std // purposefully not versioned |
| 88 | { |
| 89 | enum class byte : unsigned char {}; |
| 90 | |
| 91 | |
| 92 | template <bool> struct __enable_if_integral_imp {}; |
| 93 | template <> struct __enable_if_integral_imp<true> { using type = byte; }; |
| 94 | template <class _Tp> using _EnableByteOverload = typename __enable_if_integral_imp<__libcpp_is_integral<_Tp>::value>::type; |
| 95 | |
| 96 | constexpr byte operator| (byte __lhs, byte __rhs) noexcept |
| 97 | { |
| 98 | return static_cast<byte>( |
| 99 | static_cast<unsigned char>( |
| 100 | static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs) |
| 101 | )); |
| 102 | } |
| 103 | |
| 104 | constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept |
| 105 | { return __lhs = __lhs | __rhs; } |
| 106 | |
| 107 | constexpr byte operator& (byte __lhs, byte __rhs) noexcept |
| 108 | { |
| 109 | return static_cast<byte>( |
| 110 | static_cast<unsigned char>( |
| 111 | static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs) |
| 112 | )); |
| 113 | } |
| 114 | |
| 115 | constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept |
| 116 | { return __lhs = __lhs & __rhs; } |
| 117 | |
| 118 | constexpr byte operator^ (byte __lhs, byte __rhs) noexcept |
| 119 | { |
| 120 | return static_cast<byte>( |
| 121 | static_cast<unsigned char>( |
| 122 | static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs) |
| 123 | )); |
| 124 | } |
| 125 | |
| 126 | constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept |
| 127 | { return __lhs = __lhs ^ __rhs; } |
| 128 | |
| 129 | constexpr byte operator~ (byte __b) noexcept |
| 130 | { |
| 131 | return static_cast<byte>( |
| 132 | static_cast<unsigned char>( |
| 133 | ~static_cast<unsigned int>(__b) |
| 134 | )); |
| 135 | } |
| 136 | template <class _Integer> |
| 137 | constexpr _EnableByteOverload<_Integer> & |
| 138 | operator<<=(byte& __lhs, _Integer __shift) noexcept |
| 139 | { return __lhs = __lhs << __shift; } |
| 140 | |
| 141 | template <class _Integer> |
| 142 | constexpr _EnableByteOverload<_Integer> |
| 143 | operator<< (byte __lhs, _Integer __shift) noexcept |
| 144 | { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); } |
| 145 | |
| 146 | template <class _Integer> |
| 147 | constexpr _EnableByteOverload<_Integer> & |
| 148 | operator>>=(byte& __lhs, _Integer __shift) noexcept |
| 149 | { return __lhs = __lhs >> __shift; } |
| 150 | |
| 151 | template <class _Integer> |
| 152 | constexpr _EnableByteOverload<_Integer> |
| 153 | operator>> (byte __lhs, _Integer __shift) noexcept |
| 154 | { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); } |
| 155 | |
| 156 | template <class _Integer, class = _EnableByteOverload<_Integer> > |
| 157 | _LIBCPP_NODISCARD_EXT constexpr _Integer |
| 158 | to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); } |
| 159 | } |
| 160 | |
| 161 | #endif |
| 162 | |
| 163 | #endif // _LIBCPP_CSTDDEF |