cstddef 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // -*- C++ -*- forwarding header.
  2. // Copyright (C) 1997-2019 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 201603
  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. #ifdef _GLIBCXX_USE_WCHAR_T
  64. template<> struct __byte_operand<wchar_t> { using __type = byte; };
  65. #endif
  66. #ifdef _GLIBCXX_USE_CHAR8_T
  67. template<> struct __byte_operand<char8_t> { using __type = byte; };
  68. #endif
  69. template<> struct __byte_operand<char16_t> { using __type = byte; };
  70. template<> struct __byte_operand<char32_t> { using __type = byte; };
  71. template<> struct __byte_operand<short> { using __type = byte; };
  72. template<> struct __byte_operand<unsigned short> { using __type = byte; };
  73. template<> struct __byte_operand<int> { using __type = byte; };
  74. template<> struct __byte_operand<unsigned int> { using __type = byte; };
  75. template<> struct __byte_operand<long> { using __type = byte; };
  76. template<> struct __byte_operand<unsigned long> { using __type = byte; };
  77. template<> struct __byte_operand<long long> { using __type = byte; };
  78. template<> struct __byte_operand<unsigned long long> { using __type = byte; };
  79. #if defined(__GLIBCXX_TYPE_INT_N_0)
  80. template<> struct __byte_operand<__GLIBCXX_TYPE_INT_N_0>
  81. { using __type = byte; };
  82. template<> struct __byte_operand<unsigned __GLIBCXX_TYPE_INT_N_0>
  83. { using __type = byte; };
  84. #endif
  85. #if defined(__GLIBCXX_TYPE_INT_N_1)
  86. template<> struct __byte_operand<__GLIBCXX_TYPE_INT_N_1>
  87. { using __type = byte; };
  88. template<> struct __byte_operand<unsigned __GLIBCXX_TYPE_INT_N_1>
  89. { using __type = byte; };
  90. #endif
  91. #if defined(__GLIBCXX_TYPE_INT_N_2)
  92. template<> struct __byte_operand<__GLIBCXX_TYPE_INT_N_2>
  93. { using __type = byte; };
  94. template<> struct __byte_operand<unsigned __GLIBCXX_TYPE_INT_N_2>
  95. { using __type = byte; };
  96. #endif
  97. template<typename _IntegerType>
  98. struct __byte_operand<const _IntegerType>
  99. : __byte_operand<_IntegerType> { };
  100. template<typename _IntegerType>
  101. struct __byte_operand<volatile _IntegerType>
  102. : __byte_operand<_IntegerType> { };
  103. template<typename _IntegerType>
  104. struct __byte_operand<const volatile _IntegerType>
  105. : __byte_operand<_IntegerType> { };
  106. template<typename _IntegerType>
  107. using __byte_op_t = typename __byte_operand<_IntegerType>::__type;
  108. template<typename _IntegerType>
  109. constexpr __byte_op_t<_IntegerType>&
  110. operator<<=(byte& __b, _IntegerType __shift) noexcept
  111. { return __b = byte(static_cast<unsigned char>(__b) << __shift); }
  112. template<typename _IntegerType>
  113. constexpr __byte_op_t<_IntegerType>
  114. operator<<(byte __b, _IntegerType __shift) noexcept
  115. { return byte(static_cast<unsigned char>(__b) << __shift); }
  116. template<typename _IntegerType>
  117. constexpr __byte_op_t<_IntegerType>&
  118. operator>>=(byte& __b, _IntegerType __shift) noexcept
  119. { return __b = byte(static_cast<unsigned char>(__b) >> __shift); }
  120. template<typename _IntegerType>
  121. constexpr __byte_op_t<_IntegerType>
  122. operator>>(byte __b, _IntegerType __shift) noexcept
  123. { return byte(static_cast<unsigned char>(__b) >> __shift); }
  124. constexpr byte&
  125. operator|=(byte& __l, byte __r) noexcept
  126. {
  127. return __l =
  128. byte(static_cast<unsigned char>(__l) | static_cast<unsigned char>(__r));
  129. }
  130. constexpr byte
  131. operator|(byte __l, byte __r) noexcept
  132. {
  133. return
  134. byte(static_cast<unsigned char>(__l) | static_cast<unsigned char>(__r));
  135. }
  136. constexpr byte&
  137. operator&=(byte& __l, byte __r) noexcept
  138. {
  139. return __l =
  140. byte(static_cast<unsigned char>(__l) & static_cast<unsigned char>(__r));
  141. }
  142. constexpr byte
  143. operator&(byte __l, byte __r) noexcept
  144. {
  145. return
  146. byte(static_cast<unsigned char>(__l) & static_cast<unsigned char>(__r));
  147. }
  148. constexpr byte&
  149. operator^=(byte& __l, byte __r) noexcept
  150. {
  151. return __l =
  152. byte(static_cast<unsigned char>(__l) ^ static_cast<unsigned char>(__r));
  153. }
  154. constexpr byte
  155. operator^(byte __l, byte __r) noexcept
  156. {
  157. return
  158. byte(static_cast<unsigned char>(__l) ^ static_cast<unsigned char>(__r));
  159. }
  160. constexpr byte
  161. operator~(byte __b) noexcept
  162. { return byte(~static_cast<unsigned char>(__b)); }
  163. template<typename _IntegerType>
  164. constexpr _IntegerType
  165. to_integer(__byte_op_t<_IntegerType> __b) noexcept
  166. { return _IntegerType(__b); }
  167. _GLIBCXX_END_NAMESPACE_VERSION
  168. } // namespace std
  169. #endif // C++17
  170. } // extern "C++"
  171. #endif // _GLIBCXX_CSTDDEF