xref: /aosp_15_r20/external/libcxx/include/system_error (revision 58b9f456b02922dfdb1fad8a988d5fd8765ecb80)
1*58b9f456SAndroid Build Coastguard Worker// -*- C++ -*-
2*58b9f456SAndroid Build Coastguard Worker//===---------------------------- system_error ----------------------------===//
3*58b9f456SAndroid Build Coastguard Worker//
4*58b9f456SAndroid Build Coastguard Worker//                     The LLVM Compiler Infrastructure
5*58b9f456SAndroid Build Coastguard Worker//
6*58b9f456SAndroid Build Coastguard Worker// This file is dual licensed under the MIT and the University of Illinois Open
7*58b9f456SAndroid Build Coastguard Worker// Source Licenses. See LICENSE.TXT for details.
8*58b9f456SAndroid Build Coastguard Worker//
9*58b9f456SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
10*58b9f456SAndroid Build Coastguard Worker
11*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_SYSTEM_ERROR
12*58b9f456SAndroid Build Coastguard Worker#define _LIBCPP_SYSTEM_ERROR
13*58b9f456SAndroid Build Coastguard Worker
14*58b9f456SAndroid Build Coastguard Worker/*
15*58b9f456SAndroid Build Coastguard Worker    system_error synopsis
16*58b9f456SAndroid Build Coastguard Worker
17*58b9f456SAndroid Build Coastguard Workernamespace std
18*58b9f456SAndroid Build Coastguard Worker{
19*58b9f456SAndroid Build Coastguard Worker
20*58b9f456SAndroid Build Coastguard Workerclass error_category
21*58b9f456SAndroid Build Coastguard Worker{
22*58b9f456SAndroid Build Coastguard Workerpublic:
23*58b9f456SAndroid Build Coastguard Worker    virtual ~error_category() noexcept;
24*58b9f456SAndroid Build Coastguard Worker
25*58b9f456SAndroid Build Coastguard Worker    constexpr error_category();
26*58b9f456SAndroid Build Coastguard Worker    error_category(const error_category&) = delete;
27*58b9f456SAndroid Build Coastguard Worker    error_category& operator=(const error_category&) = delete;
28*58b9f456SAndroid Build Coastguard Worker
29*58b9f456SAndroid Build Coastguard Worker    virtual const char* name() const noexcept = 0;
30*58b9f456SAndroid Build Coastguard Worker    virtual error_condition default_error_condition(int ev) const noexcept;
31*58b9f456SAndroid Build Coastguard Worker    virtual bool equivalent(int code, const error_condition& condition) const noexcept;
32*58b9f456SAndroid Build Coastguard Worker    virtual bool equivalent(const error_code& code, int condition) const noexcept;
33*58b9f456SAndroid Build Coastguard Worker    virtual string message(int ev) const = 0;
34*58b9f456SAndroid Build Coastguard Worker
35*58b9f456SAndroid Build Coastguard Worker    bool operator==(const error_category& rhs) const noexcept;
36*58b9f456SAndroid Build Coastguard Worker    bool operator!=(const error_category& rhs) const noexcept;
37*58b9f456SAndroid Build Coastguard Worker    bool operator<(const error_category& rhs) const noexcept;
38*58b9f456SAndroid Build Coastguard Worker};
39*58b9f456SAndroid Build Coastguard Worker
40*58b9f456SAndroid Build Coastguard Workerconst error_category& generic_category() noexcept;
41*58b9f456SAndroid Build Coastguard Workerconst error_category& system_category() noexcept;
42*58b9f456SAndroid Build Coastguard Worker
43*58b9f456SAndroid Build Coastguard Workertemplate <class T> struct is_error_code_enum
44*58b9f456SAndroid Build Coastguard Worker    : public false_type {};
45*58b9f456SAndroid Build Coastguard Worker
46*58b9f456SAndroid Build Coastguard Workertemplate <class T> struct is_error_condition_enum
47*58b9f456SAndroid Build Coastguard Worker    : public false_type {};
48*58b9f456SAndroid Build Coastguard Worker
49*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
50*58b9f456SAndroid Build Coastguard Workerinline constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17
51*58b9f456SAndroid Build Coastguard Worker
52*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
53*58b9f456SAndroid Build Coastguard Workerinline constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17
54*58b9f456SAndroid Build Coastguard Worker
55*58b9f456SAndroid Build Coastguard Workerclass error_code
56*58b9f456SAndroid Build Coastguard Worker{
57*58b9f456SAndroid Build Coastguard Workerpublic:
58*58b9f456SAndroid Build Coastguard Worker    // constructors:
59*58b9f456SAndroid Build Coastguard Worker    error_code() noexcept;
60*58b9f456SAndroid Build Coastguard Worker    error_code(int val, const error_category& cat) noexcept;
61*58b9f456SAndroid Build Coastguard Worker    template <class ErrorCodeEnum>
62*58b9f456SAndroid Build Coastguard Worker        error_code(ErrorCodeEnum e) noexcept;
63*58b9f456SAndroid Build Coastguard Worker
64*58b9f456SAndroid Build Coastguard Worker    // modifiers:
65*58b9f456SAndroid Build Coastguard Worker    void assign(int val, const error_category& cat) noexcept;
66*58b9f456SAndroid Build Coastguard Worker    template <class ErrorCodeEnum>
67*58b9f456SAndroid Build Coastguard Worker        error_code& operator=(ErrorCodeEnum e) noexcept;
68*58b9f456SAndroid Build Coastguard Worker    void clear() noexcept;
69*58b9f456SAndroid Build Coastguard Worker
70*58b9f456SAndroid Build Coastguard Worker    // observers:
71*58b9f456SAndroid Build Coastguard Worker    int value() const noexcept;
72*58b9f456SAndroid Build Coastguard Worker    const error_category& category() const noexcept;
73*58b9f456SAndroid Build Coastguard Worker    error_condition default_error_condition() const noexcept;
74*58b9f456SAndroid Build Coastguard Worker    string message() const;
75*58b9f456SAndroid Build Coastguard Worker    explicit operator bool() const noexcept;
76*58b9f456SAndroid Build Coastguard Worker};
77*58b9f456SAndroid Build Coastguard Worker
78*58b9f456SAndroid Build Coastguard Worker// non-member functions:
79*58b9f456SAndroid Build Coastguard Workerbool operator<(const error_code& lhs, const error_code& rhs) noexcept;
80*58b9f456SAndroid Build Coastguard Workertemplate <class charT, class traits>
81*58b9f456SAndroid Build Coastguard Worker    basic_ostream<charT,traits>&
82*58b9f456SAndroid Build Coastguard Worker    operator<<(basic_ostream<charT,traits>& os, const error_code& ec);
83*58b9f456SAndroid Build Coastguard Worker
84*58b9f456SAndroid Build Coastguard Workerclass error_condition
85*58b9f456SAndroid Build Coastguard Worker{
86*58b9f456SAndroid Build Coastguard Workerpublic:
87*58b9f456SAndroid Build Coastguard Worker    // constructors:
88*58b9f456SAndroid Build Coastguard Worker    error_condition() noexcept;
89*58b9f456SAndroid Build Coastguard Worker    error_condition(int val, const error_category& cat) noexcept;
90*58b9f456SAndroid Build Coastguard Worker    template <class ErrorConditionEnum>
91*58b9f456SAndroid Build Coastguard Worker        error_condition(ErrorConditionEnum e) noexcept;
92*58b9f456SAndroid Build Coastguard Worker
93*58b9f456SAndroid Build Coastguard Worker    // modifiers:
94*58b9f456SAndroid Build Coastguard Worker    void assign(int val, const error_category& cat) noexcept;
95*58b9f456SAndroid Build Coastguard Worker    template <class ErrorConditionEnum>
96*58b9f456SAndroid Build Coastguard Worker        error_condition& operator=(ErrorConditionEnum e) noexcept;
97*58b9f456SAndroid Build Coastguard Worker    void clear() noexcept;
98*58b9f456SAndroid Build Coastguard Worker
99*58b9f456SAndroid Build Coastguard Worker    // observers:
100*58b9f456SAndroid Build Coastguard Worker    int value() const noexcept;
101*58b9f456SAndroid Build Coastguard Worker    const error_category& category() const noexcept;
102*58b9f456SAndroid Build Coastguard Worker    string message() const noexcept;
103*58b9f456SAndroid Build Coastguard Worker    explicit operator bool() const noexcept;
104*58b9f456SAndroid Build Coastguard Worker};
105*58b9f456SAndroid Build Coastguard Worker
106*58b9f456SAndroid Build Coastguard Workerbool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
107*58b9f456SAndroid Build Coastguard Worker
108*58b9f456SAndroid Build Coastguard Workerclass system_error
109*58b9f456SAndroid Build Coastguard Worker    : public runtime_error
110*58b9f456SAndroid Build Coastguard Worker{
111*58b9f456SAndroid Build Coastguard Workerpublic:
112*58b9f456SAndroid Build Coastguard Worker    system_error(error_code ec, const string& what_arg);
113*58b9f456SAndroid Build Coastguard Worker    system_error(error_code ec, const char* what_arg);
114*58b9f456SAndroid Build Coastguard Worker    system_error(error_code ec);
115*58b9f456SAndroid Build Coastguard Worker    system_error(int ev, const error_category& ecat, const string& what_arg);
116*58b9f456SAndroid Build Coastguard Worker    system_error(int ev, const error_category& ecat, const char* what_arg);
117*58b9f456SAndroid Build Coastguard Worker    system_error(int ev, const error_category& ecat);
118*58b9f456SAndroid Build Coastguard Worker
119*58b9f456SAndroid Build Coastguard Worker    const error_code& code() const noexcept;
120*58b9f456SAndroid Build Coastguard Worker    const char* what() const noexcept;
121*58b9f456SAndroid Build Coastguard Worker};
122*58b9f456SAndroid Build Coastguard Worker
123*58b9f456SAndroid Build Coastguard Workertemplate <> struct is_error_condition_enum<errc>
124*58b9f456SAndroid Build Coastguard Worker    : true_type { }
125*58b9f456SAndroid Build Coastguard Worker
126*58b9f456SAndroid Build Coastguard Workererror_code make_error_code(errc e) noexcept;
127*58b9f456SAndroid Build Coastguard Workererror_condition make_error_condition(errc e) noexcept;
128*58b9f456SAndroid Build Coastguard Worker
129*58b9f456SAndroid Build Coastguard Worker// Comparison operators:
130*58b9f456SAndroid Build Coastguard Workerbool operator==(const error_code& lhs, const error_code& rhs) noexcept;
131*58b9f456SAndroid Build Coastguard Workerbool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
132*58b9f456SAndroid Build Coastguard Workerbool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
133*58b9f456SAndroid Build Coastguard Workerbool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
134*58b9f456SAndroid Build Coastguard Workerbool operator!=(const error_code& lhs, const error_code& rhs) noexcept;
135*58b9f456SAndroid Build Coastguard Workerbool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
136*58b9f456SAndroid Build Coastguard Workerbool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
137*58b9f456SAndroid Build Coastguard Workerbool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
138*58b9f456SAndroid Build Coastguard Worker
139*58b9f456SAndroid Build Coastguard Workertemplate <> struct hash<std::error_code>;
140*58b9f456SAndroid Build Coastguard Workertemplate <> struct hash<std::error_condition>;
141*58b9f456SAndroid Build Coastguard Worker
142*58b9f456SAndroid Build Coastguard Worker}  // std
143*58b9f456SAndroid Build Coastguard Worker
144*58b9f456SAndroid Build Coastguard Worker*/
145*58b9f456SAndroid Build Coastguard Worker
146*58b9f456SAndroid Build Coastguard Worker#include <__errc>
147*58b9f456SAndroid Build Coastguard Worker#include <type_traits>
148*58b9f456SAndroid Build Coastguard Worker#include <stdexcept>
149*58b9f456SAndroid Build Coastguard Worker#include <__functional_base>
150*58b9f456SAndroid Build Coastguard Worker#include <string>
151*58b9f456SAndroid Build Coastguard Worker
152*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
153*58b9f456SAndroid Build Coastguard Worker#pragma GCC system_header
154*58b9f456SAndroid Build Coastguard Worker#endif
155*58b9f456SAndroid Build Coastguard Worker
156*58b9f456SAndroid Build Coastguard Worker_LIBCPP_BEGIN_NAMESPACE_STD
157*58b9f456SAndroid Build Coastguard Worker
158*58b9f456SAndroid Build Coastguard Worker// is_error_code_enum
159*58b9f456SAndroid Build Coastguard Worker
160*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
161*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS is_error_code_enum
162*58b9f456SAndroid Build Coastguard Worker    : public false_type {};
163*58b9f456SAndroid Build Coastguard Worker
164*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER > 14
165*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
166*58b9f456SAndroid Build Coastguard Worker_LIBCPP_INLINE_VAR constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value;
167*58b9f456SAndroid Build Coastguard Worker#endif
168*58b9f456SAndroid Build Coastguard Worker
169*58b9f456SAndroid Build Coastguard Worker// is_error_condition_enum
170*58b9f456SAndroid Build Coastguard Worker
171*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
172*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum
173*58b9f456SAndroid Build Coastguard Worker    : public false_type {};
174*58b9f456SAndroid Build Coastguard Worker
175*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER > 14
176*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
177*58b9f456SAndroid Build Coastguard Worker_LIBCPP_INLINE_VAR constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value;
178*58b9f456SAndroid Build Coastguard Worker#endif
179*58b9f456SAndroid Build Coastguard Worker
180*58b9f456SAndroid Build Coastguard Workertemplate <>
181*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc>
182*58b9f456SAndroid Build Coastguard Worker    : true_type { };
183*58b9f456SAndroid Build Coastguard Worker
184*58b9f456SAndroid Build Coastguard Worker#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
185*58b9f456SAndroid Build Coastguard Workertemplate <>
186*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc::__lx>
187*58b9f456SAndroid Build Coastguard Worker    : true_type { };
188*58b9f456SAndroid Build Coastguard Worker#endif
189*58b9f456SAndroid Build Coastguard Worker
190*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS error_condition;
191*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS error_code;
192*58b9f456SAndroid Build Coastguard Worker
193*58b9f456SAndroid Build Coastguard Worker// class error_category
194*58b9f456SAndroid Build Coastguard Worker
195*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_HIDDEN __do_message;
196*58b9f456SAndroid Build Coastguard Worker
197*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS error_category
198*58b9f456SAndroid Build Coastguard Worker{
199*58b9f456SAndroid Build Coastguard Workerpublic:
200*58b9f456SAndroid Build Coastguard Worker    virtual ~error_category() _NOEXCEPT;
201*58b9f456SAndroid Build Coastguard Worker
202*58b9f456SAndroid Build Coastguard Worker#if defined(_LIBCPP_BUILDING_LIBRARY) && \
203*58b9f456SAndroid Build Coastguard Worker    defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
204*58b9f456SAndroid Build Coastguard Worker    error_category() _NOEXCEPT;
205*58b9f456SAndroid Build Coastguard Worker#else
206*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
207*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT _LIBCPP_DEFAULT
208*58b9f456SAndroid Build Coastguard Worker#endif
209*58b9f456SAndroid Build Coastguard Workerprivate:
210*58b9f456SAndroid Build Coastguard Worker    error_category(const error_category&);// = delete;
211*58b9f456SAndroid Build Coastguard Worker    error_category& operator=(const error_category&);// = delete;
212*58b9f456SAndroid Build Coastguard Worker
213*58b9f456SAndroid Build Coastguard Workerpublic:
214*58b9f456SAndroid Build Coastguard Worker    virtual const char* name() const _NOEXCEPT = 0;
215*58b9f456SAndroid Build Coastguard Worker    virtual error_condition default_error_condition(int __ev) const _NOEXCEPT;
216*58b9f456SAndroid Build Coastguard Worker    virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT;
217*58b9f456SAndroid Build Coastguard Worker    virtual bool equivalent(const error_code& __code, int __condition) const _NOEXCEPT;
218*58b9f456SAndroid Build Coastguard Worker    virtual string message(int __ev) const = 0;
219*58b9f456SAndroid Build Coastguard Worker
220*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
221*58b9f456SAndroid Build Coastguard Worker    bool operator==(const error_category& __rhs) const _NOEXCEPT {return this == &__rhs;}
222*58b9f456SAndroid Build Coastguard Worker
223*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
224*58b9f456SAndroid Build Coastguard Worker    bool operator!=(const error_category& __rhs) const _NOEXCEPT {return !(*this == __rhs);}
225*58b9f456SAndroid Build Coastguard Worker
226*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
227*58b9f456SAndroid Build Coastguard Worker    bool operator< (const error_category& __rhs) const _NOEXCEPT {return this < &__rhs;}
228*58b9f456SAndroid Build Coastguard Worker
229*58b9f456SAndroid Build Coastguard Worker    friend class _LIBCPP_HIDDEN __do_message;
230*58b9f456SAndroid Build Coastguard Worker};
231*58b9f456SAndroid Build Coastguard Worker
232*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_HIDDEN __do_message
233*58b9f456SAndroid Build Coastguard Worker    : public error_category
234*58b9f456SAndroid Build Coastguard Worker{
235*58b9f456SAndroid Build Coastguard Workerpublic:
236*58b9f456SAndroid Build Coastguard Worker    virtual string message(int ev) const;
237*58b9f456SAndroid Build Coastguard Worker};
238*58b9f456SAndroid Build Coastguard Worker
239*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS const error_category& generic_category() _NOEXCEPT;
240*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS const error_category& system_category() _NOEXCEPT;
241*58b9f456SAndroid Build Coastguard Worker
242*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS error_condition
243*58b9f456SAndroid Build Coastguard Worker{
244*58b9f456SAndroid Build Coastguard Worker    int __val_;
245*58b9f456SAndroid Build Coastguard Worker    const error_category* __cat_;
246*58b9f456SAndroid Build Coastguard Workerpublic:
247*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
248*58b9f456SAndroid Build Coastguard Worker    error_condition() _NOEXCEPT : __val_(0), __cat_(&generic_category()) {}
249*58b9f456SAndroid Build Coastguard Worker
250*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
251*58b9f456SAndroid Build Coastguard Worker    error_condition(int __val, const error_category& __cat) _NOEXCEPT
252*58b9f456SAndroid Build Coastguard Worker        : __val_(__val), __cat_(&__cat) {}
253*58b9f456SAndroid Build Coastguard Worker
254*58b9f456SAndroid Build Coastguard Worker    template <class _Ep>
255*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
256*58b9f456SAndroid Build Coastguard Worker        error_condition(_Ep __e,
257*58b9f456SAndroid Build Coastguard Worker              typename enable_if<is_error_condition_enum<_Ep>::value>::type* = 0
258*58b9f456SAndroid Build Coastguard Worker                                                                     ) _NOEXCEPT
259*58b9f456SAndroid Build Coastguard Worker            {*this = make_error_condition(__e);}
260*58b9f456SAndroid Build Coastguard Worker
261*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
262*58b9f456SAndroid Build Coastguard Worker    void assign(int __val, const error_category& __cat) _NOEXCEPT
263*58b9f456SAndroid Build Coastguard Worker    {
264*58b9f456SAndroid Build Coastguard Worker        __val_ = __val;
265*58b9f456SAndroid Build Coastguard Worker        __cat_ = &__cat;
266*58b9f456SAndroid Build Coastguard Worker    }
267*58b9f456SAndroid Build Coastguard Worker
268*58b9f456SAndroid Build Coastguard Worker    template <class _Ep>
269*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
270*58b9f456SAndroid Build Coastguard Worker        typename enable_if
271*58b9f456SAndroid Build Coastguard Worker        <
272*58b9f456SAndroid Build Coastguard Worker            is_error_condition_enum<_Ep>::value,
273*58b9f456SAndroid Build Coastguard Worker            error_condition&
274*58b9f456SAndroid Build Coastguard Worker        >::type
275*58b9f456SAndroid Build Coastguard Worker        operator=(_Ep __e) _NOEXCEPT
276*58b9f456SAndroid Build Coastguard Worker            {*this = make_error_condition(__e); return *this;}
277*58b9f456SAndroid Build Coastguard Worker
278*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
279*58b9f456SAndroid Build Coastguard Worker    void clear() _NOEXCEPT
280*58b9f456SAndroid Build Coastguard Worker    {
281*58b9f456SAndroid Build Coastguard Worker        __val_ = 0;
282*58b9f456SAndroid Build Coastguard Worker        __cat_ = &generic_category();
283*58b9f456SAndroid Build Coastguard Worker    }
284*58b9f456SAndroid Build Coastguard Worker
285*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
286*58b9f456SAndroid Build Coastguard Worker    int value() const _NOEXCEPT {return __val_;}
287*58b9f456SAndroid Build Coastguard Worker
288*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
289*58b9f456SAndroid Build Coastguard Worker    const error_category& category() const _NOEXCEPT {return *__cat_;}
290*58b9f456SAndroid Build Coastguard Worker    string message() const;
291*58b9f456SAndroid Build Coastguard Worker
292*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
293*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_EXPLICIT
294*58b9f456SAndroid Build Coastguard Worker        operator bool() const _NOEXCEPT {return __val_ != 0;}
295*58b9f456SAndroid Build Coastguard Worker};
296*58b9f456SAndroid Build Coastguard Worker
297*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
298*58b9f456SAndroid Build Coastguard Workererror_condition
299*58b9f456SAndroid Build Coastguard Workermake_error_condition(errc __e) _NOEXCEPT
300*58b9f456SAndroid Build Coastguard Worker{
301*58b9f456SAndroid Build Coastguard Worker    return error_condition(static_cast<int>(__e), generic_category());
302*58b9f456SAndroid Build Coastguard Worker}
303*58b9f456SAndroid Build Coastguard Worker
304*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
305*58b9f456SAndroid Build Coastguard Workerbool
306*58b9f456SAndroid Build Coastguard Workeroperator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT
307*58b9f456SAndroid Build Coastguard Worker{
308*58b9f456SAndroid Build Coastguard Worker    return __x.category() < __y.category()
309*58b9f456SAndroid Build Coastguard Worker        || (__x.category() == __y.category() && __x.value() < __y.value());
310*58b9f456SAndroid Build Coastguard Worker}
311*58b9f456SAndroid Build Coastguard Worker
312*58b9f456SAndroid Build Coastguard Worker// error_code
313*58b9f456SAndroid Build Coastguard Worker
314*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS error_code
315*58b9f456SAndroid Build Coastguard Worker{
316*58b9f456SAndroid Build Coastguard Worker    int __val_;
317*58b9f456SAndroid Build Coastguard Worker    const error_category* __cat_;
318*58b9f456SAndroid Build Coastguard Workerpublic:
319*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
320*58b9f456SAndroid Build Coastguard Worker    error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {}
321*58b9f456SAndroid Build Coastguard Worker
322*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
323*58b9f456SAndroid Build Coastguard Worker    error_code(int __val, const error_category& __cat) _NOEXCEPT
324*58b9f456SAndroid Build Coastguard Worker        : __val_(__val), __cat_(&__cat) {}
325*58b9f456SAndroid Build Coastguard Worker
326*58b9f456SAndroid Build Coastguard Worker    template <class _Ep>
327*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
328*58b9f456SAndroid Build Coastguard Worker        error_code(_Ep __e,
329*58b9f456SAndroid Build Coastguard Worker                   typename enable_if<is_error_code_enum<_Ep>::value>::type* = 0
330*58b9f456SAndroid Build Coastguard Worker                                                                     ) _NOEXCEPT
331*58b9f456SAndroid Build Coastguard Worker            {*this = make_error_code(__e);}
332*58b9f456SAndroid Build Coastguard Worker
333*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
334*58b9f456SAndroid Build Coastguard Worker    void assign(int __val, const error_category& __cat) _NOEXCEPT
335*58b9f456SAndroid Build Coastguard Worker    {
336*58b9f456SAndroid Build Coastguard Worker        __val_ = __val;
337*58b9f456SAndroid Build Coastguard Worker        __cat_ = &__cat;
338*58b9f456SAndroid Build Coastguard Worker    }
339*58b9f456SAndroid Build Coastguard Worker
340*58b9f456SAndroid Build Coastguard Worker    template <class _Ep>
341*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
342*58b9f456SAndroid Build Coastguard Worker        typename enable_if
343*58b9f456SAndroid Build Coastguard Worker        <
344*58b9f456SAndroid Build Coastguard Worker            is_error_code_enum<_Ep>::value,
345*58b9f456SAndroid Build Coastguard Worker            error_code&
346*58b9f456SAndroid Build Coastguard Worker        >::type
347*58b9f456SAndroid Build Coastguard Worker        operator=(_Ep __e) _NOEXCEPT
348*58b9f456SAndroid Build Coastguard Worker            {*this = make_error_code(__e); return *this;}
349*58b9f456SAndroid Build Coastguard Worker
350*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
351*58b9f456SAndroid Build Coastguard Worker    void clear() _NOEXCEPT
352*58b9f456SAndroid Build Coastguard Worker    {
353*58b9f456SAndroid Build Coastguard Worker        __val_ = 0;
354*58b9f456SAndroid Build Coastguard Worker        __cat_ = &system_category();
355*58b9f456SAndroid Build Coastguard Worker    }
356*58b9f456SAndroid Build Coastguard Worker
357*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
358*58b9f456SAndroid Build Coastguard Worker    int value() const _NOEXCEPT {return __val_;}
359*58b9f456SAndroid Build Coastguard Worker
360*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
361*58b9f456SAndroid Build Coastguard Worker    const error_category& category() const _NOEXCEPT {return *__cat_;}
362*58b9f456SAndroid Build Coastguard Worker
363*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
364*58b9f456SAndroid Build Coastguard Worker    error_condition default_error_condition() const _NOEXCEPT
365*58b9f456SAndroid Build Coastguard Worker        {return __cat_->default_error_condition(__val_);}
366*58b9f456SAndroid Build Coastguard Worker
367*58b9f456SAndroid Build Coastguard Worker    string message() const;
368*58b9f456SAndroid Build Coastguard Worker
369*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
370*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_EXPLICIT
371*58b9f456SAndroid Build Coastguard Worker        operator bool() const _NOEXCEPT {return __val_ != 0;}
372*58b9f456SAndroid Build Coastguard Worker};
373*58b9f456SAndroid Build Coastguard Worker
374*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
375*58b9f456SAndroid Build Coastguard Workererror_code
376*58b9f456SAndroid Build Coastguard Workermake_error_code(errc __e) _NOEXCEPT
377*58b9f456SAndroid Build Coastguard Worker{
378*58b9f456SAndroid Build Coastguard Worker    return error_code(static_cast<int>(__e), generic_category());
379*58b9f456SAndroid Build Coastguard Worker}
380*58b9f456SAndroid Build Coastguard Worker
381*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
382*58b9f456SAndroid Build Coastguard Workerbool
383*58b9f456SAndroid Build Coastguard Workeroperator<(const error_code& __x, const error_code& __y) _NOEXCEPT
384*58b9f456SAndroid Build Coastguard Worker{
385*58b9f456SAndroid Build Coastguard Worker    return __x.category() < __y.category()
386*58b9f456SAndroid Build Coastguard Worker        || (__x.category() == __y.category() && __x.value() < __y.value());
387*58b9f456SAndroid Build Coastguard Worker}
388*58b9f456SAndroid Build Coastguard Worker
389*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
390*58b9f456SAndroid Build Coastguard Workerbool
391*58b9f456SAndroid Build Coastguard Workeroperator==(const error_code& __x, const error_code& __y) _NOEXCEPT
392*58b9f456SAndroid Build Coastguard Worker{
393*58b9f456SAndroid Build Coastguard Worker    return __x.category() == __y.category() && __x.value() == __y.value();
394*58b9f456SAndroid Build Coastguard Worker}
395*58b9f456SAndroid Build Coastguard Worker
396*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
397*58b9f456SAndroid Build Coastguard Workerbool
398*58b9f456SAndroid Build Coastguard Workeroperator==(const error_code& __x, const error_condition& __y) _NOEXCEPT
399*58b9f456SAndroid Build Coastguard Worker{
400*58b9f456SAndroid Build Coastguard Worker    return __x.category().equivalent(__x.value(), __y)
401*58b9f456SAndroid Build Coastguard Worker        || __y.category().equivalent(__x, __y.value());
402*58b9f456SAndroid Build Coastguard Worker}
403*58b9f456SAndroid Build Coastguard Worker
404*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
405*58b9f456SAndroid Build Coastguard Workerbool
406*58b9f456SAndroid Build Coastguard Workeroperator==(const error_condition& __x, const error_code& __y) _NOEXCEPT
407*58b9f456SAndroid Build Coastguard Worker{
408*58b9f456SAndroid Build Coastguard Worker    return __y == __x;
409*58b9f456SAndroid Build Coastguard Worker}
410*58b9f456SAndroid Build Coastguard Worker
411*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
412*58b9f456SAndroid Build Coastguard Workerbool
413*58b9f456SAndroid Build Coastguard Workeroperator==(const error_condition& __x, const error_condition& __y) _NOEXCEPT
414*58b9f456SAndroid Build Coastguard Worker{
415*58b9f456SAndroid Build Coastguard Worker    return __x.category() == __y.category() && __x.value() == __y.value();
416*58b9f456SAndroid Build Coastguard Worker}
417*58b9f456SAndroid Build Coastguard Worker
418*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
419*58b9f456SAndroid Build Coastguard Workerbool
420*58b9f456SAndroid Build Coastguard Workeroperator!=(const error_code& __x, const error_code& __y) _NOEXCEPT
421*58b9f456SAndroid Build Coastguard Worker{return !(__x == __y);}
422*58b9f456SAndroid Build Coastguard Worker
423*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
424*58b9f456SAndroid Build Coastguard Workerbool
425*58b9f456SAndroid Build Coastguard Workeroperator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT
426*58b9f456SAndroid Build Coastguard Worker{return !(__x == __y);}
427*58b9f456SAndroid Build Coastguard Worker
428*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
429*58b9f456SAndroid Build Coastguard Workerbool
430*58b9f456SAndroid Build Coastguard Workeroperator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT
431*58b9f456SAndroid Build Coastguard Worker{return !(__x == __y);}
432*58b9f456SAndroid Build Coastguard Worker
433*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
434*58b9f456SAndroid Build Coastguard Workerbool
435*58b9f456SAndroid Build Coastguard Workeroperator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT
436*58b9f456SAndroid Build Coastguard Worker{return !(__x == __y);}
437*58b9f456SAndroid Build Coastguard Worker
438*58b9f456SAndroid Build Coastguard Workertemplate <>
439*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS hash<error_code>
440*58b9f456SAndroid Build Coastguard Worker    : public unary_function<error_code, size_t>
441*58b9f456SAndroid Build Coastguard Worker{
442*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
443*58b9f456SAndroid Build Coastguard Worker    size_t operator()(const error_code& __ec) const _NOEXCEPT
444*58b9f456SAndroid Build Coastguard Worker    {
445*58b9f456SAndroid Build Coastguard Worker        return static_cast<size_t>(__ec.value());
446*58b9f456SAndroid Build Coastguard Worker    }
447*58b9f456SAndroid Build Coastguard Worker};
448*58b9f456SAndroid Build Coastguard Worker
449*58b9f456SAndroid Build Coastguard Workertemplate <>
450*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS hash<error_condition>
451*58b9f456SAndroid Build Coastguard Worker    : public unary_function<error_condition, size_t>
452*58b9f456SAndroid Build Coastguard Worker{
453*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
454*58b9f456SAndroid Build Coastguard Worker    size_t operator()(const error_condition& __ec) const _NOEXCEPT
455*58b9f456SAndroid Build Coastguard Worker    {
456*58b9f456SAndroid Build Coastguard Worker        return static_cast<size_t>(__ec.value());
457*58b9f456SAndroid Build Coastguard Worker    }
458*58b9f456SAndroid Build Coastguard Worker};
459*58b9f456SAndroid Build Coastguard Worker
460*58b9f456SAndroid Build Coastguard Worker// system_error
461*58b9f456SAndroid Build Coastguard Worker
462*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS system_error
463*58b9f456SAndroid Build Coastguard Worker    : public runtime_error
464*58b9f456SAndroid Build Coastguard Worker{
465*58b9f456SAndroid Build Coastguard Worker    error_code __ec_;
466*58b9f456SAndroid Build Coastguard Workerpublic:
467*58b9f456SAndroid Build Coastguard Worker    system_error(error_code __ec, const string& __what_arg);
468*58b9f456SAndroid Build Coastguard Worker    system_error(error_code __ec, const char* __what_arg);
469*58b9f456SAndroid Build Coastguard Worker    system_error(error_code __ec);
470*58b9f456SAndroid Build Coastguard Worker    system_error(int __ev, const error_category& __ecat, const string& __what_arg);
471*58b9f456SAndroid Build Coastguard Worker    system_error(int __ev, const error_category& __ecat, const char* __what_arg);
472*58b9f456SAndroid Build Coastguard Worker    system_error(int __ev, const error_category& __ecat);
473*58b9f456SAndroid Build Coastguard Worker    ~system_error() _NOEXCEPT;
474*58b9f456SAndroid Build Coastguard Worker
475*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
476*58b9f456SAndroid Build Coastguard Worker    const error_code& code() const _NOEXCEPT {return __ec_;}
477*58b9f456SAndroid Build Coastguard Worker
478*58b9f456SAndroid Build Coastguard Workerprivate:
479*58b9f456SAndroid Build Coastguard Worker    static string __init(const error_code&, string);
480*58b9f456SAndroid Build Coastguard Worker};
481*58b9f456SAndroid Build Coastguard Worker
482*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN _LIBCPP_FUNC_VIS
483*58b9f456SAndroid Build Coastguard Workervoid __throw_system_error(int ev, const char* what_arg);
484*58b9f456SAndroid Build Coastguard Worker
485*58b9f456SAndroid Build Coastguard Worker_LIBCPP_END_NAMESPACE_STD
486*58b9f456SAndroid Build Coastguard Worker
487*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_SYSTEM_ERROR
488