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