cstddef 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  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 // C++11
  22. nullptr_t
  23. byte // C++17
  24. } // std
  25. */
  26. #include <__config>
  27. #include <__type_traits/enable_if.h>
  28. #include <__type_traits/integral_constant.h>
  29. #include <__type_traits/is_integral.h>
  30. #include <version>
  31. #include <stddef.h>
  32. #ifndef _LIBCPP_STDDEF_H
  33. # error <cstddef> tried including <stddef.h> but didn't find libc++'s <stddef.h> header. \
  34. This usually means that your header search paths are not configured properly. \
  35. The header search paths should contain the C++ Standard Library headers before \
  36. any C Standard Library, and you are probably using compiler flags that make that \
  37. not be the case.
  38. #endif
  39. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  40. # pragma GCC system_header
  41. #endif
  42. _LIBCPP_BEGIN_NAMESPACE_STD
  43. using ::nullptr_t;
  44. using ::ptrdiff_t _LIBCPP_USING_IF_EXISTS;
  45. using ::size_t _LIBCPP_USING_IF_EXISTS;
  46. #if !defined(_LIBCPP_CXX03_LANG)
  47. using ::max_align_t _LIBCPP_USING_IF_EXISTS;
  48. #endif
  49. _LIBCPP_END_NAMESPACE_STD
  50. #if _LIBCPP_STD_VER >= 17
  51. namespace std // purposefully not versioned
  52. {
  53. enum class byte : unsigned char {};
  54. _LIBCPP_HIDE_FROM_ABI inline constexpr byte operator|(byte __lhs, byte __rhs) noexcept {
  55. return static_cast<byte>(
  56. static_cast<unsigned char>(static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs)));
  57. }
  58. _LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept {
  59. return __lhs = __lhs | __rhs;
  60. }
  61. _LIBCPP_HIDE_FROM_ABI inline constexpr byte operator&(byte __lhs, byte __rhs) noexcept {
  62. return static_cast<byte>(
  63. static_cast<unsigned char>(static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs)));
  64. }
  65. _LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept {
  66. return __lhs = __lhs & __rhs;
  67. }
  68. _LIBCPP_HIDE_FROM_ABI inline constexpr byte operator^(byte __lhs, byte __rhs) noexcept {
  69. return static_cast<byte>(
  70. static_cast<unsigned char>(static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs)));
  71. }
  72. _LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept {
  73. return __lhs = __lhs ^ __rhs;
  74. }
  75. _LIBCPP_HIDE_FROM_ABI inline constexpr byte operator~(byte __b) noexcept {
  76. return static_cast<byte>(static_cast<unsigned char>(~static_cast<unsigned int>(__b)));
  77. }
  78. template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
  79. _LIBCPP_HIDE_FROM_ABI constexpr byte& operator<<=(byte& __lhs, _Integer __shift) noexcept {
  80. return __lhs = __lhs << __shift;
  81. }
  82. template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
  83. _LIBCPP_HIDE_FROM_ABI constexpr byte operator<<(byte __lhs, _Integer __shift) noexcept {
  84. return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift));
  85. }
  86. template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
  87. _LIBCPP_HIDE_FROM_ABI constexpr byte& operator>>=(byte& __lhs, _Integer __shift) noexcept {
  88. return __lhs = __lhs >> __shift;
  89. }
  90. template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
  91. _LIBCPP_HIDE_FROM_ABI constexpr byte operator>>(byte __lhs, _Integer __shift) noexcept {
  92. return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift));
  93. }
  94. template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
  95. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Integer to_integer(byte __b) noexcept {
  96. return static_cast<_Integer>(__b);
  97. }
  98. } // namespace std
  99. #endif
  100. #endif // _LIBCPP_CSTDDEF