blob: e3c066917570fbc3faecaf73564b06ba28224b6b [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:161// -*- C++ -*-
Louis Dionneeb8650a2021-11-17 21:25:012//===----------------------------------------------------------------------===//
Howard Hinnant3e519522010-05-11 19:42:163//
Chandler Carruth57b08b02019-01-19 10:56:404// 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
Howard Hinnant3e519522010-05-11 19:42:167//
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
Howard Hinnantb3371f62010-08-22 00:02:4320
Howard Hinnant3e519522010-05-11 19:42:1621namespace std
22{
23
24Types:
25
26 ptrdiff_t
27 size_t
Joerg Sonnenberger98f77822020-04-03 22:48:0228 max_align_t // C++11
Howard Hinnant3e519522010-05-11 19:42:1629 nullptr_t
Marshall Clowc97d8aa2017-03-24 05:45:3930 byte // C++17
Howard Hinnant3e519522010-05-11 19:42:1631
32} // std
33
34*/
35
Louis Dionne385cc252022-03-25 16:55:3636#include <__assert> // all public C++ headers provide the assertion handler
Howard Hinnant3e519522010-05-11 19:42:1637#include <__config>
Nikolas Klauser7e69bd92022-05-28 13:22:2538#include <__type_traits/enable_if.h>
39#include <__type_traits/integral_constant.h>
Nikolas Klausereebc1fb2022-05-20 21:31:1340#include <__type_traits/is_integral.h>
Marshall Clowf56972e2018-09-12 19:41:4041#include <version>
Howard Hinnant8ae50972010-06-02 18:53:2242
Louis Dionne8cedff12022-08-08 21:03:5643#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
Howard Hinnant073458b2011-10-17 20:05:1053#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyerfa6b9e42022-02-02 01:16:4054# pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:1055#endif
Howard Hinnant3e519522010-05-11 19:42:1656
Howard Hinnant3e519522010-05-11 19:42:1657_LIBCPP_BEGIN_NAMESPACE_STD
58
Louis Dionne157bbe62021-09-08 16:57:5859using ::nullptr_t;
Louis Dionnea9c91832021-06-02 14:41:3760using ::ptrdiff_t _LIBCPP_USING_IF_EXISTS;
61using ::size_t _LIBCPP_USING_IF_EXISTS;
Howard Hinnant3e519522010-05-11 19:42:1662
Joerg Sonnenberger98f77822020-04-03 22:48:0263#if !defined(_LIBCPP_CXX03_LANG)
Louis Dionnea9c91832021-06-02 14:41:3764using ::max_align_t _LIBCPP_USING_IF_EXISTS;
Chandler Carruth265b83a2014-02-21 08:37:3065#endif
Howard Hinnant3e519522010-05-11 19:42:1666
Howard Hinnant3e519522010-05-11 19:42:1667_LIBCPP_END_NAMESPACE_STD
68
Marshall Clowc97d8aa2017-03-24 05:45:3969#if _LIBCPP_STD_VER > 14
70namespace std // purposefully not versioned
71{
72enum class byte : unsigned char {};
73
Nikolas Klauser80c7e932022-08-13 11:23:1674_LIBCPP_HIDE_FROM_ABI constexpr byte operator| (byte __lhs, byte __rhs) noexcept
Marshall Clow12de6e92017-11-14 01:14:5375{
Louis Dionne7c3492b002018-08-03 22:36:5376 return static_cast<byte>(
77 static_cast<unsigned char>(
78 static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs)
79 ));
Marshall Clow12de6e92017-11-14 01:14:5380}
81
Nikolas Klauser80c7e932022-08-13 11:23:1682_LIBCPP_HIDE_FROM_ABI constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept
Marshall Clow12de6e92017-11-14 01:14:5383{ return __lhs = __lhs | __rhs; }
84
Nikolas Klauser80c7e932022-08-13 11:23:1685_LIBCPP_HIDE_FROM_ABI constexpr byte operator& (byte __lhs, byte __rhs) noexcept
Marshall Clow12de6e92017-11-14 01:14:5386{
Louis Dionne7c3492b002018-08-03 22:36:5387 return static_cast<byte>(
88 static_cast<unsigned char>(
89 static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs)
90 ));
Marshall Clow12de6e92017-11-14 01:14:5391}
Marshall Clowc97d8aa2017-03-24 05:45:3992
Nikolas Klauser80c7e932022-08-13 11:23:1693_LIBCPP_HIDE_FROM_ABI constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept
Marshall Clow12de6e92017-11-14 01:14:5394{ return __lhs = __lhs & __rhs; }
95
Nikolas Klauser80c7e932022-08-13 11:23:1696_LIBCPP_HIDE_FROM_ABI constexpr byte operator^ (byte __lhs, byte __rhs) noexcept
Marshall Clow12de6e92017-11-14 01:14:5397{
Louis Dionne7c3492b002018-08-03 22:36:5398 return static_cast<byte>(
99 static_cast<unsigned char>(
100 static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs)
101 ));
Marshall Clow12de6e92017-11-14 01:14:53102}
Marshall Clowc97d8aa2017-03-24 05:45:39103
Nikolas Klauser80c7e932022-08-13 11:23:16104_LIBCPP_HIDE_FROM_ABI constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept
Marshall Clow12de6e92017-11-14 01:14:53105{ return __lhs = __lhs ^ __rhs; }
Marshall Clowc97d8aa2017-03-24 05:45:39106
Nikolas Klauser80c7e932022-08-13 11:23:16107_LIBCPP_HIDE_FROM_ABI constexpr byte operator~ (byte __b) noexcept
Marshall Clow12de6e92017-11-14 01:14:53108{
109 return static_cast<byte>(
110 static_cast<unsigned char>(
111 ~static_cast<unsigned int>(__b)
112 ));
113}
Nikolas Klauser7e69bd92022-05-28 13:22:25114
115template <class _Tp>
116using _EnableByteOverload = __enable_if_t<is_integral<_Tp>::value, byte>;
117
Eric Fiseliercccf1ef2020-02-14 16:34:46118template <class _Integer>
Nikolas Klauser80c7e932022-08-13 11:23:16119_LIBCPP_HIDE_FROM_ABI constexpr _EnableByteOverload<_Integer> &
Eric Fiseliercccf1ef2020-02-14 16:34:46120 operator<<=(byte& __lhs, _Integer __shift) noexcept
121 { return __lhs = __lhs << __shift; }
Marshall Clowc97d8aa2017-03-24 05:45:39122
Eric Fiseliercccf1ef2020-02-14 16:34:46123template <class _Integer>
Nikolas Klauser80c7e932022-08-13 11:23:16124_LIBCPP_HIDE_FROM_ABI constexpr _EnableByteOverload<_Integer>
Eric Fiseliercccf1ef2020-02-14 16:34:46125 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>
Nikolas Klauser80c7e932022-08-13 11:23:16129_LIBCPP_HIDE_FROM_ABI constexpr _EnableByteOverload<_Integer> &
Eric Fiseliercccf1ef2020-02-14 16:34:46130 operator>>=(byte& __lhs, _Integer __shift) noexcept
131 { return __lhs = __lhs >> __shift; }
132
133template <class _Integer>
Nikolas Klauser80c7e932022-08-13 11:23:16134_LIBCPP_HIDE_FROM_ABI constexpr _EnableByteOverload<_Integer>
Eric Fiseliercccf1ef2020-02-14 16:34:46135 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> >
Nikolas Klauser80c7e932022-08-13 11:23:16139_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Integer
Eric Fiseliercccf1ef2020-02-14 16:34:46140 to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); }
Nikolas Klauser9c52a192022-02-01 17:11:49141
142} // namespace std
Marshall Clowc97d8aa2017-03-24 05:45:39143
Marshall Clowc97d8aa2017-03-24 05:45:39144#endif
145
Louis Dionne4cd6ca12021-04-20 16:03:32146#endif // _LIBCPP_CSTDDEF