xref: /freebsd/contrib/llvm-project/libcxx/include/cstddef (revision fe6060f10f634930ff71b7c50291ddc610da2475)
10b57cec5SDimitry Andric// -*- C++ -*-
20b57cec5SDimitry Andric//===--------------------------- cstddef ----------------------------------===//
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
360b57cec5SDimitry Andric#include <__config>
370b57cec5SDimitry Andric#include <version>
380b57cec5SDimitry Andric
390b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
400b57cec5SDimitry Andric#pragma GCC system_header
410b57cec5SDimitry Andric#endif
420b57cec5SDimitry Andric
430b57cec5SDimitry Andric// Don't include our own <stddef.h>; we don't want to declare ::nullptr_t.
440b57cec5SDimitry Andric#include_next <stddef.h>
450b57cec5SDimitry Andric#include <__nullptr>
460b57cec5SDimitry Andric
470b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
480b57cec5SDimitry Andric
49*fe6060f1SDimitry Andricusing ::ptrdiff_t _LIBCPP_USING_IF_EXISTS;
50*fe6060f1SDimitry Andricusing ::size_t _LIBCPP_USING_IF_EXISTS;
510b57cec5SDimitry Andric
525ffd83dbSDimitry Andric#if !defined(_LIBCPP_CXX03_LANG)
53*fe6060f1SDimitry Andricusing ::max_align_t _LIBCPP_USING_IF_EXISTS;
545ffd83dbSDimitry Andric#endif
555ffd83dbSDimitry Andric
565ffd83dbSDimitry Andrictemplate <class _Tp> struct __libcpp_is_integral                     { enum { value = 0 }; };
575ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<bool>               { enum { value = 1 }; };
585ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<char>               { enum { value = 1 }; };
595ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<signed char>        { enum { value = 1 }; };
605ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<unsigned char>      { enum { value = 1 }; };
615ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<wchar_t>            { enum { value = 1 }; };
62*fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T
635ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<char8_t>            { enum { value = 1 }; };
645ffd83dbSDimitry Andric#endif
655ffd83dbSDimitry Andric#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
665ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<char16_t>           { enum { value = 1 }; };
675ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<char32_t>           { enum { value = 1 }; };
685ffd83dbSDimitry Andric#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
695ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<short>              { enum { value = 1 }; };
705ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<unsigned short>     { enum { value = 1 }; };
715ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<int>                { enum { value = 1 }; };
725ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<unsigned int>       { enum { value = 1 }; };
735ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<long>               { enum { value = 1 }; };
745ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<unsigned long>      { enum { value = 1 }; };
755ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<long long>          { enum { value = 1 }; };
765ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<unsigned long long> { enum { value = 1 }; };
775ffd83dbSDimitry Andric#ifndef _LIBCPP_HAS_NO_INT128
785ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<__int128_t>         { enum { value = 1 }; };
795ffd83dbSDimitry Andrictemplate <>          struct __libcpp_is_integral<__uint128_t>        { enum { value = 1 }; };
800b57cec5SDimitry Andric#endif
810b57cec5SDimitry Andric
820b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
830b57cec5SDimitry Andric
840b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
850b57cec5SDimitry Andricnamespace std  // purposefully not versioned
860b57cec5SDimitry Andric{
870b57cec5SDimitry Andricenum class byte : unsigned char {};
880b57cec5SDimitry Andric
895ffd83dbSDimitry Andric
905ffd83dbSDimitry Andrictemplate <bool> struct __enable_if_integral_imp {};
915ffd83dbSDimitry Andrictemplate <> struct __enable_if_integral_imp<true> { using type = byte; };
925ffd83dbSDimitry Andrictemplate <class _Tp> using _EnableByteOverload = typename __enable_if_integral_imp<__libcpp_is_integral<_Tp>::value>::type;
935ffd83dbSDimitry Andric
940b57cec5SDimitry Andricconstexpr byte  operator| (byte  __lhs, byte __rhs) noexcept
950b57cec5SDimitry Andric{
960b57cec5SDimitry Andric    return static_cast<byte>(
970b57cec5SDimitry Andric      static_cast<unsigned char>(
980b57cec5SDimitry Andric         static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs)
990b57cec5SDimitry Andric    ));
1000b57cec5SDimitry Andric}
1010b57cec5SDimitry Andric
1020b57cec5SDimitry Andricconstexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept
1030b57cec5SDimitry Andric{ return __lhs = __lhs | __rhs; }
1040b57cec5SDimitry Andric
1050b57cec5SDimitry Andricconstexpr byte  operator& (byte  __lhs, byte __rhs) noexcept
1060b57cec5SDimitry Andric{
1070b57cec5SDimitry Andric    return static_cast<byte>(
1080b57cec5SDimitry Andric      static_cast<unsigned char>(
1090b57cec5SDimitry Andric         static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs)
1100b57cec5SDimitry Andric    ));
1110b57cec5SDimitry Andric}
1120b57cec5SDimitry Andric
1130b57cec5SDimitry Andricconstexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept
1140b57cec5SDimitry Andric{ return __lhs = __lhs & __rhs; }
1150b57cec5SDimitry Andric
1160b57cec5SDimitry Andricconstexpr byte  operator^ (byte  __lhs, byte __rhs) noexcept
1170b57cec5SDimitry Andric{
1180b57cec5SDimitry Andric    return static_cast<byte>(
1190b57cec5SDimitry Andric      static_cast<unsigned char>(
1200b57cec5SDimitry Andric         static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs)
1210b57cec5SDimitry Andric    ));
1220b57cec5SDimitry Andric}
1230b57cec5SDimitry Andric
1240b57cec5SDimitry Andricconstexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept
1250b57cec5SDimitry Andric{ return __lhs = __lhs ^ __rhs; }
1260b57cec5SDimitry Andric
1270b57cec5SDimitry Andricconstexpr byte  operator~ (byte __b) noexcept
1280b57cec5SDimitry Andric{
1290b57cec5SDimitry Andric    return static_cast<byte>(
1300b57cec5SDimitry Andric      static_cast<unsigned char>(
1310b57cec5SDimitry Andric        ~static_cast<unsigned int>(__b)
1320b57cec5SDimitry Andric    ));
1330b57cec5SDimitry Andric}
1345ffd83dbSDimitry Andrictemplate <class _Integer>
1355ffd83dbSDimitry Andric  constexpr _EnableByteOverload<_Integer> &
1365ffd83dbSDimitry Andric  operator<<=(byte& __lhs, _Integer __shift) noexcept
1375ffd83dbSDimitry Andric  { return __lhs = __lhs << __shift; }
1380b57cec5SDimitry Andric
1395ffd83dbSDimitry Andrictemplate <class _Integer>
1405ffd83dbSDimitry Andric  constexpr _EnableByteOverload<_Integer>
1415ffd83dbSDimitry Andric  operator<< (byte  __lhs, _Integer __shift) noexcept
1425ffd83dbSDimitry Andric  { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); }
1435ffd83dbSDimitry Andric
1445ffd83dbSDimitry Andrictemplate <class _Integer>
1455ffd83dbSDimitry Andric  constexpr _EnableByteOverload<_Integer> &
1465ffd83dbSDimitry Andric  operator>>=(byte& __lhs, _Integer __shift) noexcept
1475ffd83dbSDimitry Andric  { return __lhs = __lhs >> __shift; }
1485ffd83dbSDimitry Andric
1495ffd83dbSDimitry Andrictemplate <class _Integer>
1505ffd83dbSDimitry Andric  constexpr _EnableByteOverload<_Integer>
1515ffd83dbSDimitry Andric  operator>> (byte  __lhs, _Integer __shift) noexcept
1525ffd83dbSDimitry Andric  { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); }
1535ffd83dbSDimitry Andric
1545ffd83dbSDimitry Andrictemplate <class _Integer, class = _EnableByteOverload<_Integer> >
155*fe6060f1SDimitry Andric  _LIBCPP_NODISCARD_EXT constexpr _Integer
1565ffd83dbSDimitry Andric  to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); }
1570b57cec5SDimitry Andric}
1580b57cec5SDimitry Andric
1590b57cec5SDimitry Andric#endif
1600b57cec5SDimitry Andric
1610b57cec5SDimitry Andric#endif // _LIBCPP_CSTDDEF
162