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/enable_if.h>
39#include <__type_traits/integral_constant.h>
40#include <__type_traits/is_integral.h>
41#include <version>
42
43#include <stddef.h>
44
45#ifndef _LIBCPP_STDDEF_H
46#   error <cstddef> tried including <stddef.h> but didn't find libc++'s <stddef.h> header. \
47          This usually means that your header search paths are not configured properly. \
48          The header search paths should contain the C++ Standard Library headers before \
49          any C Standard Library, and you are probably using compiler flags that make that \
50          not be the case.
51#endif
52
53#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
54#  pragma GCC system_header
55#endif
56
57_LIBCPP_BEGIN_NAMESPACE_STD
58
59using ::nullptr_t;
60using ::ptrdiff_t _LIBCPP_USING_IF_EXISTS;
61using ::size_t _LIBCPP_USING_IF_EXISTS;
62
63#if !defined(_LIBCPP_CXX03_LANG)
64using ::max_align_t _LIBCPP_USING_IF_EXISTS;
65#endif
66
67_LIBCPP_END_NAMESPACE_STD
68
69#if _LIBCPP_STD_VER >= 17
70namespace std  // purposefully not versioned
71{
72enum class byte : unsigned char {};
73
74_LIBCPP_HIDE_FROM_ABI constexpr byte  operator| (byte  __lhs, byte __rhs) noexcept
75{
76    return static_cast<byte>(
77      static_cast<unsigned char>(
78         static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs)
79    ));
80}
81
82_LIBCPP_HIDE_FROM_ABI constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept
83{ return __lhs = __lhs | __rhs; }
84
85_LIBCPP_HIDE_FROM_ABI constexpr byte  operator& (byte  __lhs, byte __rhs) noexcept
86{
87    return static_cast<byte>(
88      static_cast<unsigned char>(
89         static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs)
90    ));
91}
92
93_LIBCPP_HIDE_FROM_ABI constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept
94{ return __lhs = __lhs & __rhs; }
95
96_LIBCPP_HIDE_FROM_ABI constexpr byte  operator^ (byte  __lhs, byte __rhs) noexcept
97{
98    return static_cast<byte>(
99      static_cast<unsigned char>(
100         static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs)
101    ));
102}
103
104_LIBCPP_HIDE_FROM_ABI constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept
105{ return __lhs = __lhs ^ __rhs; }
106
107_LIBCPP_HIDE_FROM_ABI constexpr byte  operator~ (byte __b) noexcept
108{
109    return static_cast<byte>(
110      static_cast<unsigned char>(
111        ~static_cast<unsigned int>(__b)
112    ));
113}
114
115template <class _Tp>
116using _EnableByteOverload = __enable_if_t<is_integral<_Tp>::value, byte>;
117
118template <class _Integer>
119_LIBCPP_HIDE_FROM_ABI constexpr _EnableByteOverload<_Integer> &
120  operator<<=(byte& __lhs, _Integer __shift) noexcept
121  { return __lhs = __lhs << __shift; }
122
123template <class _Integer>
124_LIBCPP_HIDE_FROM_ABI 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>
129_LIBCPP_HIDE_FROM_ABI constexpr _EnableByteOverload<_Integer> &
130  operator>>=(byte& __lhs, _Integer __shift) noexcept
131  { return __lhs = __lhs >> __shift; }
132
133template <class _Integer>
134_LIBCPP_HIDE_FROM_ABI constexpr _EnableByteOverload<_Integer>
135  operator>> (byte  __lhs, _Integer __shift) noexcept
136  { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); }
137
138template <class _Integer, class = _EnableByteOverload<_Integer> >
139_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Integer
140  to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); }
141
142} // namespace std
143
144#endif
145
146#endif // _LIBCPP_CSTDDEF
147