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