Path: blob/main/contrib/llvm-project/libcxx/include/__cstddef/byte.h
213766 views
//===---------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===---------------------------------------------------------------------===//78#ifndef _LIBCPP___CSTDDEF_BYTE_H9#define _LIBCPP___CSTDDEF_BYTE_H1011#include <__config>12#include <__fwd/byte.h>13#include <__type_traits/enable_if.h>14#include <__type_traits/is_integral.h>1516#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)17# pragma GCC system_header18#endif1920#if _LIBCPP_STD_VER >= 1721_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD2223enum class byte : unsigned char {};2425_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator|(byte __lhs, byte __rhs) noexcept {26return static_cast<byte>(27static_cast<unsigned char>(static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs)));28}2930_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept {31return __lhs = __lhs | __rhs;32}3334_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator&(byte __lhs, byte __rhs) noexcept {35return static_cast<byte>(36static_cast<unsigned char>(static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs)));37}3839_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept {40return __lhs = __lhs & __rhs;41}4243_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator^(byte __lhs, byte __rhs) noexcept {44return static_cast<byte>(45static_cast<unsigned char>(static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs)));46}4748_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept {49return __lhs = __lhs ^ __rhs;50}5152_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator~(byte __b) noexcept {53return static_cast<byte>(static_cast<unsigned char>(~static_cast<unsigned int>(__b)));54}5556template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>57_LIBCPP_HIDE_FROM_ABI constexpr byte& operator<<=(byte& __lhs, _Integer __shift) noexcept {58return __lhs = __lhs << __shift;59}6061template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>62_LIBCPP_HIDE_FROM_ABI constexpr byte operator<<(byte __lhs, _Integer __shift) noexcept {63return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift));64}6566template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>67_LIBCPP_HIDE_FROM_ABI constexpr byte& operator>>=(byte& __lhs, _Integer __shift) noexcept {68return __lhs = __lhs >> __shift;69}7071template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>72_LIBCPP_HIDE_FROM_ABI constexpr byte operator>>(byte __lhs, _Integer __shift) noexcept {73return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift));74}7576template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>77[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Integer to_integer(byte __b) noexcept {78return static_cast<_Integer>(__b);79}8081_LIBCPP_END_UNVERSIONED_NAMESPACE_STD82#endif // _LIBCPP_STD_VER >= 178384#endif // _LIBCPP___CSTDDEF_BYTE_H858687