Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- cstddef ----------------------------------===// |
| 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame^] | 4 | // 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 Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_CSTDDEF |
| 11 | #define _LIBCPP_CSTDDEF |
| 12 | |
| 13 | /* |
| 14 | cstddef synopsis |
| 15 | |
| 16 | Macros: |
| 17 | |
| 18 | offsetof(type,member-designator) |
| 19 | NULL |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 20 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | namespace std |
| 22 | { |
| 23 | |
| 24 | Types: |
| 25 | |
| 26 | ptrdiff_t |
| 27 | size_t |
| 28 | max_align_t |
| 29 | nullptr_t |
Marshall Clow | cade1f7 | 2017-03-24 05:45:39 +0000 | [diff] [blame] | 30 | byte // C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 31 | |
| 32 | } // std |
| 33 | |
| 34 | */ |
| 35 | |
| 36 | #include <__config> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 37 | #include <version> |
Howard Hinnant | 59ef87b | 2010-06-02 18:53:22 +0000 | [diff] [blame] | 38 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 39 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 40 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 41 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 42 | |
Richard Smith | 523b172 | 2015-10-09 00:26:50 +0000 | [diff] [blame] | 43 | // 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 Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 47 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 48 | |
| 49 | using ::ptrdiff_t; |
| 50 | using ::size_t; |
| 51 | |
David L. Jones | 8465cf1 | 2017-02-10 01:27:42 +0000 | [diff] [blame] | 52 | #if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T) || \ |
Kamil Rytarowski | 5678f1e | 2018-08-20 22:29:20 +0000 | [diff] [blame] | 53 | defined(__DEFINED_max_align_t) || defined(__NetBSD__) |
Chandler Carruth | 4dcf199 | 2014-02-21 08:37:30 +0000 | [diff] [blame] | 54 | // Re-use the compiler's <stddef.h> max_align_t where possible. |
| 55 | using ::max_align_t; |
| 56 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 57 | typedef long double max_align_t; |
Chandler Carruth | 4dcf199 | 2014-02-21 08:37:30 +0000 | [diff] [blame] | 58 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 59 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 60 | _LIBCPP_END_NAMESPACE_STD |
| 61 | |
Marshall Clow | cade1f7 | 2017-03-24 05:45:39 +0000 | [diff] [blame] | 62 | #if _LIBCPP_STD_VER > 14 |
| 63 | namespace std // purposefully not versioned |
| 64 | { |
| 65 | enum class byte : unsigned char {}; |
| 66 | |
Marshall Clow | cade1f7 | 2017-03-24 05:45:39 +0000 | [diff] [blame] | 67 | constexpr byte operator| (byte __lhs, byte __rhs) noexcept |
Marshall Clow | 31c8f46 | 2017-11-14 01:14:53 +0000 | [diff] [blame] | 68 | { |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 69 | return static_cast<byte>( |
| 70 | static_cast<unsigned char>( |
| 71 | static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs) |
| 72 | )); |
Marshall Clow | 31c8f46 | 2017-11-14 01:14:53 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept |
| 76 | { return __lhs = __lhs | __rhs; } |
| 77 | |
| 78 | constexpr byte operator& (byte __lhs, byte __rhs) noexcept |
| 79 | { |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 80 | return static_cast<byte>( |
| 81 | static_cast<unsigned char>( |
| 82 | static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs) |
| 83 | )); |
Marshall Clow | 31c8f46 | 2017-11-14 01:14:53 +0000 | [diff] [blame] | 84 | } |
Marshall Clow | cade1f7 | 2017-03-24 05:45:39 +0000 | [diff] [blame] | 85 | |
| 86 | constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept |
Marshall Clow | 31c8f46 | 2017-11-14 01:14:53 +0000 | [diff] [blame] | 87 | { return __lhs = __lhs & __rhs; } |
| 88 | |
| 89 | constexpr byte operator^ (byte __lhs, byte __rhs) noexcept |
| 90 | { |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 91 | return static_cast<byte>( |
| 92 | static_cast<unsigned char>( |
| 93 | static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs) |
| 94 | )); |
Marshall Clow | 31c8f46 | 2017-11-14 01:14:53 +0000 | [diff] [blame] | 95 | } |
Marshall Clow | cade1f7 | 2017-03-24 05:45:39 +0000 | [diff] [blame] | 96 | |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 97 | constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept |
Marshall Clow | 31c8f46 | 2017-11-14 01:14:53 +0000 | [diff] [blame] | 98 | { return __lhs = __lhs ^ __rhs; } |
Marshall Clow | cade1f7 | 2017-03-24 05:45:39 +0000 | [diff] [blame] | 99 | |
| 100 | constexpr byte operator~ (byte __b) noexcept |
Marshall Clow | 31c8f46 | 2017-11-14 01:14:53 +0000 | [diff] [blame] | 101 | { |
| 102 | return static_cast<byte>( |
| 103 | static_cast<unsigned char>( |
| 104 | ~static_cast<unsigned int>(__b) |
| 105 | )); |
| 106 | } |
Marshall Clow | cade1f7 | 2017-03-24 05:45:39 +0000 | [diff] [blame] | 107 | |
| 108 | } |
| 109 | |
| 110 | #include <type_traits> // rest of byte |
| 111 | #endif |
| 112 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 113 | #endif // _LIBCPP_CSTDDEF |