xref: /freebsd/contrib/llvm-project/libcxx/include/cstddef (revision cb14a3fe5122c879eae1fb480ed7ce82a699ddb6)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry 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
3681ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
370b57cec5SDimitry Andric#include <__config>
3881ad6265SDimitry Andric#include <__type_traits/enable_if.h>
3981ad6265SDimitry Andric#include <__type_traits/integral_constant.h>
4081ad6265SDimitry Andric#include <__type_traits/is_integral.h>
410b57cec5SDimitry Andric#include <version>
420b57cec5SDimitry Andric
43bdd1243dSDimitry Andric#include <stddef.h>
44bdd1243dSDimitry Andric
45bdd1243dSDimitry Andric#ifndef _LIBCPP_STDDEF_H
46bdd1243dSDimitry Andric#   error <cstddef> tried including <stddef.h> but didn't find libc++'s <stddef.h> header. \
47bdd1243dSDimitry Andric          This usually means that your header search paths are not configured properly. \
48bdd1243dSDimitry Andric          The header search paths should contain the C++ Standard Library headers before \
49bdd1243dSDimitry Andric          any C Standard Library, and you are probably using compiler flags that make that \
50bdd1243dSDimitry Andric          not be the case.
51bdd1243dSDimitry Andric#endif
52bdd1243dSDimitry Andric
530b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
540b57cec5SDimitry Andric#  pragma GCC system_header
550b57cec5SDimitry Andric#endif
560b57cec5SDimitry Andric
570b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
580b57cec5SDimitry Andric
5981ad6265SDimitry Andricusing ::nullptr_t;
60fe6060f1SDimitry Andricusing ::ptrdiff_t _LIBCPP_USING_IF_EXISTS;
61fe6060f1SDimitry Andricusing ::size_t _LIBCPP_USING_IF_EXISTS;
620b57cec5SDimitry Andric
635ffd83dbSDimitry Andric#if !defined(_LIBCPP_CXX03_LANG)
64fe6060f1SDimitry Andricusing ::max_align_t _LIBCPP_USING_IF_EXISTS;
655ffd83dbSDimitry Andric#endif
665ffd83dbSDimitry Andric
670b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
680b57cec5SDimitry Andric
6906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
700b57cec5SDimitry Andricnamespace std // purposefully not versioned
710b57cec5SDimitry Andric{
720b57cec5SDimitry Andricenum class byte : unsigned char {};
730b57cec5SDimitry Andric
74*cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator|(byte __lhs, byte __rhs) noexcept {
750b57cec5SDimitry Andric  return static_cast<byte>(
76*cb14a3feSDimitry Andric      static_cast<unsigned char>(static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs)));
770b57cec5SDimitry Andric}
780b57cec5SDimitry Andric
79*cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept {
80*cb14a3feSDimitry Andric  return __lhs = __lhs | __rhs;
810b57cec5SDimitry Andric}
820b57cec5SDimitry Andric
83*cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator&(byte __lhs, byte __rhs) noexcept {
840b57cec5SDimitry Andric  return static_cast<byte>(
85*cb14a3feSDimitry Andric      static_cast<unsigned char>(static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs)));
860b57cec5SDimitry Andric}
870b57cec5SDimitry Andric
88*cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept {
89*cb14a3feSDimitry Andric  return __lhs = __lhs & __rhs;
90*cb14a3feSDimitry Andric}
910b57cec5SDimitry Andric
92*cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator^(byte __lhs, byte __rhs) noexcept {
930b57cec5SDimitry Andric  return static_cast<byte>(
94*cb14a3feSDimitry Andric      static_cast<unsigned char>(static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs)));
95*cb14a3feSDimitry Andric}
96*cb14a3feSDimitry Andric
97*cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept {
98*cb14a3feSDimitry Andric  return __lhs = __lhs ^ __rhs;
99*cb14a3feSDimitry Andric}
100*cb14a3feSDimitry Andric
101*cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator~(byte __b) noexcept {
102*cb14a3feSDimitry Andric  return static_cast<byte>(static_cast<unsigned char>(~static_cast<unsigned int>(__b)));
1030b57cec5SDimitry Andric}
10481ad6265SDimitry Andric
1055f757f3fSDimitry Andrictemplate <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
1065f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr byte& operator<<=(byte& __lhs, _Integer __shift) noexcept {
1075f757f3fSDimitry Andric  return __lhs = __lhs << __shift;
1085f757f3fSDimitry Andric}
10981ad6265SDimitry Andric
1105f757f3fSDimitry Andrictemplate <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
1115f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr byte operator<<(byte __lhs, _Integer __shift) noexcept {
1125f757f3fSDimitry Andric  return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift));
1135f757f3fSDimitry Andric}
1140b57cec5SDimitry Andric
1155f757f3fSDimitry Andrictemplate <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
1165f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr byte& operator>>=(byte& __lhs, _Integer __shift) noexcept {
1175f757f3fSDimitry Andric  return __lhs = __lhs >> __shift;
1185f757f3fSDimitry Andric}
1195ffd83dbSDimitry Andric
1205f757f3fSDimitry Andrictemplate <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
1215f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr byte operator>>(byte __lhs, _Integer __shift) noexcept {
1225f757f3fSDimitry Andric  return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift));
1235f757f3fSDimitry Andric}
1245ffd83dbSDimitry Andric
1255f757f3fSDimitry Andrictemplate <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
1265f757f3fSDimitry Andric_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Integer to_integer(byte __b) noexcept {
1275f757f3fSDimitry Andric  return static_cast<_Integer>(__b);
1285f757f3fSDimitry Andric}
1291fd87a68SDimitry Andric
1301fd87a68SDimitry Andric} // namespace std
1310b57cec5SDimitry Andric
1320b57cec5SDimitry Andric#endif
1330b57cec5SDimitry Andric
1340b57cec5SDimitry Andric#endif // _LIBCPP_CSTDDEF
135