cstddef 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // -*- C++ -*- forwarding header.
  2. // Copyright (C) 1997-2022 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file cstddef
  21. * This is a Standard C++ Library file. You should @c \#include this file
  22. * in your programs, rather than any of the @a *.h implementation files.
  23. *
  24. * This is the C++ version of the Standard C Library header @c stddef.h,
  25. * and its contents are (mostly) the same as that header, but are all
  26. * contained in the namespace @c std (except for names which are defined
  27. * as macros in C).
  28. */
  29. //
  30. // ISO C++ 14882: 18.1 Types
  31. //
  32. #ifndef _GLIBCXX_CSTDDEF
  33. #define _GLIBCXX_CSTDDEF 1
  34. #pragma GCC system_header
  35. #undef __need_wchar_t
  36. #undef __need_ptrdiff_t
  37. #undef __need_size_t
  38. #undef __need_NULL
  39. #undef __need_wint_t
  40. #include <bits/c++config.h>
  41. #include <stddef.h>
  42. extern "C++"
  43. {
  44. #if __cplusplus >= 201103L
  45. namespace std
  46. {
  47. // We handle size_t, ptrdiff_t, and nullptr_t in c++config.h.
  48. using ::max_align_t;
  49. }
  50. #endif // C++11
  51. #if __cplusplus >= 201703L
  52. namespace std
  53. {
  54. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  55. #define __cpp_lib_byte 201603L
  56. /// std::byte
  57. enum class byte : unsigned char {};
  58. template<typename _IntegerType> struct __byte_operand { };
  59. template<> struct __byte_operand<bool> { using __type = byte; };
  60. template<> struct __byte_operand<char> { using __type = byte; };
  61. template<> struct __byte_operand<signed char> { using __type = byte; };
  62. template<> struct __byte_operand<unsigned char> { using __type = byte; };
  63. template<> struct __byte_operand<wchar_t> { using __type = byte; };
  64. #ifdef _GLIBCXX_USE_CHAR8_T
  65. template<> struct __byte_operand<char8_t> { using __type = byte; };
  66. #endif
  67. template<> struct __byte_operand<char16_t> { using __type = byte; };
  68. template<> struct __byte_operand<char32_t> { using __type = byte; };
  69. template<> struct __byte_operand<short> { using __type = byte; };
  70. template<> struct __byte_operand<unsigned short> { using __type = byte; };
  71. template<> struct __byte_operand<int> { using __type = byte; };
  72. template<> struct __byte_operand<unsigned int> { using __type = byte; };
  73. template<> struct __byte_operand<long> { using __type = byte; };
  74. template<> struct __byte_operand<unsigned long> { using __type = byte; };
  75. template<> struct __byte_operand<long long> { using __type = byte; };
  76. template<> struct __byte_operand<unsigned long long> { using __type = byte; };
  77. #if defined(__GLIBCXX_TYPE_INT_N_0)
  78. template<> struct __byte_operand<__GLIBCXX_TYPE_INT_N_0>
  79. { using __type = byte; };
  80. template<> struct __byte_operand<unsigned __GLIBCXX_TYPE_INT_N_0>
  81. { using __type = byte; };
  82. #endif
  83. #if defined(__GLIBCXX_TYPE_INT_N_1)
  84. template<> struct __byte_operand<__GLIBCXX_TYPE_INT_N_1>
  85. { using __type = byte; };
  86. template<> struct __byte_operand<unsigned __GLIBCXX_TYPE_INT_N_1>
  87. { using __type = byte; };
  88. #endif
  89. #if defined(__GLIBCXX_TYPE_INT_N_2)
  90. template<> struct __byte_operand<__GLIBCXX_TYPE_INT_N_2>
  91. { using __type = byte; };
  92. template<> struct __byte_operand<unsigned __GLIBCXX_TYPE_INT_N_2>
  93. { using __type = byte; };
  94. #endif
  95. template<typename _IntegerType>
  96. struct __byte_operand<const _IntegerType>
  97. : __byte_operand<_IntegerType> { };
  98. template<typename _IntegerType>
  99. struct __byte_operand<volatile _IntegerType>
  100. : __byte_operand<_IntegerType> { };
  101. template<typename _IntegerType>
  102. struct __byte_operand<const volatile _IntegerType>
  103. : __byte_operand<_IntegerType> { };
  104. template<typename _IntegerType>
  105. using __byte_op_t = typename __byte_operand<_IntegerType>::__type;
  106. template<typename _IntegerType>
  107. constexpr __byte_op_t<_IntegerType>
  108. operator<<(byte __b, _IntegerType __shift) noexcept
  109. { return (byte)(unsigned char)((unsigned)__b << __shift); }
  110. template<typename _IntegerType>
  111. constexpr __byte_op_t<_IntegerType>
  112. operator>>(byte __b, _IntegerType __shift) noexcept
  113. { return (byte)(unsigned char)((unsigned)__b >> __shift); }
  114. constexpr byte
  115. operator|(byte __l, byte __r) noexcept
  116. { return (byte)(unsigned char)((unsigned)__l | (unsigned)__r); }
  117. constexpr byte
  118. operator&(byte __l, byte __r) noexcept
  119. { return (byte)(unsigned char)((unsigned)__l & (unsigned)__r); }
  120. constexpr byte
  121. operator^(byte __l, byte __r) noexcept
  122. { return (byte)(unsigned char)((unsigned)__l ^ (unsigned)__r); }
  123. constexpr byte
  124. operator~(byte __b) noexcept
  125. { return (byte)(unsigned char)~(unsigned)__b; }
  126. template<typename _IntegerType>
  127. constexpr __byte_op_t<_IntegerType>&
  128. operator<<=(byte& __b, _IntegerType __shift) noexcept
  129. { return __b = __b << __shift; }
  130. template<typename _IntegerType>
  131. constexpr __byte_op_t<_IntegerType>&
  132. operator>>=(byte& __b, _IntegerType __shift) noexcept
  133. { return __b = __b >> __shift; }
  134. constexpr byte&
  135. operator|=(byte& __l, byte __r) noexcept
  136. { return __l = __l | __r; }
  137. constexpr byte&
  138. operator&=(byte& __l, byte __r) noexcept
  139. { return __l = __l & __r; }
  140. constexpr byte&
  141. operator^=(byte& __l, byte __r) noexcept
  142. { return __l = __l ^ __r; }
  143. template<typename _IntegerType>
  144. [[nodiscard]]
  145. constexpr _IntegerType
  146. to_integer(__byte_op_t<_IntegerType> __b) noexcept
  147. { return _IntegerType(__b); }
  148. _GLIBCXX_END_NAMESPACE_VERSION
  149. } // namespace std
  150. #endif // C++17
  151. } // extern "C++"
  152. #endif // _GLIBCXX_CSTDDEF