File indexing completed on 2026-05-03 08:13:17
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CSTDDEF_BYTE_H
0010 #define _LIBCPP___CSTDDEF_BYTE_H
0011
0012 #include <__config>
0013 #include <__fwd/byte.h>
0014 #include <__type_traits/enable_if.h>
0015 #include <__type_traits/is_integral.h>
0016
0017 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0018 # pragma GCC system_header
0019 #endif
0020
0021 #if _LIBCPP_STD_VER >= 17
0022 namespace std {
0023
0024 enum class byte : unsigned char {};
0025
0026 _LIBCPP_HIDE_FROM_ABI inline constexpr byte operator|(byte __lhs, byte __rhs) noexcept {
0027 return static_cast<byte>(
0028 static_cast<unsigned char>(static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs)));
0029 }
0030
0031 _LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept {
0032 return __lhs = __lhs | __rhs;
0033 }
0034
0035 _LIBCPP_HIDE_FROM_ABI inline constexpr byte operator&(byte __lhs, byte __rhs) noexcept {
0036 return static_cast<byte>(
0037 static_cast<unsigned char>(static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs)));
0038 }
0039
0040 _LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept {
0041 return __lhs = __lhs & __rhs;
0042 }
0043
0044 _LIBCPP_HIDE_FROM_ABI inline constexpr byte operator^(byte __lhs, byte __rhs) noexcept {
0045 return static_cast<byte>(
0046 static_cast<unsigned char>(static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs)));
0047 }
0048
0049 _LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept {
0050 return __lhs = __lhs ^ __rhs;
0051 }
0052
0053 _LIBCPP_HIDE_FROM_ABI inline constexpr byte operator~(byte __b) noexcept {
0054 return static_cast<byte>(static_cast<unsigned char>(~static_cast<unsigned int>(__b)));
0055 }
0056
0057 template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
0058 _LIBCPP_HIDE_FROM_ABI constexpr byte& operator<<=(byte& __lhs, _Integer __shift) noexcept {
0059 return __lhs = __lhs << __shift;
0060 }
0061
0062 template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
0063 _LIBCPP_HIDE_FROM_ABI constexpr byte operator<<(byte __lhs, _Integer __shift) noexcept {
0064 return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift));
0065 }
0066
0067 template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
0068 _LIBCPP_HIDE_FROM_ABI constexpr byte& operator>>=(byte& __lhs, _Integer __shift) noexcept {
0069 return __lhs = __lhs >> __shift;
0070 }
0071
0072 template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
0073 _LIBCPP_HIDE_FROM_ABI constexpr byte operator>>(byte __lhs, _Integer __shift) noexcept {
0074 return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift));
0075 }
0076
0077 template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
0078 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Integer to_integer(byte __b) noexcept {
0079 return static_cast<_Integer>(__b);
0080 }
0081
0082 }
0083 #endif
0084
0085 #endif