annotate libstdc++-v3/include/std/system_error @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // <system_error> -*- C++ -*-
kono
parents:
diff changeset
2
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
3 // Copyright (C) 2007-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
4 //
kono
parents:
diff changeset
5 // This file is part of the GNU ISO C++ Library. This library is free
kono
parents:
diff changeset
6 // software; you can redistribute it and/or modify it under the
kono
parents:
diff changeset
7 // terms of the GNU General Public License as published by the
kono
parents:
diff changeset
8 // Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
9 // any later version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 // This library is distributed in the hope that it will be useful,
kono
parents:
diff changeset
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
14 // GNU General Public License for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 // Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 // permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 // 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 // You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 // a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 // <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 /** @file include/system_error
kono
parents:
diff changeset
26 * This is a Standard C++ Library header.
kono
parents:
diff changeset
27 */
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 #ifndef _GLIBCXX_SYSTEM_ERROR
kono
parents:
diff changeset
30 #define _GLIBCXX_SYSTEM_ERROR 1
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 #pragma GCC system_header
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 #if __cplusplus < 201103L
kono
parents:
diff changeset
35 # include <bits/c++0x_warning.h>
kono
parents:
diff changeset
36 #else
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 #include <bits/c++config.h>
kono
parents:
diff changeset
39 #include <bits/error_constants.h>
kono
parents:
diff changeset
40 #include <iosfwd>
kono
parents:
diff changeset
41 #include <stdexcept>
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 namespace std _GLIBCXX_VISIBILITY(default)
kono
parents:
diff changeset
44 {
kono
parents:
diff changeset
45 _GLIBCXX_BEGIN_NAMESPACE_VERSION
kono
parents:
diff changeset
46
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
47 /** @addtogroup diagnostics
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
48 * @{
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
49 */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
50
111
kono
parents:
diff changeset
51 class error_code;
kono
parents:
diff changeset
52 class error_condition;
kono
parents:
diff changeset
53 class system_error;
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 /// is_error_code_enum
kono
parents:
diff changeset
56 template<typename _Tp>
kono
parents:
diff changeset
57 struct is_error_code_enum : public false_type { };
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 /// is_error_condition_enum
kono
parents:
diff changeset
60 template<typename _Tp>
kono
parents:
diff changeset
61 struct is_error_condition_enum : public false_type { };
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 template<>
kono
parents:
diff changeset
64 struct is_error_condition_enum<errc>
kono
parents:
diff changeset
65 : public true_type { };
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 #if __cplusplus > 201402L
kono
parents:
diff changeset
68 template <typename _Tp>
kono
parents:
diff changeset
69 inline constexpr bool is_error_code_enum_v =
kono
parents:
diff changeset
70 is_error_code_enum<_Tp>::value;
kono
parents:
diff changeset
71 template <typename _Tp>
kono
parents:
diff changeset
72 inline constexpr bool is_error_condition_enum_v =
kono
parents:
diff changeset
73 is_error_condition_enum<_Tp>::value;
kono
parents:
diff changeset
74 #endif // C++17
kono
parents:
diff changeset
75 inline namespace _V2 {
kono
parents:
diff changeset
76
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
77 /** Abstract base class for types defining a category of error codes.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
78 *
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
79 * An error category defines a context that give meaning to the integer
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
80 * stored in an `error_code` or `error_condition` object. For example,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
81 * the standard `errno` constants such a `EINVAL` and `ENOMEM` are
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
82 * associated with the "generic" category and other OS-specific error
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
83 * numbers are associated with the "system" category, but a user-defined
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
84 * category might give different meanings to the same numerical values.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
85 */
111
kono
parents:
diff changeset
86 class error_category
kono
parents:
diff changeset
87 {
kono
parents:
diff changeset
88 public:
kono
parents:
diff changeset
89 constexpr error_category() noexcept = default;
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 virtual ~error_category();
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 error_category(const error_category&) = delete;
kono
parents:
diff changeset
94 error_category& operator=(const error_category&) = delete;
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 virtual const char*
kono
parents:
diff changeset
97 name() const noexcept = 0;
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 // We need two different virtual functions here, one returning a
kono
parents:
diff changeset
100 // COW string and one returning an SSO string. Their positions in the
kono
parents:
diff changeset
101 // vtable must be consistent for dynamic dispatch to work, but which one
kono
parents:
diff changeset
102 // the name "message()" finds depends on which ABI the caller is using.
kono
parents:
diff changeset
103 #if _GLIBCXX_USE_CXX11_ABI
kono
parents:
diff changeset
104 private:
kono
parents:
diff changeset
105 _GLIBCXX_DEFAULT_ABI_TAG
kono
parents:
diff changeset
106 virtual __cow_string
kono
parents:
diff changeset
107 _M_message(int) const;
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 public:
kono
parents:
diff changeset
110 _GLIBCXX_DEFAULT_ABI_TAG
kono
parents:
diff changeset
111 virtual string
kono
parents:
diff changeset
112 message(int) const = 0;
kono
parents:
diff changeset
113 #else
kono
parents:
diff changeset
114 virtual string
kono
parents:
diff changeset
115 message(int) const = 0;
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 private:
kono
parents:
diff changeset
118 virtual __sso_string
kono
parents:
diff changeset
119 _M_message(int) const;
kono
parents:
diff changeset
120 #endif
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 public:
kono
parents:
diff changeset
123 virtual error_condition
kono
parents:
diff changeset
124 default_error_condition(int __i) const noexcept;
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 virtual bool
kono
parents:
diff changeset
127 equivalent(int __i, const error_condition& __cond) const noexcept;
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 virtual bool
158
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
130 equivalent(const error_code& __code0, int __i) const noexcept;
111
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 bool
kono
parents:
diff changeset
133 operator<(const error_category& __other) const noexcept
kono
parents:
diff changeset
134 { return less<const error_category*>()(this, &__other); }
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 bool
kono
parents:
diff changeset
137 operator==(const error_category& __other) const noexcept
kono
parents:
diff changeset
138 { return this == &__other; }
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 bool
kono
parents:
diff changeset
141 operator!=(const error_category& __other) const noexcept
kono
parents:
diff changeset
142 { return this != &__other; }
kono
parents:
diff changeset
143 };
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 // DR 890.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
146
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
147 /// Error category for `errno` error codes.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
148 _GLIBCXX_CONST const error_category& generic_category() noexcept;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
149
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
150 /// Error category for other error codes defined by the OS.
111
kono
parents:
diff changeset
151 _GLIBCXX_CONST const error_category& system_category() noexcept;
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 } // end inline namespace
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 error_code make_error_code(errc) noexcept;
kono
parents:
diff changeset
156
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
157 /** Class error_code
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
158 *
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
159 * This class is a value type storing an integer error number and a
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
160 * category that gives meaning to the error number. Typically this is done
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
161 * close the the point where the error happens, to capture the original
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
162 * error value.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
163 *
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
164 * An `error_code` object can be used to store the original error value
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
165 * emitted by some subsystem, with a category relevant to the subsystem.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
166 * For example, errors from POSIX library functions can be represented by
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
167 * an `errno` value and the "generic" category, but errors from an HTTP
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
168 * library might be represented by an HTTP response status code (e.g. 404)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
169 * and a custom category defined by the library.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
170 */
111
kono
parents:
diff changeset
171 struct error_code
kono
parents:
diff changeset
172 {
kono
parents:
diff changeset
173 error_code() noexcept
kono
parents:
diff changeset
174 : _M_value(0), _M_cat(&system_category()) { }
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 error_code(int __v, const error_category& __cat) noexcept
kono
parents:
diff changeset
177 : _M_value(__v), _M_cat(&__cat) { }
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 template<typename _ErrorCodeEnum, typename = typename
kono
parents:
diff changeset
180 enable_if<is_error_code_enum<_ErrorCodeEnum>::value>::type>
kono
parents:
diff changeset
181 error_code(_ErrorCodeEnum __e) noexcept
kono
parents:
diff changeset
182 { *this = make_error_code(__e); }
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 void
kono
parents:
diff changeset
185 assign(int __v, const error_category& __cat) noexcept
kono
parents:
diff changeset
186 {
kono
parents:
diff changeset
187 _M_value = __v;
kono
parents:
diff changeset
188 _M_cat = &__cat;
kono
parents:
diff changeset
189 }
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 void
kono
parents:
diff changeset
192 clear() noexcept
kono
parents:
diff changeset
193 { assign(0, system_category()); }
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 // DR 804.
kono
parents:
diff changeset
196 template<typename _ErrorCodeEnum>
kono
parents:
diff changeset
197 typename enable_if<is_error_code_enum<_ErrorCodeEnum>::value,
kono
parents:
diff changeset
198 error_code&>::type
kono
parents:
diff changeset
199 operator=(_ErrorCodeEnum __e) noexcept
kono
parents:
diff changeset
200 { return *this = make_error_code(__e); }
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 int
kono
parents:
diff changeset
203 value() const noexcept { return _M_value; }
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 const error_category&
kono
parents:
diff changeset
206 category() const noexcept { return *_M_cat; }
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 error_condition
kono
parents:
diff changeset
209 default_error_condition() const noexcept;
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 _GLIBCXX_DEFAULT_ABI_TAG
kono
parents:
diff changeset
212 string
kono
parents:
diff changeset
213 message() const
kono
parents:
diff changeset
214 { return category().message(value()); }
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 explicit operator bool() const noexcept
kono
parents:
diff changeset
217 { return _M_value != 0; }
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 // DR 804.
kono
parents:
diff changeset
220 private:
kono
parents:
diff changeset
221 int _M_value;
kono
parents:
diff changeset
222 const error_category* _M_cat;
kono
parents:
diff changeset
223 };
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 // 19.4.2.6 non-member functions
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
226
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
227 /// @relates error_code @{
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
228
111
kono
parents:
diff changeset
229 inline error_code
kono
parents:
diff changeset
230 make_error_code(errc __e) noexcept
kono
parents:
diff changeset
231 { return error_code(static_cast<int>(__e), generic_category()); }
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 inline bool
kono
parents:
diff changeset
234 operator<(const error_code& __lhs, const error_code& __rhs) noexcept
kono
parents:
diff changeset
235 {
kono
parents:
diff changeset
236 return (__lhs.category() < __rhs.category()
kono
parents:
diff changeset
237 || (__lhs.category() == __rhs.category()
kono
parents:
diff changeset
238 && __lhs.value() < __rhs.value()));
kono
parents:
diff changeset
239 }
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 template<typename _CharT, typename _Traits>
kono
parents:
diff changeset
242 basic_ostream<_CharT, _Traits>&
kono
parents:
diff changeset
243 operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)
kono
parents:
diff changeset
244 { return (__os << __e.category().name() << ':' << __e.value()); }
kono
parents:
diff changeset
245
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
246 // @}
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
247
111
kono
parents:
diff changeset
248 error_condition make_error_condition(errc) noexcept;
kono
parents:
diff changeset
249
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
250 /** Class error_condition
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
251 *
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
252 * This class represents error conditions that may be visible at an API
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
253 * boundary. Different `error_code` values that can occur within a library
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
254 * or module might map to the same `error_condition`.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
255 *
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
256 * An `error_condition` represents something that the program can test for,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
257 * and subsequently take appropriate action.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
258 */
111
kono
parents:
diff changeset
259 struct error_condition
kono
parents:
diff changeset
260 {
kono
parents:
diff changeset
261 error_condition() noexcept
kono
parents:
diff changeset
262 : _M_value(0), _M_cat(&generic_category()) { }
kono
parents:
diff changeset
263
kono
parents:
diff changeset
264 error_condition(int __v, const error_category& __cat) noexcept
kono
parents:
diff changeset
265 : _M_value(__v), _M_cat(&__cat) { }
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 template<typename _ErrorConditionEnum, typename = typename
kono
parents:
diff changeset
268 enable_if<is_error_condition_enum<_ErrorConditionEnum>::value>::type>
kono
parents:
diff changeset
269 error_condition(_ErrorConditionEnum __e) noexcept
kono
parents:
diff changeset
270 { *this = make_error_condition(__e); }
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 void
kono
parents:
diff changeset
273 assign(int __v, const error_category& __cat) noexcept
kono
parents:
diff changeset
274 {
kono
parents:
diff changeset
275 _M_value = __v;
kono
parents:
diff changeset
276 _M_cat = &__cat;
kono
parents:
diff changeset
277 }
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 // DR 804.
kono
parents:
diff changeset
280 template<typename _ErrorConditionEnum>
kono
parents:
diff changeset
281 typename enable_if<is_error_condition_enum
kono
parents:
diff changeset
282 <_ErrorConditionEnum>::value, error_condition&>::type
kono
parents:
diff changeset
283 operator=(_ErrorConditionEnum __e) noexcept
kono
parents:
diff changeset
284 { return *this = make_error_condition(__e); }
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 void
kono
parents:
diff changeset
287 clear() noexcept
kono
parents:
diff changeset
288 { assign(0, generic_category()); }
kono
parents:
diff changeset
289
kono
parents:
diff changeset
290 // 19.4.3.4 observers
kono
parents:
diff changeset
291 int
kono
parents:
diff changeset
292 value() const noexcept { return _M_value; }
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 const error_category&
kono
parents:
diff changeset
295 category() const noexcept { return *_M_cat; }
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 _GLIBCXX_DEFAULT_ABI_TAG
kono
parents:
diff changeset
298 string
kono
parents:
diff changeset
299 message() const
kono
parents:
diff changeset
300 { return category().message(value()); }
kono
parents:
diff changeset
301
kono
parents:
diff changeset
302 explicit operator bool() const noexcept
kono
parents:
diff changeset
303 { return _M_value != 0; }
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 // DR 804.
kono
parents:
diff changeset
306 private:
kono
parents:
diff changeset
307 int _M_value;
kono
parents:
diff changeset
308 const error_category* _M_cat;
kono
parents:
diff changeset
309 };
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 // 19.4.3.6 non-member functions
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
312
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
313 /// Create an `error_condition` representing a standard `errc` condition.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
314 /// @relates error_condition
111
kono
parents:
diff changeset
315 inline error_condition
kono
parents:
diff changeset
316 make_error_condition(errc __e) noexcept
kono
parents:
diff changeset
317 { return error_condition(static_cast<int>(__e), generic_category()); }
kono
parents:
diff changeset
318
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
319 /// Define an ordering for error_condition objects.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
320 /// @relates error_condition
111
kono
parents:
diff changeset
321 inline bool
kono
parents:
diff changeset
322 operator<(const error_condition& __lhs,
kono
parents:
diff changeset
323 const error_condition& __rhs) noexcept
kono
parents:
diff changeset
324 {
kono
parents:
diff changeset
325 return (__lhs.category() < __rhs.category()
kono
parents:
diff changeset
326 || (__lhs.category() == __rhs.category()
kono
parents:
diff changeset
327 && __lhs.value() < __rhs.value()));
kono
parents:
diff changeset
328 }
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 // 19.4.4 Comparison operators
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
331
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
332 /// @relates error_code
111
kono
parents:
diff changeset
333 inline bool
kono
parents:
diff changeset
334 operator==(const error_code& __lhs, const error_code& __rhs) noexcept
kono
parents:
diff changeset
335 { return (__lhs.category() == __rhs.category()
kono
parents:
diff changeset
336 && __lhs.value() == __rhs.value()); }
kono
parents:
diff changeset
337
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
338 /// @relates error_code
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
339 /// @relates error_condition
111
kono
parents:
diff changeset
340 inline bool
kono
parents:
diff changeset
341 operator==(const error_code& __lhs, const error_condition& __rhs) noexcept
kono
parents:
diff changeset
342 {
kono
parents:
diff changeset
343 return (__lhs.category().equivalent(__lhs.value(), __rhs)
kono
parents:
diff changeset
344 || __rhs.category().equivalent(__lhs, __rhs.value()));
kono
parents:
diff changeset
345 }
kono
parents:
diff changeset
346
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
347 /// @relates error_code
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
348 /// @relates error_condition
111
kono
parents:
diff changeset
349 inline bool
kono
parents:
diff changeset
350 operator==(const error_condition& __lhs, const error_code& __rhs) noexcept
kono
parents:
diff changeset
351 {
kono
parents:
diff changeset
352 return (__rhs.category().equivalent(__rhs.value(), __lhs)
kono
parents:
diff changeset
353 || __lhs.category().equivalent(__rhs, __lhs.value()));
kono
parents:
diff changeset
354 }
kono
parents:
diff changeset
355
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
356 /// @relates error_condition
111
kono
parents:
diff changeset
357 inline bool
kono
parents:
diff changeset
358 operator==(const error_condition& __lhs,
kono
parents:
diff changeset
359 const error_condition& __rhs) noexcept
kono
parents:
diff changeset
360 {
kono
parents:
diff changeset
361 return (__lhs.category() == __rhs.category()
kono
parents:
diff changeset
362 && __lhs.value() == __rhs.value());
kono
parents:
diff changeset
363 }
kono
parents:
diff changeset
364
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
365 /// @relates error_code
111
kono
parents:
diff changeset
366 inline bool
kono
parents:
diff changeset
367 operator!=(const error_code& __lhs, const error_code& __rhs) noexcept
kono
parents:
diff changeset
368 { return !(__lhs == __rhs); }
kono
parents:
diff changeset
369
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
370 /// @relates error_code
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
371 /// @relates error_condition
111
kono
parents:
diff changeset
372 inline bool
kono
parents:
diff changeset
373 operator!=(const error_code& __lhs, const error_condition& __rhs) noexcept
kono
parents:
diff changeset
374 { return !(__lhs == __rhs); }
kono
parents:
diff changeset
375
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
376 /// @relates error_code
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
377 /// @relates error_condition
111
kono
parents:
diff changeset
378 inline bool
kono
parents:
diff changeset
379 operator!=(const error_condition& __lhs, const error_code& __rhs) noexcept
kono
parents:
diff changeset
380 { return !(__lhs == __rhs); }
kono
parents:
diff changeset
381
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
382 /// @relates error_condition
111
kono
parents:
diff changeset
383 inline bool
kono
parents:
diff changeset
384 operator!=(const error_condition& __lhs,
kono
parents:
diff changeset
385 const error_condition& __rhs) noexcept
kono
parents:
diff changeset
386 { return !(__lhs == __rhs); }
kono
parents:
diff changeset
387
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 /**
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
390 * @brief An exception type that includes an `error_code` value.
111
kono
parents:
diff changeset
391 *
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
392 * Typically used to report errors from the operating system and other
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
393 * low-level APIs.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
394 *
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
395 * @ingroup exceptions
111
kono
parents:
diff changeset
396 */
kono
parents:
diff changeset
397 class system_error : public std::runtime_error
kono
parents:
diff changeset
398 {
kono
parents:
diff changeset
399 private:
kono
parents:
diff changeset
400 error_code _M_code;
kono
parents:
diff changeset
401
kono
parents:
diff changeset
402 public:
kono
parents:
diff changeset
403 system_error(error_code __ec = error_code())
kono
parents:
diff changeset
404 : runtime_error(__ec.message()), _M_code(__ec) { }
kono
parents:
diff changeset
405
kono
parents:
diff changeset
406 system_error(error_code __ec, const string& __what)
kono
parents:
diff changeset
407 : runtime_error(__what + ": " + __ec.message()), _M_code(__ec) { }
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 system_error(error_code __ec, const char* __what)
kono
parents:
diff changeset
410 : runtime_error(__what + (": " + __ec.message())), _M_code(__ec) { }
kono
parents:
diff changeset
411
kono
parents:
diff changeset
412 system_error(int __v, const error_category& __ecat, const char* __what)
kono
parents:
diff changeset
413 : system_error(error_code(__v, __ecat), __what) { }
kono
parents:
diff changeset
414
kono
parents:
diff changeset
415 system_error(int __v, const error_category& __ecat)
kono
parents:
diff changeset
416 : runtime_error(error_code(__v, __ecat).message()),
kono
parents:
diff changeset
417 _M_code(__v, __ecat) { }
kono
parents:
diff changeset
418
kono
parents:
diff changeset
419 system_error(int __v, const error_category& __ecat, const string& __what)
kono
parents:
diff changeset
420 : runtime_error(__what + ": " + error_code(__v, __ecat).message()),
kono
parents:
diff changeset
421 _M_code(__v, __ecat) { }
kono
parents:
diff changeset
422
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
423 #if __cplusplus >= 201103L
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
424 system_error (const system_error &) = default;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
425 system_error &operator= (const system_error &) = default;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
426 #endif
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
427
111
kono
parents:
diff changeset
428 virtual ~system_error() noexcept;
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 const error_code&
kono
parents:
diff changeset
431 code() const noexcept { return _M_code; }
kono
parents:
diff changeset
432 };
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 _GLIBCXX_END_NAMESPACE_VERSION
kono
parents:
diff changeset
435 } // namespace
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 #include <bits/functional_hash.h>
kono
parents:
diff changeset
438
kono
parents:
diff changeset
439 namespace std _GLIBCXX_VISIBILITY(default)
kono
parents:
diff changeset
440 {
kono
parents:
diff changeset
441 _GLIBCXX_BEGIN_NAMESPACE_VERSION
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 #ifndef _GLIBCXX_COMPATIBILITY_CXX0X
kono
parents:
diff changeset
444 // DR 1182.
kono
parents:
diff changeset
445 /// std::hash specialization for error_code.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
446 /// @relates error_code
111
kono
parents:
diff changeset
447 template<>
kono
parents:
diff changeset
448 struct hash<error_code>
kono
parents:
diff changeset
449 : public __hash_base<size_t, error_code>
kono
parents:
diff changeset
450 {
kono
parents:
diff changeset
451 size_t
kono
parents:
diff changeset
452 operator()(const error_code& __e) const noexcept
kono
parents:
diff changeset
453 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
454 const size_t __tmp = std::_Hash_impl::hash(__e.value());
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
455 return std::_Hash_impl::__hash_combine(&__e.category(), __tmp);
111
kono
parents:
diff changeset
456 }
kono
parents:
diff changeset
457 };
kono
parents:
diff changeset
458 #endif // _GLIBCXX_COMPATIBILITY_CXX0X
kono
parents:
diff changeset
459
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
460 #if __cplusplus >= 201703L
111
kono
parents:
diff changeset
461 // DR 2686.
kono
parents:
diff changeset
462 /// std::hash specialization for error_condition.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
463 /// @relates error_condition
111
kono
parents:
diff changeset
464 template<>
kono
parents:
diff changeset
465 struct hash<error_condition>
kono
parents:
diff changeset
466 : public __hash_base<size_t, error_condition>
kono
parents:
diff changeset
467 {
kono
parents:
diff changeset
468 size_t
kono
parents:
diff changeset
469 operator()(const error_condition& __e) const noexcept
kono
parents:
diff changeset
470 {
kono
parents:
diff changeset
471 const size_t __tmp = std::_Hash_impl::hash(__e.value());
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
472 return std::_Hash_impl::__hash_combine(&__e.category(), __tmp);
111
kono
parents:
diff changeset
473 }
kono
parents:
diff changeset
474 };
kono
parents:
diff changeset
475 #endif
kono
parents:
diff changeset
476
kono
parents:
diff changeset
477 _GLIBCXX_END_NAMESPACE_VERSION
kono
parents:
diff changeset
478 } // namespace
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480 #endif // C++11
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482 #endif // _GLIBCXX_SYSTEM_ERROR