]>
Commit | Line | Data |
---|---|---|
0646d8a3 BK |
1 | // <system_error> -*- C++ -*- |
2 | ||
7adcbafe | 3 | // Copyright (C) 2007-2022 Free Software Foundation, Inc. |
0646d8a3 BK |
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 | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
0646d8a3 BK |
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 | ||
748086b7 JJ |
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/>. | |
0646d8a3 | 24 | |
f910786b | 25 | /** @file include/system_error |
0646d8a3 BK |
26 | * This is a Standard C++ Library header. |
27 | */ | |
28 | ||
29 | #ifndef _GLIBCXX_SYSTEM_ERROR | |
30 | #define _GLIBCXX_SYSTEM_ERROR 1 | |
31 | ||
32 | #pragma GCC system_header | |
33 | ||
734f5023 | 34 | #if __cplusplus < 201103L |
ab65a4c7 | 35 | # include <bits/c++0x_warning.h> |
57317d2a | 36 | #else |
0646d8a3 BK |
37 | |
38 | #include <bits/c++config.h> | |
e4bf5dfc | 39 | #include <bits/error_constants.h> |
0646d8a3 BK |
40 | #include <iosfwd> |
41 | #include <stdexcept> | |
4be779f5 JW |
42 | #if __cplusplus > 201703L |
43 | # include <compare> | |
44 | #endif | |
0646d8a3 | 45 | |
12ffa228 BK |
46 | namespace std _GLIBCXX_VISIBILITY(default) |
47 | { | |
48 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
0646d8a3 | 49 | |
2f7f1aca | 50 | /** @addtogroup diagnostics |
f2ce64b5 | 51 | * @{ |
2f7f1aca JW |
52 | */ |
53 | ||
0646d8a3 | 54 | class error_code; |
70593ad2 | 55 | class error_condition; |
70593ad2 BK |
56 | class system_error; |
57 | ||
58 | /// is_error_code_enum | |
c9faf465 | 59 | template<typename _Tp> |
70593ad2 BK |
60 | struct is_error_code_enum : public false_type { }; |
61 | ||
70593ad2 | 62 | /// is_error_condition_enum |
c9faf465 | 63 | template<typename _Tp> |
70593ad2 BK |
64 | struct is_error_condition_enum : public false_type { }; |
65 | ||
33ac58d5 | 66 | template<> |
92010a79 | 67 | struct is_error_condition_enum<errc> |
70593ad2 | 68 | : public true_type { }; |
0646d8a3 | 69 | |
137422c8 VV |
70 | #if __cplusplus > 201402L |
71 | template <typename _Tp> | |
288695f7 DK |
72 | inline constexpr bool is_error_code_enum_v = |
73 | is_error_code_enum<_Tp>::value; | |
137422c8 | 74 | template <typename _Tp> |
288695f7 | 75 | inline constexpr bool is_error_condition_enum_v = |
137422c8 VV |
76 | is_error_condition_enum<_Tp>::value; |
77 | #endif // C++17 | |
f2ce64b5 JW |
78 | /// @} |
79 | ||
34a2b755 | 80 | inline namespace _V2 { |
0646d8a3 | 81 | |
f2ce64b5 JW |
82 | /** @addtogroup diagnostics |
83 | * @{ | |
84 | */ | |
85 | ||
2f7f1aca JW |
86 | /** Abstract base class for types defining a category of error codes. |
87 | * | |
88 | * An error category defines a context that give meaning to the integer | |
5b503252 | 89 | * stored in an `error_code` or `error_condition` object. For example, |
2f7f1aca JW |
90 | * the standard `errno` constants such a `EINVAL` and `ENOMEM` are |
91 | * associated with the "generic" category and other OS-specific error | |
92 | * numbers are associated with the "system" category, but a user-defined | |
93 | * category might give different meanings to the same numerical values. | |
f2ce64b5 JW |
94 | * |
95 | * @since C++11 | |
2f7f1aca | 96 | */ |
92010a79 | 97 | class error_category |
0646d8a3 | 98 | { |
f891e5d1 | 99 | public: |
f891e5d1 | 100 | constexpr error_category() noexcept = default; |
92010a79 | 101 | |
f891e5d1 | 102 | virtual ~error_category(); |
92010a79 CF |
103 | |
104 | error_category(const error_category&) = delete; | |
105 | error_category& operator=(const error_category&) = delete; | |
0646d8a3 | 106 | |
33ac58d5 | 107 | virtual const char* |
cd88bb8c | 108 | name() const noexcept = 0; |
70593ad2 | 109 | |
34a2b755 JW |
110 | // We need two different virtual functions here, one returning a |
111 | // COW string and one returning an SSO string. Their positions in the | |
112 | // vtable must be consistent for dynamic dispatch to work, but which one | |
113 | // the name "message()" finds depends on which ABI the caller is using. | |
114 | #if _GLIBCXX_USE_CXX11_ABI | |
115 | private: | |
116 | _GLIBCXX_DEFAULT_ABI_TAG | |
117 | virtual __cow_string | |
118 | _M_message(int) const; | |
119 | ||
120 | public: | |
121 | _GLIBCXX_DEFAULT_ABI_TAG | |
122 | virtual string | |
123 | message(int) const = 0; | |
124 | #else | |
33ac58d5 | 125 | virtual string |
70593ad2 BK |
126 | message(int) const = 0; |
127 | ||
34a2b755 JW |
128 | private: |
129 | virtual __sso_string | |
130 | _M_message(int) const; | |
131 | #endif | |
132 | ||
133 | public: | |
70593ad2 | 134 | virtual error_condition |
cd88bb8c | 135 | default_error_condition(int __i) const noexcept; |
70593ad2 | 136 | |
33ac58d5 | 137 | virtual bool |
cd88bb8c | 138 | equivalent(int __i, const error_condition& __cond) const noexcept; |
70593ad2 | 139 | |
33ac58d5 | 140 | virtual bool |
cd88bb8c | 141 | equivalent(const error_code& __code, int __i) const noexcept; |
70593ad2 | 142 | |
33ac58d5 | 143 | bool |
cd88bb8c | 144 | operator==(const error_category& __other) const noexcept |
0646d8a3 BK |
145 | { return this == &__other; } |
146 | ||
4be779f5 JW |
147 | #if __cpp_lib_three_way_comparison |
148 | strong_ordering | |
149 | operator<=>(const error_category& __rhs) const noexcept | |
150 | { return std::compare_three_way()(this, &__rhs); } | |
151 | #else | |
33ac58d5 | 152 | bool |
cd88bb8c | 153 | operator!=(const error_category& __other) const noexcept |
0646d8a3 | 154 | { return this != &__other; } |
4be779f5 JW |
155 | |
156 | bool | |
157 | operator<(const error_category& __other) const noexcept | |
158 | { return less<const error_category*>()(this, &__other); } | |
159 | #endif | |
0646d8a3 BK |
160 | }; |
161 | ||
92010a79 | 162 | // DR 890. |
2f7f1aca JW |
163 | |
164 | /// Error category for `errno` error codes. | |
cd88bb8c | 165 | _GLIBCXX_CONST const error_category& generic_category() noexcept; |
70593ad2 | 166 | |
2f7f1aca JW |
167 | /// Error category for other error codes defined by the OS. |
168 | _GLIBCXX_CONST const error_category& system_category() noexcept; | |
169 | ||
f2ce64b5 | 170 | /// @} |
34a2b755 JW |
171 | } // end inline namespace |
172 | ||
f2ce64b5 JW |
173 | /** @addtogroup diagnostics |
174 | * @{ | |
175 | */ | |
176 | ||
cd88bb8c | 177 | error_code make_error_code(errc) noexcept; |
bb81f9a0 | 178 | |
2f7f1aca JW |
179 | /** Class error_code |
180 | * | |
181 | * This class is a value type storing an integer error number and a | |
182 | * category that gives meaning to the error number. Typically this is done | |
183 | * close the the point where the error happens, to capture the original | |
184 | * error value. | |
185 | * | |
186 | * An `error_code` object can be used to store the original error value | |
187 | * emitted by some subsystem, with a category relevant to the subsystem. | |
188 | * For example, errors from POSIX library functions can be represented by | |
189 | * an `errno` value and the "generic" category, but errors from an HTTP | |
190 | * library might be represented by an HTTP response status code (e.g. 404) | |
191 | * and a custom category defined by the library. | |
f2ce64b5 JW |
192 | * |
193 | * @since C++11 | |
194 | * @ingroup diagnostics | |
2f7f1aca | 195 | */ |
0e5abeb0 | 196 | class error_code |
0646d8a3 | 197 | { |
0e5abeb0 | 198 | public: |
cd88bb8c | 199 | error_code() noexcept |
bb81f9a0 | 200 | : _M_value(0), _M_cat(&system_category()) { } |
0646d8a3 | 201 | |
cd88bb8c | 202 | error_code(int __v, const error_category& __cat) noexcept |
0646d8a3 BK |
203 | : _M_value(__v), _M_cat(&__cat) { } |
204 | ||
cd88bb8c PC |
205 | template<typename _ErrorCodeEnum, typename = typename |
206 | enable_if<is_error_code_enum<_ErrorCodeEnum>::value>::type> | |
207 | error_code(_ErrorCodeEnum __e) noexcept | |
bb81f9a0 | 208 | { *this = make_error_code(__e); } |
0646d8a3 | 209 | |
33ac58d5 | 210 | void |
cd88bb8c | 211 | assign(int __v, const error_category& __cat) noexcept |
0646d8a3 BK |
212 | { |
213 | _M_value = __v; | |
33ac58d5 | 214 | _M_cat = &__cat; |
0646d8a3 BK |
215 | } |
216 | ||
33ac58d5 | 217 | void |
cd88bb8c | 218 | clear() noexcept |
9b3003d5 | 219 | { assign(0, system_category()); } |
70593ad2 | 220 | |
4661c8fd | 221 | // DR 804. |
70593ad2 | 222 | template<typename _ErrorCodeEnum> |
4661c8fd PC |
223 | typename enable_if<is_error_code_enum<_ErrorCodeEnum>::value, |
224 | error_code&>::type | |
cd88bb8c | 225 | operator=(_ErrorCodeEnum __e) noexcept |
bb81f9a0 | 226 | { return *this = make_error_code(__e); } |
0646d8a3 BK |
227 | |
228 | int | |
cd88bb8c | 229 | value() const noexcept { return _M_value; } |
33ac58d5 JW |
230 | |
231 | const error_category& | |
cd88bb8c | 232 | category() const noexcept { return *_M_cat; } |
0646d8a3 | 233 | |
33ac58d5 | 234 | error_condition |
cd88bb8c | 235 | default_error_condition() const noexcept; |
70593ad2 | 236 | |
34a2b755 | 237 | _GLIBCXX_DEFAULT_ABI_TAG |
33ac58d5 | 238 | string |
70593ad2 BK |
239 | message() const |
240 | { return category().message(value()); } | |
0646d8a3 | 241 | |
cd88bb8c | 242 | explicit operator bool() const noexcept |
2eb57e54 | 243 | { return _M_value != 0; } |
0646d8a3 | 244 | |
4661c8fd | 245 | // DR 804. |
0646d8a3 BK |
246 | private: |
247 | int _M_value; | |
248 | const error_category* _M_cat; | |
249 | }; | |
250 | ||
92010a79 | 251 | // 19.4.2.6 non-member functions |
2f7f1aca JW |
252 | |
253 | /// @relates error_code @{ | |
254 | ||
92010a79 | 255 | inline error_code |
cd88bb8c | 256 | make_error_code(errc __e) noexcept |
9b3003d5 | 257 | { return error_code(static_cast<int>(__e), generic_category()); } |
92010a79 | 258 | |
4be779f5 JW |
259 | #if __cpp_lib_three_way_comparison |
260 | inline strong_ordering | |
261 | operator<=>(const error_code& __lhs, const error_code& __rhs) noexcept | |
262 | { | |
263 | if (auto __c = __lhs.category() <=> __rhs.category(); __c != 0) | |
264 | return __c; | |
265 | return __lhs.value() <=> __rhs.value(); | |
266 | } | |
267 | #else | |
4661c8fd | 268 | inline bool |
cd88bb8c | 269 | operator<(const error_code& __lhs, const error_code& __rhs) noexcept |
33ac58d5 | 270 | { |
4661c8fd PC |
271 | return (__lhs.category() < __rhs.category() |
272 | || (__lhs.category() == __rhs.category() | |
273 | && __lhs.value() < __rhs.value())); | |
274 | } | |
4be779f5 | 275 | #endif |
70593ad2 | 276 | |
4661c8fd PC |
277 | template<typename _CharT, typename _Traits> |
278 | basic_ostream<_CharT, _Traits>& | |
279 | operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e) | |
280 | { return (__os << __e.category().name() << ':' << __e.value()); } | |
70593ad2 | 281 | |
f0b88346 | 282 | /// @} |
2f7f1aca | 283 | |
cd88bb8c | 284 | error_condition make_error_condition(errc) noexcept; |
70593ad2 | 285 | |
2f7f1aca JW |
286 | /** Class error_condition |
287 | * | |
288 | * This class represents error conditions that may be visible at an API | |
289 | * boundary. Different `error_code` values that can occur within a library | |
290 | * or module might map to the same `error_condition`. | |
291 | * | |
292 | * An `error_condition` represents something that the program can test for, | |
293 | * and subsequently take appropriate action. | |
f2ce64b5 JW |
294 | * |
295 | * @since C++11 | |
2f7f1aca | 296 | */ |
0e5abeb0 | 297 | class error_condition |
70593ad2 | 298 | { |
0e5abeb0 | 299 | public: |
cd88bb8c | 300 | error_condition() noexcept |
bb81f9a0 | 301 | : _M_value(0), _M_cat(&generic_category()) { } |
70593ad2 | 302 | |
cd88bb8c | 303 | error_condition(int __v, const error_category& __cat) noexcept |
4661c8fd | 304 | : _M_value(__v), _M_cat(&__cat) { } |
70593ad2 | 305 | |
cd88bb8c PC |
306 | template<typename _ErrorConditionEnum, typename = typename |
307 | enable_if<is_error_condition_enum<_ErrorConditionEnum>::value>::type> | |
308 | error_condition(_ErrorConditionEnum __e) noexcept | |
bb81f9a0 | 309 | { *this = make_error_condition(__e); } |
70593ad2 | 310 | |
4661c8fd | 311 | void |
cd88bb8c | 312 | assign(int __v, const error_category& __cat) noexcept |
4661c8fd PC |
313 | { |
314 | _M_value = __v; | |
315 | _M_cat = &__cat; | |
316 | } | |
70593ad2 | 317 | |
4661c8fd PC |
318 | // DR 804. |
319 | template<typename _ErrorConditionEnum> | |
320 | typename enable_if<is_error_condition_enum | |
321 | <_ErrorConditionEnum>::value, error_condition&>::type | |
cd88bb8c | 322 | operator=(_ErrorConditionEnum __e) noexcept |
bb81f9a0 | 323 | { return *this = make_error_condition(__e); } |
70593ad2 | 324 | |
33ac58d5 | 325 | void |
cd88bb8c | 326 | clear() noexcept |
9b3003d5 | 327 | { assign(0, generic_category()); } |
70593ad2 BK |
328 | |
329 | // 19.4.3.4 observers | |
cd88bb8c PC |
330 | int |
331 | value() const noexcept { return _M_value; } | |
70593ad2 | 332 | |
4661c8fd | 333 | const error_category& |
cd88bb8c | 334 | category() const noexcept { return *_M_cat; } |
70593ad2 | 335 | |
34a2b755 | 336 | _GLIBCXX_DEFAULT_ABI_TAG |
33ac58d5 | 337 | string |
70593ad2 BK |
338 | message() const |
339 | { return category().message(value()); } | |
340 | ||
cd88bb8c | 341 | explicit operator bool() const noexcept |
2eb57e54 | 342 | { return _M_value != 0; } |
70593ad2 | 343 | |
4661c8fd | 344 | // DR 804. |
70593ad2 BK |
345 | private: |
346 | int _M_value; | |
4661c8fd | 347 | const error_category* _M_cat; |
70593ad2 BK |
348 | }; |
349 | ||
92010a79 | 350 | // 19.4.3.6 non-member functions |
2f7f1aca JW |
351 | |
352 | /// Create an `error_condition` representing a standard `errc` condition. | |
353 | /// @relates error_condition | |
92010a79 | 354 | inline error_condition |
cd88bb8c | 355 | make_error_condition(errc __e) noexcept |
9b3003d5 | 356 | { return error_condition(static_cast<int>(__e), generic_category()); } |
92010a79 | 357 | |
70593ad2 | 358 | // 19.4.4 Comparison operators |
2f7f1aca JW |
359 | |
360 | /// @relates error_code | |
4661c8fd | 361 | inline bool |
cd88bb8c | 362 | operator==(const error_code& __lhs, const error_code& __rhs) noexcept |
4661c8fd PC |
363 | { return (__lhs.category() == __rhs.category() |
364 | && __lhs.value() == __rhs.value()); } | |
70593ad2 | 365 | |
2f7f1aca | 366 | /// @relates error_code |
4661c8fd | 367 | inline bool |
cd88bb8c | 368 | operator==(const error_code& __lhs, const error_condition& __rhs) noexcept |
70593ad2 | 369 | { |
4661c8fd PC |
370 | return (__lhs.category().equivalent(__lhs.value(), __rhs) |
371 | || __rhs.category().equivalent(__lhs, __rhs.value())); | |
70593ad2 BK |
372 | } |
373 | ||
2f7f1aca | 374 | /// @relates error_condition |
4661c8fd | 375 | inline bool |
4be779f5 JW |
376 | operator==(const error_condition& __lhs, |
377 | const error_condition& __rhs) noexcept | |
70593ad2 | 378 | { |
4be779f5 JW |
379 | return (__lhs.category() == __rhs.category() |
380 | && __lhs.value() == __rhs.value()); | |
70593ad2 BK |
381 | } |
382 | ||
4be779f5 JW |
383 | #if __cpp_lib_three_way_comparison |
384 | /// Define an ordering for error_condition objects. | |
385 | /// @relates error_condition | |
386 | inline strong_ordering | |
387 | operator<=>(const error_condition& __lhs, | |
388 | const error_condition& __rhs) noexcept | |
389 | { | |
390 | if (auto __c = __lhs.category() <=> __rhs.category(); __c != 0) | |
391 | return __c; | |
392 | return __lhs.value() <=> __rhs.value(); | |
393 | } | |
394 | #else | |
395 | /// Define an ordering for error_condition objects. | |
2f7f1aca | 396 | /// @relates error_condition |
4661c8fd | 397 | inline bool |
4be779f5 JW |
398 | operator<(const error_condition& __lhs, |
399 | const error_condition& __rhs) noexcept | |
4661c8fd | 400 | { |
4be779f5 JW |
401 | return (__lhs.category() < __rhs.category() |
402 | || (__lhs.category() == __rhs.category() | |
403 | && __lhs.value() < __rhs.value())); | |
404 | } | |
405 | ||
4be779f5 JW |
406 | /// @relates error_condition |
407 | inline bool | |
408 | operator==(const error_condition& __lhs, const error_code& __rhs) noexcept | |
409 | { | |
410 | return (__rhs.category().equivalent(__rhs.value(), __lhs) | |
411 | || __lhs.category().equivalent(__rhs, __lhs.value())); | |
4661c8fd | 412 | } |
70593ad2 | 413 | |
2f7f1aca | 414 | /// @relates error_code |
4661c8fd | 415 | inline bool |
cd88bb8c | 416 | operator!=(const error_code& __lhs, const error_code& __rhs) noexcept |
4661c8fd | 417 | { return !(__lhs == __rhs); } |
70593ad2 | 418 | |
2f7f1aca | 419 | /// @relates error_code |
4661c8fd | 420 | inline bool |
cd88bb8c | 421 | operator!=(const error_code& __lhs, const error_condition& __rhs) noexcept |
4661c8fd | 422 | { return !(__lhs == __rhs); } |
70593ad2 | 423 | |
2f7f1aca | 424 | /// @relates error_condition |
4661c8fd | 425 | inline bool |
cd88bb8c | 426 | operator!=(const error_condition& __lhs, const error_code& __rhs) noexcept |
4661c8fd PC |
427 | { return !(__lhs == __rhs); } |
428 | ||
2f7f1aca | 429 | /// @relates error_condition |
4661c8fd | 430 | inline bool |
cd88bb8c PC |
431 | operator!=(const error_condition& __lhs, |
432 | const error_condition& __rhs) noexcept | |
4661c8fd | 433 | { return !(__lhs == __rhs); } |
4be779f5 | 434 | #endif // three_way_comparison |
f2ce64b5 | 435 | /// @} |
70593ad2 | 436 | |
33ac58d5 | 437 | /** |
2f7f1aca JW |
438 | * @brief An exception type that includes an `error_code` value. |
439 | * | |
440 | * Typically used to report errors from the operating system and other | |
441 | * low-level APIs. | |
5b9daa7e | 442 | * |
f2ce64b5 | 443 | * @since C++11 |
2f7f1aca | 444 | * @ingroup exceptions |
5b9daa7e | 445 | */ |
0646d8a3 BK |
446 | class system_error : public std::runtime_error |
447 | { | |
448 | private: | |
449 | error_code _M_code; | |
450 | ||
451 | public: | |
4514bed6 | 452 | system_error(error_code __ec = error_code()) |
b5fbd147 | 453 | : runtime_error(__ec.message()), _M_code(__ec) { } |
4514bed6 | 454 | |
70593ad2 | 455 | system_error(error_code __ec, const string& __what) |
b5fbd147 PC |
456 | : runtime_error(__what + ": " + __ec.message()), _M_code(__ec) { } |
457 | ||
a5dde6dd JW |
458 | system_error(error_code __ec, const char* __what) |
459 | : runtime_error(__what + (": " + __ec.message())), _M_code(__ec) { } | |
460 | ||
461 | system_error(int __v, const error_category& __ecat, const char* __what) | |
462 | : system_error(error_code(__v, __ecat), __what) { } | |
0646d8a3 | 463 | |
70593ad2 | 464 | system_error(int __v, const error_category& __ecat) |
b5fbd147 PC |
465 | : runtime_error(error_code(__v, __ecat).message()), |
466 | _M_code(__v, __ecat) { } | |
70593ad2 BK |
467 | |
468 | system_error(int __v, const error_category& __ecat, const string& __what) | |
b5fbd147 PC |
469 | : runtime_error(__what + ": " + error_code(__v, __ecat).message()), |
470 | _M_code(__v, __ecat) { } | |
0646d8a3 | 471 | |
f07c2237 JM |
472 | #if __cplusplus >= 201103L |
473 | system_error (const system_error &) = default; | |
474 | system_error &operator= (const system_error &) = default; | |
475 | #endif | |
476 | ||
8535715d | 477 | virtual ~system_error() noexcept; |
0646d8a3 | 478 | |
33ac58d5 | 479 | const error_code& |
cd88bb8c | 480 | code() const noexcept { return _M_code; } |
0646d8a3 BK |
481 | }; |
482 | ||
12ffa228 BK |
483 | _GLIBCXX_END_NAMESPACE_VERSION |
484 | } // namespace | |
0646d8a3 | 485 | |
15d81a3c PC |
486 | #include <bits/functional_hash.h> |
487 | ||
12ffa228 BK |
488 | namespace std _GLIBCXX_VISIBILITY(default) |
489 | { | |
490 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
15d81a3c | 491 | |
7f359d19 | 492 | #ifndef _GLIBCXX_COMPATIBILITY_CXX0X |
15d81a3c PC |
493 | // DR 1182. |
494 | /// std::hash specialization for error_code. | |
2f7f1aca | 495 | /// @relates error_code |
15d81a3c PC |
496 | template<> |
497 | struct hash<error_code> | |
5d64ee19 | 498 | : public __hash_base<size_t, error_code> |
15d81a3c PC |
499 | { |
500 | size_t | |
72f1c34b | 501 | operator()(const error_code& __e) const noexcept |
15d81a3c | 502 | { |
fe6fb0d1 JW |
503 | const size_t __tmp = std::_Hash_impl::hash(__e.value()); |
504 | return std::_Hash_impl::__hash_combine(&__e.category(), __tmp); | |
15d81a3c PC |
505 | } |
506 | }; | |
7f359d19 DK |
507 | #endif // _GLIBCXX_COMPATIBILITY_CXX0X |
508 | ||
fe6fb0d1 | 509 | #if __cplusplus >= 201703L |
7f359d19 DK |
510 | // DR 2686. |
511 | /// std::hash specialization for error_condition. | |
2f7f1aca | 512 | /// @relates error_condition |
7f359d19 DK |
513 | template<> |
514 | struct hash<error_condition> | |
515 | : public __hash_base<size_t, error_condition> | |
516 | { | |
517 | size_t | |
518 | operator()(const error_condition& __e) const noexcept | |
519 | { | |
520 | const size_t __tmp = std::_Hash_impl::hash(__e.value()); | |
fe6fb0d1 | 521 | return std::_Hash_impl::__hash_combine(&__e.category(), __tmp); |
7f359d19 DK |
522 | } |
523 | }; | |
524 | #endif | |
15d81a3c | 525 | |
12ffa228 BK |
526 | _GLIBCXX_END_NAMESPACE_VERSION |
527 | } // namespace | |
15d81a3c | 528 | |
734f5023 | 529 | #endif // C++11 |
57317d2a PC |
530 | |
531 | #endif // _GLIBCXX_SYSTEM_ERROR |