|
| 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___CSTDDEF_BYTE_H |
| 10 | +#define _LIBCPP___CSTDDEF_BYTE_H |
| 11 | + |
| 12 | +#include <__config> |
| 13 | +#include <__type_traits/enable_if.h> |
| 14 | +#include <__type_traits/is_integral.h> |
| 15 | + |
| 16 | +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 17 | +# pragma GCC system_header |
| 18 | +#endif |
| 19 | + |
| 20 | +#if _LIBCPP_STD_VER >= 17 |
| 21 | +namespace std { // purposefully not versioned |
| 22 | + |
| 23 | +enum class byte : unsigned char {}; |
| 24 | + |
| 25 | +_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator|(byte __lhs, byte __rhs) noexcept { |
| 26 | + return static_cast<byte>( |
| 27 | + static_cast<unsigned char>(static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs))); |
| 28 | +} |
| 29 | + |
| 30 | +_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept { |
| 31 | + return __lhs = __lhs | __rhs; |
| 32 | +} |
| 33 | + |
| 34 | +_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator&(byte __lhs, byte __rhs) noexcept { |
| 35 | + return static_cast<byte>( |
| 36 | + static_cast<unsigned char>(static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs))); |
| 37 | +} |
| 38 | + |
| 39 | +_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept { |
| 40 | + return __lhs = __lhs & __rhs; |
| 41 | +} |
| 42 | + |
| 43 | +_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator^(byte __lhs, byte __rhs) noexcept { |
| 44 | + return static_cast<byte>( |
| 45 | + static_cast<unsigned char>(static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs))); |
| 46 | +} |
| 47 | + |
| 48 | +_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept { |
| 49 | + return __lhs = __lhs ^ __rhs; |
| 50 | +} |
| 51 | + |
| 52 | +_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator~(byte __b) noexcept { |
| 53 | + return static_cast<byte>(static_cast<unsigned char>(~static_cast<unsigned int>(__b))); |
| 54 | +} |
| 55 | + |
| 56 | +template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0> |
| 57 | +_LIBCPP_HIDE_FROM_ABI constexpr byte& operator<<=(byte& __lhs, _Integer __shift) noexcept { |
| 58 | + return __lhs = __lhs << __shift; |
| 59 | +} |
| 60 | + |
| 61 | +template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0> |
| 62 | +_LIBCPP_HIDE_FROM_ABI constexpr byte operator<<(byte __lhs, _Integer __shift) noexcept { |
| 63 | + return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); |
| 64 | +} |
| 65 | + |
| 66 | +template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0> |
| 67 | +_LIBCPP_HIDE_FROM_ABI constexpr byte& operator>>=(byte& __lhs, _Integer __shift) noexcept { |
| 68 | + return __lhs = __lhs >> __shift; |
| 69 | +} |
| 70 | + |
| 71 | +template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0> |
| 72 | +_LIBCPP_HIDE_FROM_ABI constexpr byte operator>>(byte __lhs, _Integer __shift) noexcept { |
| 73 | + return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); |
| 74 | +} |
| 75 | + |
| 76 | +template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0> |
| 77 | +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Integer to_integer(byte __b) noexcept { |
| 78 | + return static_cast<_Integer>(__b); |
| 79 | +} |
| 80 | + |
| 81 | +} // namespace std |
| 82 | +#endif // _LIBCPP_STD_VER >= 17 |
| 83 | + |
| 84 | +#endif // _LIBCPP___CSTDDEF_BYTE_H |
0 commit comments