Path: blob/main/contrib/llvm-project/libc/src/__support/CPP/cstddef.h
213799 views
//===-- A self contained equivalent of cstddef ------------------*- C++ -*-===//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 LLVM_LIBC_SRC___SUPPORT_CPP_CSTDDEF_H9#define LLVM_LIBC_SRC___SUPPORT_CPP_CSTDDEF_H1011#include "src/__support/macros/attributes.h"12#include "src/__support/macros/config.h"13#include "type_traits.h" // For enable_if_t, is_integral_v.1415namespace LIBC_NAMESPACE_DECL {16namespace cpp {1718enum class byte : unsigned char {};1920template <class IntegerType>21LIBC_INLINE constexpr enable_if_t<is_integral_v<IntegerType>, byte>22operator>>(byte b, IntegerType shift) noexcept {23return static_cast<byte>(static_cast<unsigned char>(b) >> shift);24}25template <class IntegerType>26LIBC_INLINE constexpr enable_if_t<is_integral_v<IntegerType>, byte &>27operator>>=(byte &b, IntegerType shift) noexcept {28return b = b >> shift;29}30template <class IntegerType>31LIBC_INLINE constexpr enable_if_t<is_integral_v<IntegerType>, byte>32operator<<(byte b, IntegerType shift) noexcept {33return static_cast<byte>(static_cast<unsigned char>(b) << shift);34}35template <class IntegerType>36LIBC_INLINE constexpr enable_if_t<is_integral_v<IntegerType>, byte &>37operator<<=(byte &b, IntegerType shift) noexcept {38return b = b << shift;39}40LIBC_INLINE constexpr byte operator|(byte l, byte r) noexcept {41return static_cast<byte>(static_cast<unsigned char>(l) |42static_cast<unsigned char>(r));43}44LIBC_INLINE constexpr byte &operator|=(byte &l, byte r) noexcept {45return l = l | r;46}47LIBC_INLINE constexpr byte operator&(byte l, byte r) noexcept {48return static_cast<byte>(static_cast<unsigned char>(l) &49static_cast<unsigned char>(r));50}51LIBC_INLINE constexpr byte &operator&=(byte &l, byte r) noexcept {52return l = l & r;53}54LIBC_INLINE constexpr byte operator^(byte l, byte r) noexcept {55return static_cast<byte>(static_cast<unsigned char>(l) ^56static_cast<unsigned char>(r));57}58LIBC_INLINE constexpr byte &operator^=(byte &l, byte r) noexcept {59return l = l ^ r;60}61LIBC_INLINE constexpr byte operator~(byte b) noexcept {62return static_cast<byte>(~static_cast<unsigned char>(b));63}64template <typename IntegerType>65LIBC_INLINE constexpr enable_if_t<is_integral_v<IntegerType>, IntegerType>66to_integer(byte b) noexcept {67return static_cast<IntegerType>(b);68}6970} // namespace cpp71} // namespace LIBC_NAMESPACE_DECL7273#endif // LLVM_LIBC_SRC___SUPPORT_CPP_CSTDDEF_H747576