cstddef 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // -*- C++ -*-
  2. //===--------------------------- cstddef ----------------------------------===//
  3. //
  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
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_CSTDDEF
  10. #define _LIBCPP_CSTDDEF
  11. /*
  12. cstddef synopsis
  13. Macros:
  14. offsetof(type,member-designator)
  15. NULL
  16. namespace std
  17. {
  18. Types:
  19. ptrdiff_t
  20. size_t
  21. max_align_t
  22. nullptr_t
  23. byte // C++17
  24. } // std
  25. */
  26. #include <__config>
  27. #include <version>
  28. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  29. #pragma GCC system_header
  30. #endif
  31. // Don't include our own <stddef.h>; we don't want to declare ::nullptr_t.
  32. #include_next <stddef.h>
  33. #include <__nullptr>
  34. _LIBCPP_BEGIN_NAMESPACE_STD
  35. using ::ptrdiff_t;
  36. using ::size_t;
  37. #if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T) || \
  38. defined(__DEFINED_max_align_t) || defined(__NetBSD__)
  39. // Re-use the compiler's <stddef.h> max_align_t where possible.
  40. using ::max_align_t;
  41. #else
  42. typedef long double max_align_t;
  43. #endif
  44. _LIBCPP_END_NAMESPACE_STD
  45. #if _LIBCPP_STD_VER > 14
  46. namespace std // purposefully not versioned
  47. {
  48. enum class byte : unsigned char {};
  49. constexpr byte operator| (byte __lhs, byte __rhs) noexcept
  50. {
  51. return static_cast<byte>(
  52. static_cast<unsigned char>(
  53. static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs)
  54. ));
  55. }
  56. constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept
  57. { return __lhs = __lhs | __rhs; }
  58. constexpr byte operator& (byte __lhs, byte __rhs) noexcept
  59. {
  60. return static_cast<byte>(
  61. static_cast<unsigned char>(
  62. static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs)
  63. ));
  64. }
  65. constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept
  66. { return __lhs = __lhs & __rhs; }
  67. constexpr byte operator^ (byte __lhs, byte __rhs) noexcept
  68. {
  69. return static_cast<byte>(
  70. static_cast<unsigned char>(
  71. static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs)
  72. ));
  73. }
  74. constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept
  75. { return __lhs = __lhs ^ __rhs; }
  76. constexpr byte operator~ (byte __b) noexcept
  77. {
  78. return static_cast<byte>(
  79. static_cast<unsigned char>(
  80. ~static_cast<unsigned int>(__b)
  81. ));
  82. }
  83. }
  84. #include <type_traits> // rest of byte
  85. #endif
  86. #endif // _LIBCPP_CSTDDEF