blob: bd62d6db39e8e61ca6ffdef331dcf0970f589c3a [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- cstddef ----------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// 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 Hinnantc51e1022010-05-11 19:42:16 +00007//
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 Hinnant3b6579a2010-08-22 00:02:43 +000020
Howard Hinnantc51e1022010-05-11 19:42:16 +000021namespace std
22{
23
24Types:
25
26 ptrdiff_t
27 size_t
28 max_align_t
29 nullptr_t
Marshall Clowcade1f72017-03-24 05:45:39 +000030 byte // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +000031
32} // std
33
34*/
35
36#include <__config>
Marshall Clow0a1e7502018-09-12 19:41:40 +000037#include <version>
Howard Hinnant59ef87b2010-06-02 18:53:22 +000038
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000039#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +000040#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000041#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +000042
Richard Smith523b1722015-10-09 00:26:50 +000043// Don't include our own <stddef.h>; we don't want to declare ::nullptr_t.
44#include_next <stddef.h>
45#include <__nullptr>
46
Howard Hinnantc51e1022010-05-11 19:42:16 +000047_LIBCPP_BEGIN_NAMESPACE_STD
48
49using ::ptrdiff_t;
50using ::size_t;
51
David L. Jones8465cf12017-02-10 01:27:42 +000052#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T) || \
Kamil Rytarowski5678f1e2018-08-20 22:29:20 +000053 defined(__DEFINED_max_align_t) || defined(__NetBSD__)
Chandler Carruth4dcf1992014-02-21 08:37:30 +000054// Re-use the compiler's <stddef.h> max_align_t where possible.
55using ::max_align_t;
56#else
Howard Hinnantc51e1022010-05-11 19:42:16 +000057typedef long double max_align_t;
Chandler Carruth4dcf1992014-02-21 08:37:30 +000058#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +000059
Howard Hinnantc51e1022010-05-11 19:42:16 +000060_LIBCPP_END_NAMESPACE_STD
61
Marshall Clowcade1f72017-03-24 05:45:39 +000062#if _LIBCPP_STD_VER > 14
63namespace std // purposefully not versioned
64{
65enum class byte : unsigned char {};
66
Marshall Clowcade1f72017-03-24 05:45:39 +000067constexpr byte operator| (byte __lhs, byte __rhs) noexcept
Marshall Clow31c8f462017-11-14 01:14:53 +000068{
Louis Dionne44bcff92018-08-03 22:36:53 +000069 return static_cast<byte>(
70 static_cast<unsigned char>(
71 static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs)
72 ));
Marshall Clow31c8f462017-11-14 01:14:53 +000073}
74
75constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept
76{ return __lhs = __lhs | __rhs; }
77
78constexpr byte operator& (byte __lhs, byte __rhs) noexcept
79{
Louis Dionne44bcff92018-08-03 22:36:53 +000080 return static_cast<byte>(
81 static_cast<unsigned char>(
82 static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs)
83 ));
Marshall Clow31c8f462017-11-14 01:14:53 +000084}
Marshall Clowcade1f72017-03-24 05:45:39 +000085
86constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept
Marshall Clow31c8f462017-11-14 01:14:53 +000087{ return __lhs = __lhs & __rhs; }
88
89constexpr byte operator^ (byte __lhs, byte __rhs) noexcept
90{
Louis Dionne44bcff92018-08-03 22:36:53 +000091 return static_cast<byte>(
92 static_cast<unsigned char>(
93 static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs)
94 ));
Marshall Clow31c8f462017-11-14 01:14:53 +000095}
Marshall Clowcade1f72017-03-24 05:45:39 +000096
Louis Dionne44bcff92018-08-03 22:36:53 +000097constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept
Marshall Clow31c8f462017-11-14 01:14:53 +000098{ return __lhs = __lhs ^ __rhs; }
Marshall Clowcade1f72017-03-24 05:45:39 +000099
100constexpr byte operator~ (byte __b) noexcept
Marshall Clow31c8f462017-11-14 01:14:53 +0000101{
102 return static_cast<byte>(
103 static_cast<unsigned char>(
104 ~static_cast<unsigned int>(__b)
105 ));
106}
Marshall Clowcade1f72017-03-24 05:45:39 +0000107
108}
109
110#include <type_traits> // rest of byte
111#endif
112
Howard Hinnantc51e1022010-05-11 19:42:16 +0000113#endif // _LIBCPP_CSTDDEF