blob: 05ef07950d059dab12f9e0145850b7a9aac724e6 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:161// -*- C++ -*-
2//===---------------------------- system_error ----------------------------===//
3//
Chandler Carruth57b08b02019-01-19 10:56:404// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnant3e519522010-05-11 19:42:167//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_SYSTEM_ERROR
11#define _LIBCPP_SYSTEM_ERROR
12
13/*
14 system_error synopsis
15
16namespace std
17{
18
19class error_category
20{
21public:
Howard Hinnanta62f2892011-05-26 19:48:0122 virtual ~error_category() noexcept;
Howard Hinnant3e519522010-05-11 19:42:1623
Marshall Clowa86d5162013-08-21 02:57:1924 constexpr error_category();
Howard Hinnant3e519522010-05-11 19:42:1625 error_category(const error_category&) = delete;
26 error_category& operator=(const error_category&) = delete;
27
Howard Hinnanta62f2892011-05-26 19:48:0128 virtual const char* name() const noexcept = 0;
29 virtual error_condition default_error_condition(int ev) const noexcept;
30 virtual bool equivalent(int code, const error_condition& condition) const noexcept;
31 virtual bool equivalent(const error_code& code, int condition) const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1632 virtual string message(int ev) const = 0;
33
Howard Hinnanta62f2892011-05-26 19:48:0134 bool operator==(const error_category& rhs) const noexcept;
35 bool operator!=(const error_category& rhs) const noexcept;
36 bool operator<(const error_category& rhs) const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1637};
38
Howard Hinnanta62f2892011-05-26 19:48:0139const error_category& generic_category() noexcept;
40const error_category& system_category() noexcept;
Howard Hinnant3e519522010-05-11 19:42:1641
42template <class T> struct is_error_code_enum
43 : public false_type {};
44
45template <class T> struct is_error_condition_enum
46 : public false_type {};
47
Marshall Clowe69a08b2016-09-24 17:36:1448template <class _Tp>
Marshall Clow40a01d52018-01-02 17:17:0149inline constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17
Marshall Clowe69a08b2016-09-24 17:36:1450
51template <class _Tp>
Marshall Clow40a01d52018-01-02 17:17:0152inline constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17
Marshall Clowe69a08b2016-09-24 17:36:1453
Howard Hinnant3e519522010-05-11 19:42:1654class error_code
55{
56public:
57 // constructors:
Howard Hinnanta62f2892011-05-26 19:48:0158 error_code() noexcept;
59 error_code(int val, const error_category& cat) noexcept;
Howard Hinnant3e519522010-05-11 19:42:1660 template <class ErrorCodeEnum>
Howard Hinnanta62f2892011-05-26 19:48:0161 error_code(ErrorCodeEnum e) noexcept;
Howard Hinnant3e519522010-05-11 19:42:1662
63 // modifiers:
Howard Hinnanta62f2892011-05-26 19:48:0164 void assign(int val, const error_category& cat) noexcept;
Howard Hinnant3e519522010-05-11 19:42:1665 template <class ErrorCodeEnum>
Howard Hinnanta62f2892011-05-26 19:48:0166 error_code& operator=(ErrorCodeEnum e) noexcept;
67 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:1668
69 // observers:
Howard Hinnanta62f2892011-05-26 19:48:0170 int value() const noexcept;
71 const error_category& category() const noexcept;
72 error_condition default_error_condition() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1673 string message() const;
Howard Hinnanta62f2892011-05-26 19:48:0174 explicit operator bool() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1675};
76
77// non-member functions:
Howard Hinnanta62f2892011-05-26 19:48:0178bool operator<(const error_code& lhs, const error_code& rhs) noexcept;
Howard Hinnant3e519522010-05-11 19:42:1679template <class charT, class traits>
80 basic_ostream<charT,traits>&
81 operator<<(basic_ostream<charT,traits>& os, const error_code& ec);
82
83class error_condition
84{
85public:
86 // constructors:
Howard Hinnanta62f2892011-05-26 19:48:0187 error_condition() noexcept;
88 error_condition(int val, const error_category& cat) noexcept;
Howard Hinnant3e519522010-05-11 19:42:1689 template <class ErrorConditionEnum>
Howard Hinnanta62f2892011-05-26 19:48:0190 error_condition(ErrorConditionEnum e) noexcept;
Howard Hinnant3e519522010-05-11 19:42:1691
92 // modifiers:
Howard Hinnanta62f2892011-05-26 19:48:0193 void assign(int val, const error_category& cat) noexcept;
Howard Hinnant3e519522010-05-11 19:42:1694 template <class ErrorConditionEnum>
Howard Hinnanta62f2892011-05-26 19:48:0195 error_condition& operator=(ErrorConditionEnum e) noexcept;
96 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:1697
98 // observers:
Howard Hinnanta62f2892011-05-26 19:48:0199 int value() const noexcept;
100 const error_category& category() const noexcept;
101 string message() const noexcept;
102 explicit operator bool() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16103};
104
Howard Hinnanta62f2892011-05-26 19:48:01105bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16106
107class system_error
108 : public runtime_error
109{
110public:
111 system_error(error_code ec, const string& what_arg);
112 system_error(error_code ec, const char* what_arg);
113 system_error(error_code ec);
114 system_error(int ev, const error_category& ecat, const string& what_arg);
115 system_error(int ev, const error_category& ecat, const char* what_arg);
116 system_error(int ev, const error_category& ecat);
117
Howard Hinnanta62f2892011-05-26 19:48:01118 const error_code& code() const noexcept;
119 const char* what() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16120};
121
Howard Hinnant3e519522010-05-11 19:42:16122template <> struct is_error_condition_enum<errc>
123 : true_type { }
124
Howard Hinnanta62f2892011-05-26 19:48:01125error_code make_error_code(errc e) noexcept;
126error_condition make_error_condition(errc e) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16127
128// Comparison operators:
Howard Hinnanta62f2892011-05-26 19:48:01129bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
130bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
131bool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
132bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
133bool operator!=(const error_code& lhs, const error_code& rhs) noexcept;
134bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
135bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
136bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16137
138template <> struct hash<std::error_code>;
Marshall Clow1c7fe122016-11-14 18:22:19139template <> struct hash<std::error_condition>;
Howard Hinnant3e519522010-05-11 19:42:16140
141} // std
142
143*/
144
Zhihao Yuan4f4effd2018-07-03 03:25:10145#include <__errc>
Howard Hinnant3e519522010-05-11 19:42:16146#include <type_traits>
147#include <stdexcept>
148#include <__functional_base>
Marshall Clowbc455472017-09-11 16:05:42149#include <string>
Howard Hinnant3e519522010-05-11 19:42:16150
Howard Hinnant073458b2011-10-17 20:05:10151#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16152#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10153#endif
Howard Hinnant3e519522010-05-11 19:42:16154
155_LIBCPP_BEGIN_NAMESPACE_STD
156
157// is_error_code_enum
158
Howard Hinnante0601332010-09-23 17:31:07159template <class _Tp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:00160struct _LIBCPP_TEMPLATE_VIS is_error_code_enum
Howard Hinnant3e519522010-05-11 19:42:16161 : public false_type {};
162
Marshall Clowe69a08b2016-09-24 17:36:14163#if _LIBCPP_STD_VER > 14
164template <class _Tp>
Marshall Clow40a01d52018-01-02 17:17:01165_LIBCPP_INLINE_VAR constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value;
Marshall Clowe69a08b2016-09-24 17:36:14166#endif
167
Howard Hinnant3e519522010-05-11 19:42:16168// is_error_condition_enum
169
Howard Hinnante0601332010-09-23 17:31:07170template <class _Tp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:00171struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum
Howard Hinnant3e519522010-05-11 19:42:16172 : public false_type {};
173
Marshall Clowe69a08b2016-09-24 17:36:14174#if _LIBCPP_STD_VER > 14
175template <class _Tp>
Marshall Clow40a01d52018-01-02 17:17:01176_LIBCPP_INLINE_VAR constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value;
Marshall Clowe69a08b2016-09-24 17:36:14177#endif
178
Howard Hinnante0601332010-09-23 17:31:07179template <>
Eric Fiseliere2f2d1ed2017-01-04 23:56:00180struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc>
Howard Hinnant3e519522010-05-11 19:42:16181 : true_type { };
182
Howard Hinnant75689c12011-12-02 19:36:40183#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
Howard Hinnante0601332010-09-23 17:31:07184template <>
Eric Fiseliere2f2d1ed2017-01-04 23:56:00185struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc::__lx>
Howard Hinnant3e519522010-05-11 19:42:16186 : true_type { };
Howard Hinnant75689c12011-12-02 19:36:40187#endif
Howard Hinnant3e519522010-05-11 19:42:16188
Howard Hinnant6e412562013-03-06 23:30:19189class _LIBCPP_TYPE_VIS error_condition;
190class _LIBCPP_TYPE_VIS error_code;
Howard Hinnant3e519522010-05-11 19:42:16191
192// class error_category
193
Howard Hinnantaeb85682012-09-14 00:39:16194class _LIBCPP_HIDDEN __do_message;
Howard Hinnant3e519522010-05-11 19:42:16195
Howard Hinnant6e412562013-03-06 23:30:19196class _LIBCPP_TYPE_VIS error_category
Howard Hinnant3e519522010-05-11 19:42:16197{
198public:
Howard Hinnanta62f2892011-05-26 19:48:01199 virtual ~error_category() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16200
Louis Dionnec8e84ff2018-08-01 02:08:59201#if defined(_LIBCPP_BUILDING_LIBRARY) && \
Eric Fiselier11f60452017-01-17 03:16:26202 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
Howard Hinnanta62f2892011-05-26 19:48:01203 error_category() _NOEXCEPT;
Marshall Clowa86d5162013-08-21 02:57:19204#else
Louis Dionnedc7200b2018-07-11 23:14:33205 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere57e3ae2015-08-28 07:02:42206 _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT _LIBCPP_DEFAULT
Marshall Clowa86d5162013-08-21 02:57:19207#endif
Howard Hinnantcb16c682012-03-21 16:18:57208private:
Howard Hinnant3e519522010-05-11 19:42:16209 error_category(const error_category&);// = delete;
210 error_category& operator=(const error_category&);// = delete;
211
212public:
Howard Hinnanta62f2892011-05-26 19:48:01213 virtual const char* name() const _NOEXCEPT = 0;
214 virtual error_condition default_error_condition(int __ev) const _NOEXCEPT;
215 virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT;
216 virtual bool equivalent(const error_code& __code, int __condition) const _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16217 virtual string message(int __ev) const = 0;
218
Louis Dionnedc7200b2018-07-11 23:14:33219 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01220 bool operator==(const error_category& __rhs) const _NOEXCEPT {return this == &__rhs;}
Howard Hinnant3e519522010-05-11 19:42:16221
Louis Dionnedc7200b2018-07-11 23:14:33222 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01223 bool operator!=(const error_category& __rhs) const _NOEXCEPT {return !(*this == __rhs);}
Howard Hinnant3e519522010-05-11 19:42:16224
Louis Dionnedc7200b2018-07-11 23:14:33225 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01226 bool operator< (const error_category& __rhs) const _NOEXCEPT {return this < &__rhs;}
Howard Hinnant3e519522010-05-11 19:42:16227
Howard Hinnantaeb85682012-09-14 00:39:16228 friend class _LIBCPP_HIDDEN __do_message;
Howard Hinnant3e519522010-05-11 19:42:16229};
230
231class _LIBCPP_HIDDEN __do_message
232 : public error_category
233{
234public:
235 virtual string message(int ev) const;
236};
237
Howard Hinnantf0544c22013-08-12 18:38:34238_LIBCPP_FUNC_VIS const error_category& generic_category() _NOEXCEPT;
239_LIBCPP_FUNC_VIS const error_category& system_category() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16240
Howard Hinnant6e412562013-03-06 23:30:19241class _LIBCPP_TYPE_VIS error_condition
Howard Hinnant3e519522010-05-11 19:42:16242{
243 int __val_;
244 const error_category* __cat_;
245public:
Louis Dionnedc7200b2018-07-11 23:14:33246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01247 error_condition() _NOEXCEPT : __val_(0), __cat_(&generic_category()) {}
Howard Hinnant3e519522010-05-11 19:42:16248
Louis Dionnedc7200b2018-07-11 23:14:33249 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01250 error_condition(int __val, const error_category& __cat) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16251 : __val_(__val), __cat_(&__cat) {}
252
Howard Hinnantc003db12011-11-29 18:15:50253 template <class _Ep>
Louis Dionnedc7200b2018-07-11 23:14:33254 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc003db12011-11-29 18:15:50255 error_condition(_Ep __e,
256 typename enable_if<is_error_condition_enum<_Ep>::value>::type* = 0
Howard Hinnanta62f2892011-05-26 19:48:01257 ) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16258 {*this = make_error_condition(__e);}
259
Louis Dionnedc7200b2018-07-11 23:14:33260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01261 void assign(int __val, const error_category& __cat) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16262 {
263 __val_ = __val;
264 __cat_ = &__cat;
265 }
266
Howard Hinnantc003db12011-11-29 18:15:50267 template <class _Ep>
Louis Dionnedc7200b2018-07-11 23:14:33268 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16269 typename enable_if
270 <
Howard Hinnantc003db12011-11-29 18:15:50271 is_error_condition_enum<_Ep>::value,
Howard Hinnant3e519522010-05-11 19:42:16272 error_condition&
273 >::type
Howard Hinnantc003db12011-11-29 18:15:50274 operator=(_Ep __e) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16275 {*this = make_error_condition(__e); return *this;}
276
Louis Dionnedc7200b2018-07-11 23:14:33277 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01278 void clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16279 {
280 __val_ = 0;
281 __cat_ = &generic_category();
282 }
283
Louis Dionnedc7200b2018-07-11 23:14:33284 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01285 int value() const _NOEXCEPT {return __val_;}
Howard Hinnant3e519522010-05-11 19:42:16286
Louis Dionnedc7200b2018-07-11 23:14:33287 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01288 const error_category& category() const _NOEXCEPT {return *__cat_;}
Howard Hinnant3e519522010-05-11 19:42:16289 string message() const;
290
Louis Dionnedc7200b2018-07-11 23:14:33291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf2f2d8b2012-02-21 21:46:43292 _LIBCPP_EXPLICIT
Howard Hinnanta62f2892011-05-26 19:48:01293 operator bool() const _NOEXCEPT {return __val_ != 0;}
Howard Hinnant3e519522010-05-11 19:42:16294};
295
296inline _LIBCPP_INLINE_VISIBILITY
297error_condition
Howard Hinnanta62f2892011-05-26 19:48:01298make_error_condition(errc __e) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16299{
300 return error_condition(static_cast<int>(__e), generic_category());
301}
302
303inline _LIBCPP_INLINE_VISIBILITY
304bool
Howard Hinnanta62f2892011-05-26 19:48:01305operator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16306{
307 return __x.category() < __y.category()
Howard Hinnantc2063662011-12-01 20:21:04308 || (__x.category() == __y.category() && __x.value() < __y.value());
Howard Hinnant3e519522010-05-11 19:42:16309}
310
311// error_code
312
Howard Hinnant6e412562013-03-06 23:30:19313class _LIBCPP_TYPE_VIS error_code
Howard Hinnant3e519522010-05-11 19:42:16314{
315 int __val_;
316 const error_category* __cat_;
317public:
Louis Dionnedc7200b2018-07-11 23:14:33318 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01319 error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {}
Howard Hinnant3e519522010-05-11 19:42:16320
Louis Dionnedc7200b2018-07-11 23:14:33321 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01322 error_code(int __val, const error_category& __cat) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16323 : __val_(__val), __cat_(&__cat) {}
324
Howard Hinnantc003db12011-11-29 18:15:50325 template <class _Ep>
Louis Dionnedc7200b2018-07-11 23:14:33326 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc003db12011-11-29 18:15:50327 error_code(_Ep __e,
328 typename enable_if<is_error_code_enum<_Ep>::value>::type* = 0
Howard Hinnanta62f2892011-05-26 19:48:01329 ) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16330 {*this = make_error_code(__e);}
331
Louis Dionnedc7200b2018-07-11 23:14:33332 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01333 void assign(int __val, const error_category& __cat) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16334 {
335 __val_ = __val;
336 __cat_ = &__cat;
337 }
338
Howard Hinnantc003db12011-11-29 18:15:50339 template <class _Ep>
Louis Dionnedc7200b2018-07-11 23:14:33340 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16341 typename enable_if
342 <
Howard Hinnantc003db12011-11-29 18:15:50343 is_error_code_enum<_Ep>::value,
Howard Hinnant3e519522010-05-11 19:42:16344 error_code&
345 >::type
Howard Hinnantc003db12011-11-29 18:15:50346 operator=(_Ep __e) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16347 {*this = make_error_code(__e); return *this;}
348
Louis Dionnedc7200b2018-07-11 23:14:33349 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01350 void clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16351 {
352 __val_ = 0;
353 __cat_ = &system_category();
354 }
355
Louis Dionnedc7200b2018-07-11 23:14:33356 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01357 int value() const _NOEXCEPT {return __val_;}
Howard Hinnant3e519522010-05-11 19:42:16358
Louis Dionnedc7200b2018-07-11 23:14:33359 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01360 const error_category& category() const _NOEXCEPT {return *__cat_;}
Howard Hinnant3e519522010-05-11 19:42:16361
Louis Dionnedc7200b2018-07-11 23:14:33362 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01363 error_condition default_error_condition() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16364 {return __cat_->default_error_condition(__val_);}
365
366 string message() const;
367
Louis Dionnedc7200b2018-07-11 23:14:33368 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf2f2d8b2012-02-21 21:46:43369 _LIBCPP_EXPLICIT
Howard Hinnanta62f2892011-05-26 19:48:01370 operator bool() const _NOEXCEPT {return __val_ != 0;}
Howard Hinnant3e519522010-05-11 19:42:16371};
372
373inline _LIBCPP_INLINE_VISIBILITY
374error_code
Howard Hinnanta62f2892011-05-26 19:48:01375make_error_code(errc __e) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16376{
377 return error_code(static_cast<int>(__e), generic_category());
378}
379
380inline _LIBCPP_INLINE_VISIBILITY
381bool
Howard Hinnanta62f2892011-05-26 19:48:01382operator<(const error_code& __x, const error_code& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16383{
384 return __x.category() < __y.category()
Howard Hinnantc2063662011-12-01 20:21:04385 || (__x.category() == __y.category() && __x.value() < __y.value());
Howard Hinnant3e519522010-05-11 19:42:16386}
387
388inline _LIBCPP_INLINE_VISIBILITY
389bool
Howard Hinnanta62f2892011-05-26 19:48:01390operator==(const error_code& __x, const error_code& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16391{
392 return __x.category() == __y.category() && __x.value() == __y.value();
393}
394
395inline _LIBCPP_INLINE_VISIBILITY
396bool
Howard Hinnanta62f2892011-05-26 19:48:01397operator==(const error_code& __x, const error_condition& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16398{
399 return __x.category().equivalent(__x.value(), __y)
400 || __y.category().equivalent(__x, __y.value());
401}
402
403inline _LIBCPP_INLINE_VISIBILITY
404bool
Howard Hinnanta62f2892011-05-26 19:48:01405operator==(const error_condition& __x, const error_code& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16406{
407 return __y == __x;
408}
409
410inline _LIBCPP_INLINE_VISIBILITY
411bool
Howard Hinnanta62f2892011-05-26 19:48:01412operator==(const error_condition& __x, const error_condition& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16413{
414 return __x.category() == __y.category() && __x.value() == __y.value();
415}
416
417inline _LIBCPP_INLINE_VISIBILITY
418bool
Howard Hinnanta62f2892011-05-26 19:48:01419operator!=(const error_code& __x, const error_code& __y) _NOEXCEPT
420{return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16421
422inline _LIBCPP_INLINE_VISIBILITY
423bool
Howard Hinnanta62f2892011-05-26 19:48:01424operator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT
425{return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16426
427inline _LIBCPP_INLINE_VISIBILITY
428bool
Howard Hinnanta62f2892011-05-26 19:48:01429operator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT
430{return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16431
432inline _LIBCPP_INLINE_VISIBILITY
433bool
Howard Hinnanta62f2892011-05-26 19:48:01434operator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT
435{return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16436
437template <>
Eric Fiseliere2f2d1ed2017-01-04 23:56:00438struct _LIBCPP_TEMPLATE_VIS hash<error_code>
Howard Hinnant3e519522010-05-11 19:42:16439 : public unary_function<error_code, size_t>
440{
Howard Hinnante0601332010-09-23 17:31:07441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01442 size_t operator()(const error_code& __ec) const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16443 {
444 return static_cast<size_t>(__ec.value());
445 }
446};
447
Marshall Clow1c7fe122016-11-14 18:22:19448template <>
Eric Fiseliere2f2d1ed2017-01-04 23:56:00449struct _LIBCPP_TEMPLATE_VIS hash<error_condition>
Marshall Clow1c7fe122016-11-14 18:22:19450 : public unary_function<error_condition, size_t>
451{
452 _LIBCPP_INLINE_VISIBILITY
453 size_t operator()(const error_condition& __ec) const _NOEXCEPT
454 {
455 return static_cast<size_t>(__ec.value());
456 }
457};
458
Howard Hinnant3e519522010-05-11 19:42:16459// system_error
460
Howard Hinnant6e412562013-03-06 23:30:19461class _LIBCPP_TYPE_VIS system_error
Howard Hinnant3e519522010-05-11 19:42:16462 : public runtime_error
463{
464 error_code __ec_;
465public:
466 system_error(error_code __ec, const string& __what_arg);
467 system_error(error_code __ec, const char* __what_arg);
468 system_error(error_code __ec);
469 system_error(int __ev, const error_category& __ecat, const string& __what_arg);
470 system_error(int __ev, const error_category& __ecat, const char* __what_arg);
471 system_error(int __ev, const error_category& __ecat);
Howard Hinnanta62f2892011-05-26 19:48:01472 ~system_error() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16473
Louis Dionnedc7200b2018-07-11 23:14:33474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01475 const error_code& code() const _NOEXCEPT {return __ec_;}
Howard Hinnant3e519522010-05-11 19:42:16476
477private:
478 static string __init(const error_code&, string);
479};
480
Aditya Kumard51f2a22016-08-27 02:26:42481_LIBCPP_NORETURN _LIBCPP_FUNC_VIS
482void __throw_system_error(int ev, const char* what_arg);
Howard Hinnant3e519522010-05-11 19:42:16483
484_LIBCPP_END_NAMESPACE_STD
485
486#endif // _LIBCPP_SYSTEM_ERROR