13e519524SHoward Hinnant// -*- C++ -*- 2eb8650a7SLouis Dionne//===----------------------------------------------------------------------===// 33e519524SHoward Hinnant// 457b08b09SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 557b08b09SChandler Carruth// See https://llvm.org/LICENSE.txt for license information. 657b08b09SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 73e519524SHoward Hinnant// 83e519524SHoward Hinnant//===----------------------------------------------------------------------===// 93e519524SHoward Hinnant 103e519524SHoward Hinnant#ifndef _LIBCPP_CSTDDEF 113e519524SHoward Hinnant#define _LIBCPP_CSTDDEF 123e519524SHoward Hinnant 133e519524SHoward Hinnant/* 143e519524SHoward Hinnant cstddef synopsis 153e519524SHoward Hinnant 163e519524SHoward HinnantMacros: 173e519524SHoward Hinnant 183e519524SHoward Hinnant offsetof(type,member-designator) 193e519524SHoward Hinnant NULL 203e519524SHoward Hinnant 213e519524SHoward Hinnantnamespace std 223e519524SHoward Hinnant{ 233e519524SHoward Hinnant 243e519524SHoward HinnantTypes: 253e519524SHoward Hinnant 263e519524SHoward Hinnant ptrdiff_t 273e519524SHoward Hinnant size_t 2898f77828SJoerg Sonnenberger max_align_t // C++11 293e519524SHoward Hinnant nullptr_t 30c97d8aa8SMarshall Clow byte // C++17 313e519524SHoward Hinnant 323e519524SHoward Hinnant} // std 333e519524SHoward Hinnant 343e519524SHoward Hinnant*/ 353e519524SHoward Hinnant 36385cc25aSLouis Dionne#include <__assert> // all public C++ headers provide the assertion handler 373e519524SHoward Hinnant#include <__config> 38*7e69bd9bSNikolas Klauser#include <__type_traits/enable_if.h> 39*7e69bd9bSNikolas Klauser#include <__type_traits/integral_constant.h> 40eebc1fb7SNikolas Klauser#include <__type_traits/is_integral.h> 41157bbe6aSLouis Dionne#include <stddef.h> 42f56972e2SMarshall Clow#include <version> 438ae5097fSHoward Hinnant 44073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 453e519524SHoward Hinnant# pragma GCC system_header 46073458b1SHoward Hinnant#endif 473e519524SHoward Hinnant 483e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD 493e519524SHoward Hinnant 50157bbe6aSLouis Dionneusing ::nullptr_t; 51a9c9183cSLouis Dionneusing ::ptrdiff_t _LIBCPP_USING_IF_EXISTS; 52a9c9183cSLouis Dionneusing ::size_t _LIBCPP_USING_IF_EXISTS; 533e519524SHoward Hinnant 5498f77828SJoerg Sonnenberger#if !defined(_LIBCPP_CXX03_LANG) 55a9c9183cSLouis Dionneusing ::max_align_t _LIBCPP_USING_IF_EXISTS; 56265b83a8SChandler Carruth#endif 573e519524SHoward Hinnant 583e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD 593e519524SHoward Hinnant 60c97d8aa8SMarshall Clow#if _LIBCPP_STD_VER > 14 61c97d8aa8SMarshall Clownamespace std // purposefully not versioned 62c97d8aa8SMarshall Clow{ 63c97d8aa8SMarshall Clowenum class byte : unsigned char {}; 64c97d8aa8SMarshall Clow 65c97d8aa8SMarshall Clowconstexpr byte operator| (byte __lhs, byte __rhs) noexcept 6612de6e9cSMarshall Clow{ 6712de6e9cSMarshall Clow return static_cast<byte>( 6812de6e9cSMarshall Clow static_cast<unsigned char>( 6912de6e9cSMarshall Clow static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs) 7012de6e9cSMarshall Clow )); 7112de6e9cSMarshall Clow} 7212de6e9cSMarshall Clow 7312de6e9cSMarshall Clowconstexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept 7412de6e9cSMarshall Clow{ return __lhs = __lhs | __rhs; } 7512de6e9cSMarshall Clow 7612de6e9cSMarshall Clowconstexpr byte operator& (byte __lhs, byte __rhs) noexcept 7712de6e9cSMarshall Clow{ 7812de6e9cSMarshall Clow return static_cast<byte>( 7912de6e9cSMarshall Clow static_cast<unsigned char>( 8012de6e9cSMarshall Clow static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs) 8112de6e9cSMarshall Clow )); 8212de6e9cSMarshall Clow} 83c97d8aa8SMarshall Clow 84c97d8aa8SMarshall Clowconstexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept 8512de6e9cSMarshall Clow{ return __lhs = __lhs & __rhs; } 8612de6e9cSMarshall Clow 8712de6e9cSMarshall Clowconstexpr byte operator^ (byte __lhs, byte __rhs) noexcept 8812de6e9cSMarshall Clow{ 8912de6e9cSMarshall Clow return static_cast<byte>( 9012de6e9cSMarshall Clow static_cast<unsigned char>( 9112de6e9cSMarshall Clow static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs) 9212de6e9cSMarshall Clow )); 9312de6e9cSMarshall Clow} 94c97d8aa8SMarshall Clow 95c97d8aa8SMarshall Clowconstexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept 9612de6e9cSMarshall Clow{ return __lhs = __lhs ^ __rhs; } 97c97d8aa8SMarshall Clow 98c97d8aa8SMarshall Clowconstexpr byte operator~ (byte __b) noexcept 9912de6e9cSMarshall Clow{ 10012de6e9cSMarshall Clow return static_cast<byte>( 10112de6e9cSMarshall Clow static_cast<unsigned char>( 10212de6e9cSMarshall Clow ~static_cast<unsigned int>(__b) 10312de6e9cSMarshall Clow )); 10412de6e9cSMarshall Clow} 105*7e69bd9bSNikolas Klauser 106*7e69bd9bSNikolas Klausertemplate <class _Tp> 107*7e69bd9bSNikolas Klauserusing _EnableByteOverload = __enable_if_t<is_integral<_Tp>::value, byte>; 108*7e69bd9bSNikolas Klauser 109cccf1ef0SEric Fiseliertemplate <class _Integer> 110cccf1ef0SEric Fiselier constexpr _EnableByteOverload<_Integer> & 111cccf1ef0SEric Fiselier operator<<=(byte& __lhs, _Integer __shift) noexcept 112cccf1ef0SEric Fiselier { return __lhs = __lhs << __shift; } 113c97d8aa8SMarshall Clow 114cccf1ef0SEric Fiseliertemplate <class _Integer> 115cccf1ef0SEric Fiselier constexpr _EnableByteOverload<_Integer> 116cccf1ef0SEric Fiselier operator<< (byte __lhs, _Integer __shift) noexcept 117cccf1ef0SEric Fiselier { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); } 118cccf1ef0SEric Fiselier 119cccf1ef0SEric Fiseliertemplate <class _Integer> 120cccf1ef0SEric Fiselier constexpr _EnableByteOverload<_Integer> & 121cccf1ef0SEric Fiselier operator>>=(byte& __lhs, _Integer __shift) noexcept 122cccf1ef0SEric Fiselier { return __lhs = __lhs >> __shift; } 123cccf1ef0SEric Fiselier 124cccf1ef0SEric Fiseliertemplate <class _Integer> 125cccf1ef0SEric Fiselier constexpr _EnableByteOverload<_Integer> 126cccf1ef0SEric Fiselier operator>> (byte __lhs, _Integer __shift) noexcept 127cccf1ef0SEric Fiselier { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); } 128cccf1ef0SEric Fiselier 129cccf1ef0SEric Fiseliertemplate <class _Integer, class = _EnableByteOverload<_Integer> > 1304b7bad9eSArthur O'Dwyer _LIBCPP_NODISCARD_EXT constexpr _Integer 131cccf1ef0SEric Fiselier to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); } 1329c52a19eSNikolas Klauser 1339c52a19eSNikolas Klauser} // namespace std 134c97d8aa8SMarshall Clow 135c97d8aa8SMarshall Clow#endif 136c97d8aa8SMarshall Clow 1373e519524SHoward Hinnant#endif // _LIBCPP_CSTDDEF 138