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