xref: /freebsd-12.1/contrib/libc++/include/cstddef (revision b5893f02)
17a984708SDavid Chisnall// -*- C++ -*-
27a984708SDavid Chisnall//===--------------------------- cstddef ----------------------------------===//
37a984708SDavid Chisnall//
47a984708SDavid Chisnall//                     The LLVM Compiler Infrastructure
57a984708SDavid Chisnall//
67a984708SDavid Chisnall// This file is dual licensed under the MIT and the University of Illinois Open
77a984708SDavid Chisnall// Source Licenses. See LICENSE.TXT for details.
87a984708SDavid Chisnall//
97a984708SDavid Chisnall//===----------------------------------------------------------------------===//
107a984708SDavid Chisnall
117a984708SDavid Chisnall#ifndef _LIBCPP_CSTDDEF
127a984708SDavid Chisnall#define _LIBCPP_CSTDDEF
137a984708SDavid Chisnall
147a984708SDavid Chisnall/*
157a984708SDavid Chisnall    cstddef synopsis
167a984708SDavid Chisnall
177a984708SDavid ChisnallMacros:
187a984708SDavid Chisnall
197a984708SDavid Chisnall    offsetof(type,member-designator)
207a984708SDavid Chisnall    NULL
217a984708SDavid Chisnall
227a984708SDavid Chisnallnamespace std
237a984708SDavid Chisnall{
247a984708SDavid Chisnall
257a984708SDavid ChisnallTypes:
267a984708SDavid Chisnall
277a984708SDavid Chisnall    ptrdiff_t
287a984708SDavid Chisnall    size_t
297a984708SDavid Chisnall    max_align_t
307a984708SDavid Chisnall    nullptr_t
31540d2a8bSDimitry Andric    byte // C++17
327a984708SDavid Chisnall
337a984708SDavid Chisnall}  // std
347a984708SDavid Chisnall
357a984708SDavid Chisnall*/
367a984708SDavid Chisnall
377a984708SDavid Chisnall#include <__config>
38*b5893f02SDimitry Andric#include <version>
397a984708SDavid Chisnall
407a984708SDavid Chisnall#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
417a984708SDavid Chisnall#pragma GCC system_header
427a984708SDavid Chisnall#endif
437a984708SDavid Chisnall
449729cf09SDimitry Andric// Don't include our own <stddef.h>; we don't want to declare ::nullptr_t.
459729cf09SDimitry Andric#include_next <stddef.h>
469729cf09SDimitry Andric#include <__nullptr>
479729cf09SDimitry Andric
487a984708SDavid Chisnall_LIBCPP_BEGIN_NAMESPACE_STD
497a984708SDavid Chisnall
507a984708SDavid Chisnallusing ::ptrdiff_t;
517a984708SDavid Chisnallusing ::size_t;
527a984708SDavid Chisnall
53540d2a8bSDimitry Andric#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T) || \
54*b5893f02SDimitry Andric    defined(__DEFINED_max_align_t) || defined(__NetBSD__)
55d72607e9SDimitry Andric// Re-use the compiler's <stddef.h> max_align_t where possible.
56d72607e9SDimitry Andricusing ::max_align_t;
57d72607e9SDimitry Andric#else
587a984708SDavid Chisnalltypedef long double max_align_t;
59d72607e9SDimitry Andric#endif
607a984708SDavid Chisnall
617a984708SDavid Chisnall_LIBCPP_END_NAMESPACE_STD
627a984708SDavid Chisnall
63540d2a8bSDimitry Andric#if _LIBCPP_STD_VER > 14
64540d2a8bSDimitry Andricnamespace std  // purposefully not versioned
65540d2a8bSDimitry Andric{
66540d2a8bSDimitry Andricenum class byte : unsigned char {};
67540d2a8bSDimitry Andric
68540d2a8bSDimitry Andricconstexpr byte  operator| (byte  __lhs, byte __rhs) noexcept
69b2c7081bSDimitry Andric{
70b2c7081bSDimitry Andric    return static_cast<byte>(
71b2c7081bSDimitry Andric      static_cast<unsigned char>(
72b2c7081bSDimitry Andric         static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs)
73b2c7081bSDimitry Andric    ));
74b2c7081bSDimitry Andric}
75b2c7081bSDimitry Andric
76b2c7081bSDimitry Andricconstexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept
77b2c7081bSDimitry Andric{ return __lhs = __lhs | __rhs; }
78b2c7081bSDimitry Andric
79b2c7081bSDimitry Andricconstexpr byte  operator& (byte  __lhs, byte __rhs) noexcept
80b2c7081bSDimitry Andric{
81b2c7081bSDimitry Andric    return static_cast<byte>(
82b2c7081bSDimitry Andric      static_cast<unsigned char>(
83b2c7081bSDimitry Andric         static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs)
84b2c7081bSDimitry Andric    ));
85b2c7081bSDimitry Andric}
86540d2a8bSDimitry Andric
87540d2a8bSDimitry Andricconstexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept
88b2c7081bSDimitry Andric{ return __lhs = __lhs & __rhs; }
89b2c7081bSDimitry Andric
90b2c7081bSDimitry Andricconstexpr byte  operator^ (byte  __lhs, byte __rhs) noexcept
91b2c7081bSDimitry Andric{
92b2c7081bSDimitry Andric    return static_cast<byte>(
93b2c7081bSDimitry Andric      static_cast<unsigned char>(
94b2c7081bSDimitry Andric         static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs)
95b2c7081bSDimitry Andric    ));
96b2c7081bSDimitry Andric}
97540d2a8bSDimitry Andric
98540d2a8bSDimitry Andricconstexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept
99b2c7081bSDimitry Andric{ return __lhs = __lhs ^ __rhs; }
100540d2a8bSDimitry Andric
101540d2a8bSDimitry Andricconstexpr byte  operator~ (byte __b) noexcept
102b2c7081bSDimitry Andric{
103b2c7081bSDimitry Andric    return static_cast<byte>(
104b2c7081bSDimitry Andric      static_cast<unsigned char>(
105b2c7081bSDimitry Andric        ~static_cast<unsigned int>(__b)
106b2c7081bSDimitry Andric    ));
107b2c7081bSDimitry Andric}
108540d2a8bSDimitry Andric
109540d2a8bSDimitry Andric}
110540d2a8bSDimitry Andric
111540d2a8bSDimitry Andric#include <type_traits>  // rest of byte
112540d2a8bSDimitry Andric#endif
113540d2a8bSDimitry Andric
1147a984708SDavid Chisnall#endif  // _LIBCPP_CSTDDEF
115