| 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 <__assert> // all public C++ headers provide the assertion handler |
| 37 | #include <__config> |
| 38 | #include <__type_traits/enable_if.h> |
| 39 | #include <__type_traits/integral_constant.h> |
| 40 | #include <__type_traits/is_integral.h> |
| 41 | #include <stddef.h> |
| 42 | #include <version> |
| 43 | |
| 44 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 45 | # pragma GCC system_header |
| 46 | #endif |
| 47 | |
| 48 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 49 | |
| 50 | using ::nullptr_t; |
| 51 | using ::ptrdiff_t _LIBCPP_USING_IF_EXISTS; |
| 52 | using ::size_t _LIBCPP_USING_IF_EXISTS; |
| 53 | |
| 54 | #if !defined(_LIBCPP_CXX03_LANG) |
| 55 | using ::max_align_t _LIBCPP_USING_IF_EXISTS; |
| 56 | #endif |
| 57 | |
| 58 | _LIBCPP_END_NAMESPACE_STD |
| 59 | |
| 60 | #if _LIBCPP_STD_VER > 14 |
| 61 | namespace std // purposefully not versioned |
| 62 | { |
| 63 | enum class byte : unsigned char {}; |
| 64 | |
| 65 | constexpr byte operator| (byte __lhs, byte __rhs) noexcept |
| 66 | { |
| 67 | return static_cast<byte>( |
| 68 | static_cast<unsigned char>( |
| 69 | static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs) |
| 70 | )); |
| 71 | } |
| 72 | |
| 73 | constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept |
| 74 | { return __lhs = __lhs | __rhs; } |
| 75 | |
| 76 | constexpr byte operator& (byte __lhs, byte __rhs) noexcept |
| 77 | { |
| 78 | return static_cast<byte>( |
| 79 | static_cast<unsigned char>( |
| 80 | static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs) |
| 81 | )); |
| 82 | } |
| 83 | |
| 84 | constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept |
| 85 | { return __lhs = __lhs & __rhs; } |
| 86 | |
| 87 | constexpr byte operator^ (byte __lhs, byte __rhs) noexcept |
| 88 | { |
| 89 | return static_cast<byte>( |
| 90 | static_cast<unsigned char>( |
| 91 | static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs) |
| 92 | )); |
| 93 | } |
| 94 | |
| 95 | constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept |
| 96 | { return __lhs = __lhs ^ __rhs; } |
| 97 | |
| 98 | constexpr byte operator~ (byte __b) noexcept |
| 99 | { |
| 100 | return static_cast<byte>( |
| 101 | static_cast<unsigned char>( |
| 102 | ~static_cast<unsigned int>(__b) |
| 103 | )); |
| 104 | } |
| 105 | |
| 106 | template <class _Tp> |
| 107 | using _EnableByteOverload = __enable_if_t<is_integral<_Tp>::value, byte>; |
| 108 | |
| 109 | template <class _Integer> |
| 110 | constexpr _EnableByteOverload<_Integer> & |
| 111 | operator<<=(byte& __lhs, _Integer __shift) noexcept |
| 112 | { return __lhs = __lhs << __shift; } |
| 113 | |
| 114 | template <class _Integer> |
| 115 | constexpr _EnableByteOverload<_Integer> |
| 116 | operator<< (byte __lhs, _Integer __shift) noexcept |
| 117 | { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); } |
| 118 | |
| 119 | template <class _Integer> |
| 120 | constexpr _EnableByteOverload<_Integer> & |
| 121 | operator>>=(byte& __lhs, _Integer __shift) noexcept |
| 122 | { return __lhs = __lhs >> __shift; } |
| 123 | |
| 124 | template <class _Integer> |
| 125 | constexpr _EnableByteOverload<_Integer> |
| 126 | (byte __lhs, _Integer __shift) noexcept |
| 127 | { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); } |
| 128 | |
| 129 | template <class _Integer, class = _EnableByteOverload<_Integer> > |
| 130 | _LIBCPP_NODISCARD_EXT constexpr _Integer |
| 131 | to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); } |
| 132 | |
| 133 | } // namespace std |
| 134 | |
| 135 | #endif |
| 136 | |
| 137 | #endif // _LIBCPP_CSTDDEF |
| 138 | |