xref: /freebsd/contrib/llvm-project/libcxx/include/cstddef (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
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*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI inline constexpr byte  operator| (byte  __lhs, byte __rhs) noexcept
750b57cec5SDimitry Andric{
760b57cec5SDimitry Andric    return static_cast<byte>(
770b57cec5SDimitry Andric      static_cast<unsigned char>(
780b57cec5SDimitry Andric         static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs)
790b57cec5SDimitry Andric    ));
800b57cec5SDimitry Andric}
810b57cec5SDimitry Andric
82*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept
830b57cec5SDimitry Andric{ return __lhs = __lhs | __rhs; }
840b57cec5SDimitry Andric
85*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI inline constexpr byte  operator& (byte  __lhs, byte __rhs) noexcept
860b57cec5SDimitry Andric{
870b57cec5SDimitry Andric    return static_cast<byte>(
880b57cec5SDimitry Andric      static_cast<unsigned char>(
890b57cec5SDimitry Andric         static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs)
900b57cec5SDimitry Andric    ));
910b57cec5SDimitry Andric}
920b57cec5SDimitry Andric
93*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept
940b57cec5SDimitry Andric{ return __lhs = __lhs & __rhs; }
950b57cec5SDimitry Andric
96*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI inline constexpr 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
104*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept
1050b57cec5SDimitry Andric{ return __lhs = __lhs ^ __rhs; }
1060b57cec5SDimitry Andric
107*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI inline constexpr byte  operator~ (byte __b) noexcept
1080b57cec5SDimitry Andric{
1090b57cec5SDimitry Andric    return static_cast<byte>(
1100b57cec5SDimitry Andric      static_cast<unsigned char>(
1110b57cec5SDimitry Andric        ~static_cast<unsigned int>(__b)
1120b57cec5SDimitry Andric    ));
1130b57cec5SDimitry Andric}
11481ad6265SDimitry Andric
115*5f757f3fSDimitry Andrictemplate <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
116*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr byte& operator<<=(byte& __lhs, _Integer __shift) noexcept {
117*5f757f3fSDimitry Andric  return __lhs = __lhs << __shift;
118*5f757f3fSDimitry Andric}
11981ad6265SDimitry Andric
120*5f757f3fSDimitry Andrictemplate <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
121*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr byte operator<<(byte __lhs, _Integer __shift) noexcept {
122*5f757f3fSDimitry Andric  return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift));
123*5f757f3fSDimitry Andric}
1240b57cec5SDimitry Andric
125*5f757f3fSDimitry Andrictemplate <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
126*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr byte& operator>>=(byte& __lhs, _Integer __shift) noexcept {
127*5f757f3fSDimitry Andric  return __lhs = __lhs >> __shift;
128*5f757f3fSDimitry Andric}
1295ffd83dbSDimitry Andric
130*5f757f3fSDimitry Andrictemplate <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
131*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr byte operator>>(byte __lhs, _Integer __shift) noexcept {
132*5f757f3fSDimitry Andric  return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift));
133*5f757f3fSDimitry Andric}
1345ffd83dbSDimitry Andric
135*5f757f3fSDimitry Andrictemplate <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
136*5f757f3fSDimitry Andric_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Integer to_integer(byte __b) noexcept {
137*5f757f3fSDimitry Andric  return static_cast<_Integer>(__b);
138*5f757f3fSDimitry Andric}
1391fd87a68SDimitry Andric
1401fd87a68SDimitry Andric} // namespace std
1410b57cec5SDimitry Andric
1420b57cec5SDimitry Andric#endif
1430b57cec5SDimitry Andric
1440b57cec5SDimitry Andric#endif // _LIBCPP_CSTDDEF
145