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 <stddef.h> 39#include <version> 40 41#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 42# pragma GCC system_header 43#endif 44 45_LIBCPP_BEGIN_NAMESPACE_STD 46 47using ::nullptr_t; 48using ::ptrdiff_t _LIBCPP_USING_IF_EXISTS; 49using ::size_t _LIBCPP_USING_IF_EXISTS; 50 51#if !defined(_LIBCPP_CXX03_LANG) 52using ::max_align_t _LIBCPP_USING_IF_EXISTS; 53#endif 54 55template <class _Tp> struct __libcpp_is_integral { enum { value = 0 }; }; 56template <> struct __libcpp_is_integral<bool> { enum { value = 1 }; }; 57template <> struct __libcpp_is_integral<char> { enum { value = 1 }; }; 58template <> struct __libcpp_is_integral<signed char> { enum { value = 1 }; }; 59template <> struct __libcpp_is_integral<unsigned char> { enum { value = 1 }; }; 60#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 61template <> struct __libcpp_is_integral<wchar_t> { enum { value = 1 }; }; 62#endif 63#ifndef _LIBCPP_HAS_NO_CHAR8_T 64template <> struct __libcpp_is_integral<char8_t> { enum { value = 1 }; }; 65#endif 66#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 67template <> struct __libcpp_is_integral<char16_t> { enum { value = 1 }; }; 68template <> struct __libcpp_is_integral<char32_t> { enum { value = 1 }; }; 69#endif 70template <> struct __libcpp_is_integral<short> { enum { value = 1 }; }; 71template <> struct __libcpp_is_integral<unsigned short> { enum { value = 1 }; }; 72template <> struct __libcpp_is_integral<int> { enum { value = 1 }; }; 73template <> struct __libcpp_is_integral<unsigned int> { enum { value = 1 }; }; 74template <> struct __libcpp_is_integral<long> { enum { value = 1 }; }; 75template <> struct __libcpp_is_integral<unsigned long> { enum { value = 1 }; }; 76template <> struct __libcpp_is_integral<long long> { enum { value = 1 }; }; 77template <> struct __libcpp_is_integral<unsigned long long> { enum { value = 1 }; }; 78#ifndef _LIBCPP_HAS_NO_INT128 79template <> struct __libcpp_is_integral<__int128_t> { enum { value = 1 }; }; 80template <> struct __libcpp_is_integral<__uint128_t> { enum { value = 1 }; }; 81#endif 82 83_LIBCPP_END_NAMESPACE_STD 84 85#if _LIBCPP_STD_VER > 14 86namespace std // purposefully not versioned 87{ 88enum class byte : unsigned char {}; 89 90 91template <bool> struct __enable_if_integral_imp {}; 92template <> struct __enable_if_integral_imp<true> { using type = byte; }; 93template <class _Tp> using _EnableByteOverload = typename __enable_if_integral_imp<__libcpp_is_integral<_Tp>::value>::type; 94 95constexpr byte operator| (byte __lhs, byte __rhs) noexcept 96{ 97 return static_cast<byte>( 98 static_cast<unsigned char>( 99 static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs) 100 )); 101} 102 103constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept 104{ return __lhs = __lhs | __rhs; } 105 106constexpr byte operator& (byte __lhs, byte __rhs) noexcept 107{ 108 return static_cast<byte>( 109 static_cast<unsigned char>( 110 static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs) 111 )); 112} 113 114constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept 115{ return __lhs = __lhs & __rhs; } 116 117constexpr byte operator^ (byte __lhs, byte __rhs) noexcept 118{ 119 return static_cast<byte>( 120 static_cast<unsigned char>( 121 static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs) 122 )); 123} 124 125constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept 126{ return __lhs = __lhs ^ __rhs; } 127 128constexpr byte operator~ (byte __b) noexcept 129{ 130 return static_cast<byte>( 131 static_cast<unsigned char>( 132 ~static_cast<unsigned int>(__b) 133 )); 134} 135template <class _Integer> 136 constexpr _EnableByteOverload<_Integer> & 137 operator<<=(byte& __lhs, _Integer __shift) noexcept 138 { return __lhs = __lhs << __shift; } 139 140template <class _Integer> 141 constexpr _EnableByteOverload<_Integer> 142 operator<< (byte __lhs, _Integer __shift) noexcept 143 { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); } 144 145template <class _Integer> 146 constexpr _EnableByteOverload<_Integer> & 147 operator>>=(byte& __lhs, _Integer __shift) noexcept 148 { return __lhs = __lhs >> __shift; } 149 150template <class _Integer> 151 constexpr _EnableByteOverload<_Integer> 152 operator>> (byte __lhs, _Integer __shift) noexcept 153 { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); } 154 155template <class _Integer, class = _EnableByteOverload<_Integer> > 156 _LIBCPP_NODISCARD_EXT constexpr _Integer 157 to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); } 158 159} // namespace std 160 161#endif 162 163#endif // _LIBCPP_CSTDDEF 164