blob: 6e2c8388f17eb2dedc3898228a24d74f90f472a3 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- system_error ----------------------------===//
3//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00005//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_SYSTEM_ERROR
12#define _LIBCPP_SYSTEM_ERROR
13
14/*
15 system_error synopsis
16
17namespace std
18{
19
20class error_category
21{
22public:
Howard Hinnanta62f2892011-05-26 19:48:01 +000023 virtual ~error_category() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000024
Marshall Clowa86d5162013-08-21 02:57:19 +000025 constexpr error_category();
Howard Hinnant3e519522010-05-11 19:42:16 +000026 error_category(const error_category&) = delete;
27 error_category& operator=(const error_category&) = delete;
28
Howard Hinnanta62f2892011-05-26 19:48:01 +000029 virtual const char* name() const noexcept = 0;
30 virtual error_condition default_error_condition(int ev) const noexcept;
31 virtual bool equivalent(int code, const error_condition& condition) const noexcept;
32 virtual bool equivalent(const error_code& code, int condition) const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000033 virtual string message(int ev) const = 0;
34
Howard Hinnanta62f2892011-05-26 19:48:01 +000035 bool operator==(const error_category& rhs) const noexcept;
36 bool operator!=(const error_category& rhs) const noexcept;
37 bool operator<(const error_category& rhs) const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000038};
39
Howard Hinnanta62f2892011-05-26 19:48:01 +000040const error_category& generic_category() noexcept;
41const error_category& system_category() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000042
43template <class T> struct is_error_code_enum
44 : public false_type {};
45
46template <class T> struct is_error_condition_enum
47 : public false_type {};
48
Marshall Clowe69a08b2016-09-24 17:36:14 +000049template <class _Tp>
Marshall Clow40a01d52018-01-02 17:17:01 +000050inline constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17
Marshall Clowe69a08b2016-09-24 17:36:14 +000051
52template <class _Tp>
Marshall Clow40a01d52018-01-02 17:17:01 +000053inline constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17
Marshall Clowe69a08b2016-09-24 17:36:14 +000054
Howard Hinnant3e519522010-05-11 19:42:16 +000055class error_code
56{
57public:
58 // constructors:
Howard Hinnanta62f2892011-05-26 19:48:01 +000059 error_code() noexcept;
60 error_code(int val, const error_category& cat) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000061 template <class ErrorCodeEnum>
Howard Hinnanta62f2892011-05-26 19:48:01 +000062 error_code(ErrorCodeEnum e) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000063
64 // modifiers:
Howard Hinnanta62f2892011-05-26 19:48:01 +000065 void assign(int val, const error_category& cat) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000066 template <class ErrorCodeEnum>
Howard Hinnanta62f2892011-05-26 19:48:01 +000067 error_code& operator=(ErrorCodeEnum e) noexcept;
68 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000069
70 // observers:
Howard Hinnanta62f2892011-05-26 19:48:01 +000071 int value() const noexcept;
72 const error_category& category() const noexcept;
73 error_condition default_error_condition() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000074 string message() const;
Howard Hinnanta62f2892011-05-26 19:48:01 +000075 explicit operator bool() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000076};
77
78// non-member functions:
Howard Hinnanta62f2892011-05-26 19:48:01 +000079bool operator<(const error_code& lhs, const error_code& rhs) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000080template <class charT, class traits>
81 basic_ostream<charT,traits>&
82 operator<<(basic_ostream<charT,traits>& os, const error_code& ec);
83
84class error_condition
85{
86public:
87 // constructors:
Howard Hinnanta62f2892011-05-26 19:48:01 +000088 error_condition() noexcept;
89 error_condition(int val, const error_category& cat) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000090 template <class ErrorConditionEnum>
Howard Hinnanta62f2892011-05-26 19:48:01 +000091 error_condition(ErrorConditionEnum e) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000092
93 // modifiers:
Howard Hinnanta62f2892011-05-26 19:48:01 +000094 void assign(int val, const error_category& cat) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000095 template <class ErrorConditionEnum>
Howard Hinnanta62f2892011-05-26 19:48:01 +000096 error_condition& operator=(ErrorConditionEnum e) noexcept;
97 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000098
99 // observers:
Howard Hinnanta62f2892011-05-26 19:48:01 +0000100 int value() const noexcept;
101 const error_category& category() const noexcept;
102 string message() const noexcept;
103 explicit operator bool() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000104};
105
Howard Hinnanta62f2892011-05-26 19:48:01 +0000106bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000107
108class system_error
109 : public runtime_error
110{
111public:
112 system_error(error_code ec, const string& what_arg);
113 system_error(error_code ec, const char* what_arg);
114 system_error(error_code ec);
115 system_error(int ev, const error_category& ecat, const string& what_arg);
116 system_error(int ev, const error_category& ecat, const char* what_arg);
117 system_error(int ev, const error_category& ecat);
118
Howard Hinnanta62f2892011-05-26 19:48:01 +0000119 const error_code& code() const noexcept;
120 const char* what() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000121};
122
Howard Hinnant3e519522010-05-11 19:42:16 +0000123template <> struct is_error_condition_enum<errc>
124 : true_type { }
125
Howard Hinnanta62f2892011-05-26 19:48:01 +0000126error_code make_error_code(errc e) noexcept;
127error_condition make_error_condition(errc e) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000128
129// Comparison operators:
Howard Hinnanta62f2892011-05-26 19:48:01 +0000130bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
131bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
132bool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
133bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
134bool operator!=(const error_code& lhs, const error_code& rhs) noexcept;
135bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
136bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
137bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000138
139template <> struct hash<std::error_code>;
Marshall Clow1c7fe122016-11-14 18:22:19 +0000140template <> struct hash<std::error_condition>;
Howard Hinnant3e519522010-05-11 19:42:16 +0000141
142} // std
143
144*/
145
Zhihao Yuan4f4effd2018-07-03 03:25:10 +0000146#include <__errc>
Howard Hinnant3e519522010-05-11 19:42:16 +0000147#include <type_traits>
148#include <stdexcept>
149#include <__functional_base>
Marshall Clowbc455472017-09-11 16:05:42 +0000150#include <string>
Howard Hinnant3e519522010-05-11 19:42:16 +0000151
Howard Hinnant073458b2011-10-17 20:05:10 +0000152#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16 +0000153#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10 +0000154#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000155
156_LIBCPP_BEGIN_NAMESPACE_STD
157
158// is_error_code_enum
159
Howard Hinnante0601332010-09-23 17:31:07 +0000160template <class _Tp>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000161struct _LIBCPP_TEMPLATE_VIS is_error_code_enum
Howard Hinnant3e519522010-05-11 19:42:16 +0000162 : public false_type {};
163
Marshall Clowe69a08b2016-09-24 17:36:14 +0000164#if _LIBCPP_STD_VER > 14
165template <class _Tp>
Marshall Clow40a01d52018-01-02 17:17:01 +0000166_LIBCPP_INLINE_VAR constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value;
Marshall Clowe69a08b2016-09-24 17:36:14 +0000167#endif
168
Howard Hinnant3e519522010-05-11 19:42:16 +0000169// is_error_condition_enum
170
Howard Hinnante0601332010-09-23 17:31:07 +0000171template <class _Tp>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000172struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum
Howard Hinnant3e519522010-05-11 19:42:16 +0000173 : public false_type {};
174
Marshall Clowe69a08b2016-09-24 17:36:14 +0000175#if _LIBCPP_STD_VER > 14
176template <class _Tp>
Marshall Clow40a01d52018-01-02 17:17:01 +0000177_LIBCPP_INLINE_VAR constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value;
Marshall Clowe69a08b2016-09-24 17:36:14 +0000178#endif
179
Howard Hinnante0601332010-09-23 17:31:07 +0000180template <>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000181struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc>
Howard Hinnant3e519522010-05-11 19:42:16 +0000182 : true_type { };
183
Howard Hinnant75689c12011-12-02 19:36:40 +0000184#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
Howard Hinnante0601332010-09-23 17:31:07 +0000185template <>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000186struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc::__lx>
Howard Hinnant3e519522010-05-11 19:42:16 +0000187 : true_type { };
Howard Hinnant75689c12011-12-02 19:36:40 +0000188#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000189
Howard Hinnant6e412562013-03-06 23:30:19 +0000190class _LIBCPP_TYPE_VIS error_condition;
191class _LIBCPP_TYPE_VIS error_code;
Howard Hinnant3e519522010-05-11 19:42:16 +0000192
193// class error_category
194
Howard Hinnantaeb85682012-09-14 00:39:16 +0000195class _LIBCPP_HIDDEN __do_message;
Howard Hinnant3e519522010-05-11 19:42:16 +0000196
Howard Hinnant6e412562013-03-06 23:30:19 +0000197class _LIBCPP_TYPE_VIS error_category
Howard Hinnant3e519522010-05-11 19:42:16 +0000198{
199public:
Howard Hinnanta62f2892011-05-26 19:48:01 +0000200 virtual ~error_category() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +0000201
Louis Dionnec8e84ff2018-08-01 02:08:59 +0000202#if defined(_LIBCPP_BUILDING_LIBRARY) && \
Eric Fiselier11f60452017-01-17 03:16:26 +0000203 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
Howard Hinnanta62f2892011-05-26 19:48:01 +0000204 error_category() _NOEXCEPT;
Marshall Clowa86d5162013-08-21 02:57:19 +0000205#else
Louis Dionnedc7200b2018-07-11 23:14:33 +0000206 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere57e3ae2015-08-28 07:02:42 +0000207 _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT _LIBCPP_DEFAULT
Marshall Clowa86d5162013-08-21 02:57:19 +0000208#endif
Howard Hinnantcb16c682012-03-21 16:18:57 +0000209private:
Howard Hinnant3e519522010-05-11 19:42:16 +0000210 error_category(const error_category&);// = delete;
211 error_category& operator=(const error_category&);// = delete;
212
213public:
Howard Hinnanta62f2892011-05-26 19:48:01 +0000214 virtual const char* name() const _NOEXCEPT = 0;
215 virtual error_condition default_error_condition(int __ev) const _NOEXCEPT;
216 virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT;
217 virtual bool equivalent(const error_code& __code, int __condition) const _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +0000218 virtual string message(int __ev) const = 0;
219
Louis Dionnedc7200b2018-07-11 23:14:33 +0000220 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000221 bool operator==(const error_category& __rhs) const _NOEXCEPT {return this == &__rhs;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000222
Louis Dionnedc7200b2018-07-11 23:14:33 +0000223 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000224 bool operator!=(const error_category& __rhs) const _NOEXCEPT {return !(*this == __rhs);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000225
Louis Dionnedc7200b2018-07-11 23:14:33 +0000226 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000227 bool operator< (const error_category& __rhs) const _NOEXCEPT {return this < &__rhs;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000228
Howard Hinnantaeb85682012-09-14 00:39:16 +0000229 friend class _LIBCPP_HIDDEN __do_message;
Howard Hinnant3e519522010-05-11 19:42:16 +0000230};
231
232class _LIBCPP_HIDDEN __do_message
233 : public error_category
234{
235public:
236 virtual string message(int ev) const;
237};
238
Howard Hinnantf0544c22013-08-12 18:38:34 +0000239_LIBCPP_FUNC_VIS const error_category& generic_category() _NOEXCEPT;
240_LIBCPP_FUNC_VIS const error_category& system_category() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +0000241
Howard Hinnant6e412562013-03-06 23:30:19 +0000242class _LIBCPP_TYPE_VIS error_condition
Howard Hinnant3e519522010-05-11 19:42:16 +0000243{
244 int __val_;
245 const error_category* __cat_;
246public:
Louis Dionnedc7200b2018-07-11 23:14:33 +0000247 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000248 error_condition() _NOEXCEPT : __val_(0), __cat_(&generic_category()) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000249
Louis Dionnedc7200b2018-07-11 23:14:33 +0000250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000251 error_condition(int __val, const error_category& __cat) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000252 : __val_(__val), __cat_(&__cat) {}
253
Howard Hinnantc003db12011-11-29 18:15:50 +0000254 template <class _Ep>
Louis Dionnedc7200b2018-07-11 23:14:33 +0000255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc003db12011-11-29 18:15:50 +0000256 error_condition(_Ep __e,
257 typename enable_if<is_error_condition_enum<_Ep>::value>::type* = 0
Howard Hinnanta62f2892011-05-26 19:48:01 +0000258 ) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000259 {*this = make_error_condition(__e);}
260
Louis Dionnedc7200b2018-07-11 23:14:33 +0000261 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000262 void assign(int __val, const error_category& __cat) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000263 {
264 __val_ = __val;
265 __cat_ = &__cat;
266 }
267
Howard Hinnantc003db12011-11-29 18:15:50 +0000268 template <class _Ep>
Louis Dionnedc7200b2018-07-11 23:14:33 +0000269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000270 typename enable_if
271 <
Howard Hinnantc003db12011-11-29 18:15:50 +0000272 is_error_condition_enum<_Ep>::value,
Howard Hinnant3e519522010-05-11 19:42:16 +0000273 error_condition&
274 >::type
Howard Hinnantc003db12011-11-29 18:15:50 +0000275 operator=(_Ep __e) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000276 {*this = make_error_condition(__e); return *this;}
277
Louis Dionnedc7200b2018-07-11 23:14:33 +0000278 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000279 void clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000280 {
281 __val_ = 0;
282 __cat_ = &generic_category();
283 }
284
Louis Dionnedc7200b2018-07-11 23:14:33 +0000285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000286 int value() const _NOEXCEPT {return __val_;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000287
Louis Dionnedc7200b2018-07-11 23:14:33 +0000288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000289 const error_category& category() const _NOEXCEPT {return *__cat_;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000290 string message() const;
291
Louis Dionnedc7200b2018-07-11 23:14:33 +0000292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf2f2d8b2012-02-21 21:46:43 +0000293 _LIBCPP_EXPLICIT
Howard Hinnanta62f2892011-05-26 19:48:01 +0000294 operator bool() const _NOEXCEPT {return __val_ != 0;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000295};
296
297inline _LIBCPP_INLINE_VISIBILITY
298error_condition
Howard Hinnanta62f2892011-05-26 19:48:01 +0000299make_error_condition(errc __e) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000300{
301 return error_condition(static_cast<int>(__e), generic_category());
302}
303
304inline _LIBCPP_INLINE_VISIBILITY
305bool
Howard Hinnanta62f2892011-05-26 19:48:01 +0000306operator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000307{
308 return __x.category() < __y.category()
Howard Hinnantc2063662011-12-01 20:21:04 +0000309 || (__x.category() == __y.category() && __x.value() < __y.value());
Howard Hinnant3e519522010-05-11 19:42:16 +0000310}
311
312// error_code
313
Howard Hinnant6e412562013-03-06 23:30:19 +0000314class _LIBCPP_TYPE_VIS error_code
Howard Hinnant3e519522010-05-11 19:42:16 +0000315{
316 int __val_;
317 const error_category* __cat_;
318public:
Louis Dionnedc7200b2018-07-11 23:14:33 +0000319 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000320 error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000321
Louis Dionnedc7200b2018-07-11 23:14:33 +0000322 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000323 error_code(int __val, const error_category& __cat) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000324 : __val_(__val), __cat_(&__cat) {}
325
Howard Hinnantc003db12011-11-29 18:15:50 +0000326 template <class _Ep>
Louis Dionnedc7200b2018-07-11 23:14:33 +0000327 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc003db12011-11-29 18:15:50 +0000328 error_code(_Ep __e,
329 typename enable_if<is_error_code_enum<_Ep>::value>::type* = 0
Howard Hinnanta62f2892011-05-26 19:48:01 +0000330 ) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000331 {*this = make_error_code(__e);}
332
Louis Dionnedc7200b2018-07-11 23:14:33 +0000333 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000334 void assign(int __val, const error_category& __cat) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000335 {
336 __val_ = __val;
337 __cat_ = &__cat;
338 }
339
Howard Hinnantc003db12011-11-29 18:15:50 +0000340 template <class _Ep>
Louis Dionnedc7200b2018-07-11 23:14:33 +0000341 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000342 typename enable_if
343 <
Howard Hinnantc003db12011-11-29 18:15:50 +0000344 is_error_code_enum<_Ep>::value,
Howard Hinnant3e519522010-05-11 19:42:16 +0000345 error_code&
346 >::type
Howard Hinnantc003db12011-11-29 18:15:50 +0000347 operator=(_Ep __e) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000348 {*this = make_error_code(__e); return *this;}
349
Louis Dionnedc7200b2018-07-11 23:14:33 +0000350 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000351 void clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000352 {
353 __val_ = 0;
354 __cat_ = &system_category();
355 }
356
Louis Dionnedc7200b2018-07-11 23:14:33 +0000357 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000358 int value() const _NOEXCEPT {return __val_;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000359
Louis Dionnedc7200b2018-07-11 23:14:33 +0000360 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000361 const error_category& category() const _NOEXCEPT {return *__cat_;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000362
Louis Dionnedc7200b2018-07-11 23:14:33 +0000363 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000364 error_condition default_error_condition() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000365 {return __cat_->default_error_condition(__val_);}
366
367 string message() const;
368
Louis Dionnedc7200b2018-07-11 23:14:33 +0000369 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf2f2d8b2012-02-21 21:46:43 +0000370 _LIBCPP_EXPLICIT
Howard Hinnanta62f2892011-05-26 19:48:01 +0000371 operator bool() const _NOEXCEPT {return __val_ != 0;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000372};
373
374inline _LIBCPP_INLINE_VISIBILITY
375error_code
Howard Hinnanta62f2892011-05-26 19:48:01 +0000376make_error_code(errc __e) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000377{
378 return error_code(static_cast<int>(__e), generic_category());
379}
380
381inline _LIBCPP_INLINE_VISIBILITY
382bool
Howard Hinnanta62f2892011-05-26 19:48:01 +0000383operator<(const error_code& __x, const error_code& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000384{
385 return __x.category() < __y.category()
Howard Hinnantc2063662011-12-01 20:21:04 +0000386 || (__x.category() == __y.category() && __x.value() < __y.value());
Howard Hinnant3e519522010-05-11 19:42:16 +0000387}
388
389inline _LIBCPP_INLINE_VISIBILITY
390bool
Howard Hinnanta62f2892011-05-26 19:48:01 +0000391operator==(const error_code& __x, const error_code& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000392{
393 return __x.category() == __y.category() && __x.value() == __y.value();
394}
395
396inline _LIBCPP_INLINE_VISIBILITY
397bool
Howard Hinnanta62f2892011-05-26 19:48:01 +0000398operator==(const error_code& __x, const error_condition& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000399{
400 return __x.category().equivalent(__x.value(), __y)
401 || __y.category().equivalent(__x, __y.value());
402}
403
404inline _LIBCPP_INLINE_VISIBILITY
405bool
Howard Hinnanta62f2892011-05-26 19:48:01 +0000406operator==(const error_condition& __x, const error_code& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000407{
408 return __y == __x;
409}
410
411inline _LIBCPP_INLINE_VISIBILITY
412bool
Howard Hinnanta62f2892011-05-26 19:48:01 +0000413operator==(const error_condition& __x, const error_condition& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000414{
415 return __x.category() == __y.category() && __x.value() == __y.value();
416}
417
418inline _LIBCPP_INLINE_VISIBILITY
419bool
Howard Hinnanta62f2892011-05-26 19:48:01 +0000420operator!=(const error_code& __x, const error_code& __y) _NOEXCEPT
421{return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000422
423inline _LIBCPP_INLINE_VISIBILITY
424bool
Howard Hinnanta62f2892011-05-26 19:48:01 +0000425operator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT
426{return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000427
428inline _LIBCPP_INLINE_VISIBILITY
429bool
Howard Hinnanta62f2892011-05-26 19:48:01 +0000430operator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT
431{return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000432
433inline _LIBCPP_INLINE_VISIBILITY
434bool
Howard Hinnanta62f2892011-05-26 19:48:01 +0000435operator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT
436{return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000437
438template <>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000439struct _LIBCPP_TEMPLATE_VIS hash<error_code>
Howard Hinnant3e519522010-05-11 19:42:16 +0000440 : public unary_function<error_code, size_t>
441{
Howard Hinnante0601332010-09-23 17:31:07 +0000442 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000443 size_t operator()(const error_code& __ec) const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000444 {
445 return static_cast<size_t>(__ec.value());
446 }
447};
448
Marshall Clow1c7fe122016-11-14 18:22:19 +0000449template <>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000450struct _LIBCPP_TEMPLATE_VIS hash<error_condition>
Marshall Clow1c7fe122016-11-14 18:22:19 +0000451 : public unary_function<error_condition, size_t>
452{
453 _LIBCPP_INLINE_VISIBILITY
454 size_t operator()(const error_condition& __ec) const _NOEXCEPT
455 {
456 return static_cast<size_t>(__ec.value());
457 }
458};
459
Howard Hinnant3e519522010-05-11 19:42:16 +0000460// system_error
461
Howard Hinnant6e412562013-03-06 23:30:19 +0000462class _LIBCPP_TYPE_VIS system_error
Howard Hinnant3e519522010-05-11 19:42:16 +0000463 : public runtime_error
464{
465 error_code __ec_;
466public:
467 system_error(error_code __ec, const string& __what_arg);
468 system_error(error_code __ec, const char* __what_arg);
469 system_error(error_code __ec);
470 system_error(int __ev, const error_category& __ecat, const string& __what_arg);
471 system_error(int __ev, const error_category& __ecat, const char* __what_arg);
472 system_error(int __ev, const error_category& __ecat);
Howard Hinnanta62f2892011-05-26 19:48:01 +0000473 ~system_error() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +0000474
Louis Dionnedc7200b2018-07-11 23:14:33 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta62f2892011-05-26 19:48:01 +0000476 const error_code& code() const _NOEXCEPT {return __ec_;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000477
478private:
479 static string __init(const error_code&, string);
480};
481
Aditya Kumard51f2a22016-08-27 02:26:42 +0000482_LIBCPP_NORETURN _LIBCPP_FUNC_VIS
483void __throw_system_error(int ev, const char* what_arg);
Howard Hinnant3e519522010-05-11 19:42:16 +0000484
485_LIBCPP_END_NAMESPACE_STD
486
487#endif // _LIBCPP_SYSTEM_ERROR