10b57cec5SDimitry Andric// -*- C++ -*- 2*349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_CSTDDEF 110b57cec5SDimitry Andric#define _LIBCPP_CSTDDEF 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric cstddef synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry AndricMacros: 170b57cec5SDimitry Andric 180b57cec5SDimitry Andric offsetof(type,member-designator) 190b57cec5SDimitry Andric NULL 200b57cec5SDimitry Andric 210b57cec5SDimitry Andricnamespace std 220b57cec5SDimitry Andric{ 230b57cec5SDimitry Andric 240b57cec5SDimitry AndricTypes: 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric ptrdiff_t 270b57cec5SDimitry Andric size_t 285ffd83dbSDimitry Andric max_align_t // C++11 290b57cec5SDimitry Andric nullptr_t 300b57cec5SDimitry Andric byte // C++17 310b57cec5SDimitry Andric 320b57cec5SDimitry Andric} // std 330b57cec5SDimitry Andric 340b57cec5SDimitry Andric*/ 350b57cec5SDimitry Andric 360b57cec5SDimitry Andric#include <__config> 370b57cec5SDimitry Andric#include <version> 380b57cec5SDimitry Andric 390b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 400b57cec5SDimitry Andric#pragma GCC system_header 410b57cec5SDimitry Andric#endif 420b57cec5SDimitry Andric 430b57cec5SDimitry Andric// Don't include our own <stddef.h>; we don't want to declare ::nullptr_t. 440b57cec5SDimitry Andric#include_next <stddef.h> 450b57cec5SDimitry Andric#include <__nullptr> 460b57cec5SDimitry Andric 470b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 480b57cec5SDimitry Andric 49fe6060f1SDimitry Andricusing ::ptrdiff_t _LIBCPP_USING_IF_EXISTS; 50fe6060f1SDimitry Andricusing ::size_t _LIBCPP_USING_IF_EXISTS; 510b57cec5SDimitry Andric 525ffd83dbSDimitry Andric#if !defined(_LIBCPP_CXX03_LANG) 53fe6060f1SDimitry Andricusing ::max_align_t _LIBCPP_USING_IF_EXISTS; 545ffd83dbSDimitry Andric#endif 555ffd83dbSDimitry Andric 565ffd83dbSDimitry Andrictemplate <class _Tp> struct __libcpp_is_integral { enum { value = 0 }; }; 575ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<bool> { enum { value = 1 }; }; 585ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<char> { enum { value = 1 }; }; 595ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<signed char> { enum { value = 1 }; }; 605ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<unsigned char> { enum { value = 1 }; }; 61*349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 625ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<wchar_t> { enum { value = 1 }; }; 63*349cc55cSDimitry Andric#endif 64fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T 655ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<char8_t> { enum { value = 1 }; }; 665ffd83dbSDimitry Andric#endif 675ffd83dbSDimitry Andric#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 685ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<char16_t> { enum { value = 1 }; }; 695ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<char32_t> { enum { value = 1 }; }; 70*349cc55cSDimitry Andric#endif 715ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<short> { enum { value = 1 }; }; 725ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<unsigned short> { enum { value = 1 }; }; 735ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<int> { enum { value = 1 }; }; 745ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<unsigned int> { enum { value = 1 }; }; 755ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<long> { enum { value = 1 }; }; 765ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<unsigned long> { enum { value = 1 }; }; 775ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<long long> { enum { value = 1 }; }; 785ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<unsigned long long> { enum { value = 1 }; }; 795ffd83dbSDimitry Andric#ifndef _LIBCPP_HAS_NO_INT128 805ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<__int128_t> { enum { value = 1 }; }; 815ffd83dbSDimitry Andrictemplate <> struct __libcpp_is_integral<__uint128_t> { enum { value = 1 }; }; 820b57cec5SDimitry Andric#endif 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 850b57cec5SDimitry Andric 860b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 870b57cec5SDimitry Andricnamespace std // purposefully not versioned 880b57cec5SDimitry Andric{ 890b57cec5SDimitry Andricenum class byte : unsigned char {}; 900b57cec5SDimitry Andric 915ffd83dbSDimitry Andric 925ffd83dbSDimitry Andrictemplate <bool> struct __enable_if_integral_imp {}; 935ffd83dbSDimitry Andrictemplate <> struct __enable_if_integral_imp<true> { using type = byte; }; 945ffd83dbSDimitry Andrictemplate <class _Tp> using _EnableByteOverload = typename __enable_if_integral_imp<__libcpp_is_integral<_Tp>::value>::type; 955ffd83dbSDimitry Andric 960b57cec5SDimitry Andricconstexpr byte operator| (byte __lhs, byte __rhs) noexcept 970b57cec5SDimitry Andric{ 980b57cec5SDimitry Andric return static_cast<byte>( 990b57cec5SDimitry Andric static_cast<unsigned char>( 1000b57cec5SDimitry Andric static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs) 1010b57cec5SDimitry Andric )); 1020b57cec5SDimitry Andric} 1030b57cec5SDimitry Andric 1040b57cec5SDimitry Andricconstexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept 1050b57cec5SDimitry Andric{ return __lhs = __lhs | __rhs; } 1060b57cec5SDimitry Andric 1070b57cec5SDimitry Andricconstexpr byte operator& (byte __lhs, byte __rhs) noexcept 1080b57cec5SDimitry Andric{ 1090b57cec5SDimitry Andric return static_cast<byte>( 1100b57cec5SDimitry Andric static_cast<unsigned char>( 1110b57cec5SDimitry Andric static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs) 1120b57cec5SDimitry Andric )); 1130b57cec5SDimitry Andric} 1140b57cec5SDimitry Andric 1150b57cec5SDimitry Andricconstexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept 1160b57cec5SDimitry Andric{ return __lhs = __lhs & __rhs; } 1170b57cec5SDimitry Andric 1180b57cec5SDimitry Andricconstexpr byte operator^ (byte __lhs, byte __rhs) noexcept 1190b57cec5SDimitry Andric{ 1200b57cec5SDimitry Andric return static_cast<byte>( 1210b57cec5SDimitry Andric static_cast<unsigned char>( 1220b57cec5SDimitry Andric static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs) 1230b57cec5SDimitry Andric )); 1240b57cec5SDimitry Andric} 1250b57cec5SDimitry Andric 1260b57cec5SDimitry Andricconstexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept 1270b57cec5SDimitry Andric{ return __lhs = __lhs ^ __rhs; } 1280b57cec5SDimitry Andric 1290b57cec5SDimitry Andricconstexpr byte operator~ (byte __b) noexcept 1300b57cec5SDimitry Andric{ 1310b57cec5SDimitry Andric return static_cast<byte>( 1320b57cec5SDimitry Andric static_cast<unsigned char>( 1330b57cec5SDimitry Andric ~static_cast<unsigned int>(__b) 1340b57cec5SDimitry Andric )); 1350b57cec5SDimitry Andric} 1365ffd83dbSDimitry Andrictemplate <class _Integer> 1375ffd83dbSDimitry Andric constexpr _EnableByteOverload<_Integer> & 1385ffd83dbSDimitry Andric operator<<=(byte& __lhs, _Integer __shift) noexcept 1395ffd83dbSDimitry Andric { return __lhs = __lhs << __shift; } 1400b57cec5SDimitry Andric 1415ffd83dbSDimitry Andrictemplate <class _Integer> 1425ffd83dbSDimitry Andric constexpr _EnableByteOverload<_Integer> 1435ffd83dbSDimitry Andric operator<< (byte __lhs, _Integer __shift) noexcept 1445ffd83dbSDimitry Andric { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); } 1455ffd83dbSDimitry Andric 1465ffd83dbSDimitry Andrictemplate <class _Integer> 1475ffd83dbSDimitry Andric constexpr _EnableByteOverload<_Integer> & 1485ffd83dbSDimitry Andric operator>>=(byte& __lhs, _Integer __shift) noexcept 1495ffd83dbSDimitry Andric { return __lhs = __lhs >> __shift; } 1505ffd83dbSDimitry Andric 1515ffd83dbSDimitry Andrictemplate <class _Integer> 1525ffd83dbSDimitry Andric constexpr _EnableByteOverload<_Integer> 1535ffd83dbSDimitry Andric operator>> (byte __lhs, _Integer __shift) noexcept 1545ffd83dbSDimitry Andric { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); } 1555ffd83dbSDimitry Andric 1565ffd83dbSDimitry Andrictemplate <class _Integer, class = _EnableByteOverload<_Integer> > 157fe6060f1SDimitry Andric _LIBCPP_NODISCARD_EXT constexpr _Integer 1585ffd83dbSDimitry Andric to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); } 1590b57cec5SDimitry Andric} 1600b57cec5SDimitry Andric 1610b57cec5SDimitry Andric#endif 1620b57cec5SDimitry Andric 1630b57cec5SDimitry Andric#endif // _LIBCPP_CSTDDEF 164