13e519524SHoward Hinnant// -*- C++ -*-
23e519524SHoward Hinnant//===---------------------------- system_error ----------------------------===//
33e519524SHoward Hinnant//
45b08a8a4SHoward Hinnant//                     The LLVM Compiler Infrastructure
53e519524SHoward Hinnant//
6412dbebeSHoward Hinnant// This file is dual licensed under the MIT and the University of Illinois Open
7412dbebeSHoward Hinnant// Source Licenses. See LICENSE.TXT for details.
83e519524SHoward Hinnant//
93e519524SHoward Hinnant//===----------------------------------------------------------------------===//
103e519524SHoward Hinnant
113e519524SHoward Hinnant#ifndef _LIBCPP_SYSTEM_ERROR
123e519524SHoward Hinnant#define _LIBCPP_SYSTEM_ERROR
133e519524SHoward Hinnant
143e519524SHoward Hinnant/*
153e519524SHoward Hinnant    system_error synopsis
163e519524SHoward Hinnant
173e519524SHoward Hinnantnamespace std
183e519524SHoward Hinnant{
193e519524SHoward Hinnant
203e519524SHoward Hinnantclass error_category
213e519524SHoward Hinnant{
223e519524SHoward Hinnantpublic:
23a62f2899SHoward Hinnant    virtual ~error_category() noexcept;
243e519524SHoward Hinnant
25a86d5162SMarshall Clow    constexpr error_category();
263e519524SHoward Hinnant    error_category(const error_category&) = delete;
273e519524SHoward Hinnant    error_category& operator=(const error_category&) = delete;
283e519524SHoward Hinnant
29a62f2899SHoward Hinnant    virtual const char* name() const noexcept = 0;
30a62f2899SHoward Hinnant    virtual error_condition default_error_condition(int ev) const noexcept;
31a62f2899SHoward Hinnant    virtual bool equivalent(int code, const error_condition& condition) const noexcept;
32a62f2899SHoward Hinnant    virtual bool equivalent(const error_code& code, int condition) const noexcept;
333e519524SHoward Hinnant    virtual string message(int ev) const = 0;
343e519524SHoward Hinnant
35a62f2899SHoward Hinnant    bool operator==(const error_category& rhs) const noexcept;
36a62f2899SHoward Hinnant    bool operator!=(const error_category& rhs) const noexcept;
37a62f2899SHoward Hinnant    bool operator<(const error_category& rhs) const noexcept;
383e519524SHoward Hinnant};
393e519524SHoward Hinnant
40a62f2899SHoward Hinnantconst error_category& generic_category() noexcept;
41a62f2899SHoward Hinnantconst error_category& system_category() noexcept;
423e519524SHoward Hinnant
433e519524SHoward Hinnanttemplate <class T> struct is_error_code_enum
443e519524SHoward Hinnant    : public false_type {};
453e519524SHoward Hinnant
463e519524SHoward Hinnanttemplate <class T> struct is_error_condition_enum
473e519524SHoward Hinnant    : public false_type {};
483e519524SHoward Hinnant
49e69a08baSMarshall Clowtemplate <class _Tp>
5040a01d53SMarshall Clowinline constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17
51e69a08baSMarshall Clow
52e69a08baSMarshall Clowtemplate <class _Tp>
5340a01d53SMarshall Clowinline constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17
54e69a08baSMarshall Clow
553e519524SHoward Hinnantclass error_code
563e519524SHoward Hinnant{
573e519524SHoward Hinnantpublic:
583e519524SHoward Hinnant    // constructors:
59a62f2899SHoward Hinnant    error_code() noexcept;
60a62f2899SHoward Hinnant    error_code(int val, const error_category& cat) noexcept;
613e519524SHoward Hinnant    template <class ErrorCodeEnum>
62a62f2899SHoward Hinnant        error_code(ErrorCodeEnum e) noexcept;
633e519524SHoward Hinnant
643e519524SHoward Hinnant    // modifiers:
65a62f2899SHoward Hinnant    void assign(int val, const error_category& cat) noexcept;
663e519524SHoward Hinnant    template <class ErrorCodeEnum>
67a62f2899SHoward Hinnant        error_code& operator=(ErrorCodeEnum e) noexcept;
68a62f2899SHoward Hinnant    void clear() noexcept;
693e519524SHoward Hinnant
703e519524SHoward Hinnant    // observers:
71a62f2899SHoward Hinnant    int value() const noexcept;
72a62f2899SHoward Hinnant    const error_category& category() const noexcept;
73a62f2899SHoward Hinnant    error_condition default_error_condition() const noexcept;
743e519524SHoward Hinnant    string message() const;
75a62f2899SHoward Hinnant    explicit operator bool() const noexcept;
763e519524SHoward Hinnant};
773e519524SHoward Hinnant
783e519524SHoward Hinnant// non-member functions:
79a62f2899SHoward Hinnantbool operator<(const error_code& lhs, const error_code& rhs) noexcept;
803e519524SHoward Hinnanttemplate <class charT, class traits>
813e519524SHoward Hinnant    basic_ostream<charT,traits>&
823e519524SHoward Hinnant    operator<<(basic_ostream<charT,traits>& os, const error_code& ec);
833e519524SHoward Hinnant
843e519524SHoward Hinnantclass error_condition
853e519524SHoward Hinnant{
863e519524SHoward Hinnantpublic:
873e519524SHoward Hinnant    // constructors:
88a62f2899SHoward Hinnant    error_condition() noexcept;
89a62f2899SHoward Hinnant    error_condition(int val, const error_category& cat) noexcept;
903e519524SHoward Hinnant    template <class ErrorConditionEnum>
91a62f2899SHoward Hinnant        error_condition(ErrorConditionEnum e) noexcept;
923e519524SHoward Hinnant
933e519524SHoward Hinnant    // modifiers:
94a62f2899SHoward Hinnant    void assign(int val, const error_category& cat) noexcept;
953e519524SHoward Hinnant    template <class ErrorConditionEnum>
96a62f2899SHoward Hinnant        error_condition& operator=(ErrorConditionEnum e) noexcept;
97a62f2899SHoward Hinnant    void clear() noexcept;
983e519524SHoward Hinnant
993e519524SHoward Hinnant    // observers:
100a62f2899SHoward Hinnant    int value() const noexcept;
101a62f2899SHoward Hinnant    const error_category& category() const noexcept;
102a62f2899SHoward Hinnant    string message() const noexcept;
103a62f2899SHoward Hinnant    explicit operator bool() const noexcept;
1043e519524SHoward Hinnant};
1053e519524SHoward Hinnant
106a62f2899SHoward Hinnantbool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
1073e519524SHoward Hinnant
1083e519524SHoward Hinnantclass system_error
1093e519524SHoward Hinnant    : public runtime_error
1103e519524SHoward Hinnant{
1113e519524SHoward Hinnantpublic:
1123e519524SHoward Hinnant    system_error(error_code ec, const string& what_arg);
1133e519524SHoward Hinnant    system_error(error_code ec, const char* what_arg);
1143e519524SHoward Hinnant    system_error(error_code ec);
1153e519524SHoward Hinnant    system_error(int ev, const error_category& ecat, const string& what_arg);
1163e519524SHoward Hinnant    system_error(int ev, const error_category& ecat, const char* what_arg);
1173e519524SHoward Hinnant    system_error(int ev, const error_category& ecat);
1183e519524SHoward Hinnant
119a62f2899SHoward Hinnant    const error_code& code() const noexcept;
120a62f2899SHoward Hinnant    const char* what() const noexcept;
1213e519524SHoward Hinnant};
1223e519524SHoward Hinnant
1233e519524SHoward Hinnanttemplate <> struct is_error_condition_enum<errc>
1243e519524SHoward Hinnant    : true_type { }
1253e519524SHoward Hinnant
126a62f2899SHoward Hinnanterror_code make_error_code(errc e) noexcept;
127a62f2899SHoward Hinnanterror_condition make_error_condition(errc e) noexcept;
1283e519524SHoward Hinnant
1293e519524SHoward Hinnant// Comparison operators:
130a62f2899SHoward Hinnantbool operator==(const error_code& lhs, const error_code& rhs) noexcept;
131a62f2899SHoward Hinnantbool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
132a62f2899SHoward Hinnantbool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
133a62f2899SHoward Hinnantbool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
134a62f2899SHoward Hinnantbool operator!=(const error_code& lhs, const error_code& rhs) noexcept;
135a62f2899SHoward Hinnantbool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
136a62f2899SHoward Hinnantbool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
137a62f2899SHoward Hinnantbool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
1383e519524SHoward Hinnant
1393e519524SHoward Hinnanttemplate <> struct hash<std::error_code>;
1401c7fe126SMarshall Clowtemplate <> struct hash<std::error_condition>;
1413e519524SHoward Hinnant
1423e519524SHoward Hinnant}  // std
1433e519524SHoward Hinnant
1443e519524SHoward Hinnant*/
1453e519524SHoward Hinnant
1464f4effd6SZhihao Yuan#include <__errc>
1473e519524SHoward Hinnant#include <type_traits>
1483e519524SHoward Hinnant#include <stdexcept>
1493e519524SHoward Hinnant#include <__functional_base>
150bc455478SMarshall Clow#include <string>
1513e519524SHoward Hinnant
152073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1533e519524SHoward Hinnant#pragma GCC system_header
154073458b1SHoward Hinnant#endif
1553e519524SHoward Hinnant
1563e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
1573e519524SHoward Hinnant
1583e519524SHoward Hinnant// is_error_code_enum
1593e519524SHoward Hinnant
160e0601335SHoward Hinnanttemplate <class _Tp>
161e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS is_error_code_enum
1623e519524SHoward Hinnant    : public false_type {};
1633e519524SHoward Hinnant
164e69a08baSMarshall Clow#if _LIBCPP_STD_VER > 14
165e69a08baSMarshall Clowtemplate <class _Tp>
16640a01d53SMarshall Clow_LIBCPP_INLINE_VAR constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value;
167e69a08baSMarshall Clow#endif
168e69a08baSMarshall Clow
1693e519524SHoward Hinnant// is_error_condition_enum
1703e519524SHoward Hinnant
171e0601335SHoward Hinnanttemplate <class _Tp>
172e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum
1733e519524SHoward Hinnant    : public false_type {};
1743e519524SHoward Hinnant
175e69a08baSMarshall Clow#if _LIBCPP_STD_VER > 14
176e69a08baSMarshall Clowtemplate <class _Tp>
17740a01d53SMarshall Clow_LIBCPP_INLINE_VAR constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value;
178e69a08baSMarshall Clow#endif
179e69a08baSMarshall Clow
180e0601335SHoward Hinnanttemplate <>
181e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc>
1823e519524SHoward Hinnant    : true_type { };
1833e519524SHoward Hinnant
18475689c10SHoward Hinnant#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
185e0601335SHoward Hinnanttemplate <>
186e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc::__lx>
1873e519524SHoward Hinnant    : true_type { };
18875689c10SHoward Hinnant#endif
1893e519524SHoward Hinnant
1906e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_condition;
1916e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_code;
1923e519524SHoward Hinnant
1933e519524SHoward Hinnant// class error_category
1943e519524SHoward Hinnant
195aeb85680SHoward Hinnantclass _LIBCPP_HIDDEN __do_message;
1963e519524SHoward Hinnant
1976e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_category
1983e519524SHoward Hinnant{
1993e519524SHoward Hinnantpublic:
200a62f2899SHoward Hinnant    virtual ~error_category() _NOEXCEPT;
2013e519524SHoward Hinnant
202*c8e84ff2SLouis Dionne#if defined(_LIBCPP_BUILDING_LIBRARY) && \
20311f60453SEric Fiselier    defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
204a62f2899SHoward Hinnant    error_category() _NOEXCEPT;
205a86d5162SMarshall Clow#else
206dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
207e57e3aebSEric Fiselier    _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT _LIBCPP_DEFAULT
208a86d5162SMarshall Clow#endif
209cb16c680SHoward Hinnantprivate:
2103e519524SHoward Hinnant    error_category(const error_category&);// = delete;
2113e519524SHoward Hinnant    error_category& operator=(const error_category&);// = delete;
2123e519524SHoward Hinnant
2133e519524SHoward Hinnantpublic:
214a62f2899SHoward Hinnant    virtual const char* name() const _NOEXCEPT = 0;
215a62f2899SHoward Hinnant    virtual error_condition default_error_condition(int __ev) const _NOEXCEPT;
216a62f2899SHoward Hinnant    virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT;
217a62f2899SHoward Hinnant    virtual bool equivalent(const error_code& __code, int __condition) const _NOEXCEPT;
2183e519524SHoward Hinnant    virtual string message(int __ev) const = 0;
2193e519524SHoward Hinnant
220dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
221a62f2899SHoward Hinnant    bool operator==(const error_category& __rhs) const _NOEXCEPT {return this == &__rhs;}
2223e519524SHoward Hinnant
223dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
224a62f2899SHoward Hinnant    bool operator!=(const error_category& __rhs) const _NOEXCEPT {return !(*this == __rhs);}
2253e519524SHoward Hinnant
226dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
227a62f2899SHoward Hinnant    bool operator< (const error_category& __rhs) const _NOEXCEPT {return this < &__rhs;}
2283e519524SHoward Hinnant
229aeb85680SHoward Hinnant    friend class _LIBCPP_HIDDEN __do_message;
2303e519524SHoward Hinnant};
2313e519524SHoward Hinnant
2323e519524SHoward Hinnantclass _LIBCPP_HIDDEN __do_message
2333e519524SHoward Hinnant    : public error_category
2343e519524SHoward Hinnant{
2353e519524SHoward Hinnantpublic:
2363e519524SHoward Hinnant    virtual string message(int ev) const;
2373e519524SHoward Hinnant};
2383e519524SHoward Hinnant
239f0544c20SHoward Hinnant_LIBCPP_FUNC_VIS const error_category& generic_category() _NOEXCEPT;
240f0544c20SHoward Hinnant_LIBCPP_FUNC_VIS const error_category& system_category() _NOEXCEPT;
2413e519524SHoward Hinnant
2426e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_condition
2433e519524SHoward Hinnant{
2443e519524SHoward Hinnant    int __val_;
2453e519524SHoward Hinnant    const error_category* __cat_;
2463e519524SHoward Hinnantpublic:
247dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
248a62f2899SHoward Hinnant    error_condition() _NOEXCEPT : __val_(0), __cat_(&generic_category()) {}
2493e519524SHoward Hinnant
250dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
251a62f2899SHoward Hinnant    error_condition(int __val, const error_category& __cat) _NOEXCEPT
2523e519524SHoward Hinnant        : __val_(__val), __cat_(&__cat) {}
2533e519524SHoward Hinnant
254c003db1fSHoward Hinnant    template <class _Ep>
255dc7200b4SLouis Dionne        _LIBCPP_INLINE_VISIBILITY
256c003db1fSHoward Hinnant        error_condition(_Ep __e,
257c003db1fSHoward Hinnant              typename enable_if<is_error_condition_enum<_Ep>::value>::type* = 0
258a62f2899SHoward Hinnant                                                                     ) _NOEXCEPT
2593e519524SHoward Hinnant            {*this = make_error_condition(__e);}
2603e519524SHoward Hinnant
261dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
262a62f2899SHoward Hinnant    void assign(int __val, const error_category& __cat) _NOEXCEPT
2633e519524SHoward Hinnant    {
2643e519524SHoward Hinnant        __val_ = __val;
2653e519524SHoward Hinnant        __cat_ = &__cat;
2663e519524SHoward Hinnant    }
2673e519524SHoward Hinnant
268c003db1fSHoward Hinnant    template <class _Ep>
269dc7200b4SLouis Dionne        _LIBCPP_INLINE_VISIBILITY
2703e519524SHoward Hinnant        typename enable_if
2713e519524SHoward Hinnant        <
272c003db1fSHoward Hinnant            is_error_condition_enum<_Ep>::value,
2733e519524SHoward Hinnant            error_condition&
2743e519524SHoward Hinnant        >::type
275c003db1fSHoward Hinnant        operator=(_Ep __e) _NOEXCEPT
2763e519524SHoward Hinnant            {*this = make_error_condition(__e); return *this;}
2773e519524SHoward Hinnant
278dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
279a62f2899SHoward Hinnant    void clear() _NOEXCEPT
2803e519524SHoward Hinnant    {
2813e519524SHoward Hinnant        __val_ = 0;
2823e519524SHoward Hinnant        __cat_ = &generic_category();
2833e519524SHoward Hinnant    }
2843e519524SHoward Hinnant
285dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
286a62f2899SHoward Hinnant    int value() const _NOEXCEPT {return __val_;}
2873e519524SHoward Hinnant
288dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
289a62f2899SHoward Hinnant    const error_category& category() const _NOEXCEPT {return *__cat_;}
2903e519524SHoward Hinnant    string message() const;
2913e519524SHoward Hinnant
292dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
293f2f2d8b9SHoward Hinnant        _LIBCPP_EXPLICIT
294a62f2899SHoward Hinnant        operator bool() const _NOEXCEPT {return __val_ != 0;}
2953e519524SHoward Hinnant};
2963e519524SHoward Hinnant
2973e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
2983e519524SHoward Hinnanterror_condition
299a62f2899SHoward Hinnantmake_error_condition(errc __e) _NOEXCEPT
3003e519524SHoward Hinnant{
3013e519524SHoward Hinnant    return error_condition(static_cast<int>(__e), generic_category());
3023e519524SHoward Hinnant}
3033e519524SHoward Hinnant
3043e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3053e519524SHoward Hinnantbool
306a62f2899SHoward Hinnantoperator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT
3073e519524SHoward Hinnant{
3083e519524SHoward Hinnant    return __x.category() < __y.category()
309c206366fSHoward Hinnant        || (__x.category() == __y.category() && __x.value() < __y.value());
3103e519524SHoward Hinnant}
3113e519524SHoward Hinnant
3123e519524SHoward Hinnant// error_code
3133e519524SHoward Hinnant
3146e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_code
3153e519524SHoward Hinnant{
3163e519524SHoward Hinnant    int __val_;
3173e519524SHoward Hinnant    const error_category* __cat_;
3183e519524SHoward Hinnantpublic:
319dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
320a62f2899SHoward Hinnant    error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {}
3213e519524SHoward Hinnant
322dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
323a62f2899SHoward Hinnant    error_code(int __val, const error_category& __cat) _NOEXCEPT
3243e519524SHoward Hinnant        : __val_(__val), __cat_(&__cat) {}
3253e519524SHoward Hinnant
326c003db1fSHoward Hinnant    template <class _Ep>
327dc7200b4SLouis Dionne        _LIBCPP_INLINE_VISIBILITY
328c003db1fSHoward Hinnant        error_code(_Ep __e,
329c003db1fSHoward Hinnant                   typename enable_if<is_error_code_enum<_Ep>::value>::type* = 0
330a62f2899SHoward Hinnant                                                                     ) _NOEXCEPT
3313e519524SHoward Hinnant            {*this = make_error_code(__e);}
3323e519524SHoward Hinnant
333dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
334a62f2899SHoward Hinnant    void assign(int __val, const error_category& __cat) _NOEXCEPT
3353e519524SHoward Hinnant    {
3363e519524SHoward Hinnant        __val_ = __val;
3373e519524SHoward Hinnant        __cat_ = &__cat;
3383e519524SHoward Hinnant    }
3393e519524SHoward Hinnant
340c003db1fSHoward Hinnant    template <class _Ep>
341dc7200b4SLouis Dionne        _LIBCPP_INLINE_VISIBILITY
3423e519524SHoward Hinnant        typename enable_if
3433e519524SHoward Hinnant        <
344c003db1fSHoward Hinnant            is_error_code_enum<_Ep>::value,
3453e519524SHoward Hinnant            error_code&
3463e519524SHoward Hinnant        >::type
347c003db1fSHoward Hinnant        operator=(_Ep __e) _NOEXCEPT
3483e519524SHoward Hinnant            {*this = make_error_code(__e); return *this;}
3493e519524SHoward Hinnant
350dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
351a62f2899SHoward Hinnant    void clear() _NOEXCEPT
3523e519524SHoward Hinnant    {
3533e519524SHoward Hinnant        __val_ = 0;
3543e519524SHoward Hinnant        __cat_ = &system_category();
3553e519524SHoward Hinnant    }
3563e519524SHoward Hinnant
357dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
358a62f2899SHoward Hinnant    int value() const _NOEXCEPT {return __val_;}
3593e519524SHoward Hinnant
360dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
361a62f2899SHoward Hinnant    const error_category& category() const _NOEXCEPT {return *__cat_;}
3623e519524SHoward Hinnant
363dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
364a62f2899SHoward Hinnant    error_condition default_error_condition() const _NOEXCEPT
3653e519524SHoward Hinnant        {return __cat_->default_error_condition(__val_);}
3663e519524SHoward Hinnant
3673e519524SHoward Hinnant    string message() const;
3683e519524SHoward Hinnant
369dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
370f2f2d8b9SHoward Hinnant        _LIBCPP_EXPLICIT
371a62f2899SHoward Hinnant        operator bool() const _NOEXCEPT {return __val_ != 0;}
3723e519524SHoward Hinnant};
3733e519524SHoward Hinnant
3743e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3753e519524SHoward Hinnanterror_code
376a62f2899SHoward Hinnantmake_error_code(errc __e) _NOEXCEPT
3773e519524SHoward Hinnant{
3783e519524SHoward Hinnant    return error_code(static_cast<int>(__e), generic_category());
3793e519524SHoward Hinnant}
3803e519524SHoward Hinnant
3813e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3823e519524SHoward Hinnantbool
383a62f2899SHoward Hinnantoperator<(const error_code& __x, const error_code& __y) _NOEXCEPT
3843e519524SHoward Hinnant{
3853e519524SHoward Hinnant    return __x.category() < __y.category()
386c206366fSHoward Hinnant        || (__x.category() == __y.category() && __x.value() < __y.value());
3873e519524SHoward Hinnant}
3883e519524SHoward Hinnant
3893e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3903e519524SHoward Hinnantbool
391a62f2899SHoward Hinnantoperator==(const error_code& __x, const error_code& __y) _NOEXCEPT
3923e519524SHoward Hinnant{
3933e519524SHoward Hinnant    return __x.category() == __y.category() && __x.value() == __y.value();
3943e519524SHoward Hinnant}
3953e519524SHoward Hinnant
3963e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3973e519524SHoward Hinnantbool
398a62f2899SHoward Hinnantoperator==(const error_code& __x, const error_condition& __y) _NOEXCEPT
3993e519524SHoward Hinnant{
4003e519524SHoward Hinnant    return __x.category().equivalent(__x.value(), __y)
4013e519524SHoward Hinnant        || __y.category().equivalent(__x, __y.value());
4023e519524SHoward Hinnant}
4033e519524SHoward Hinnant
4043e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4053e519524SHoward Hinnantbool
406a62f2899SHoward Hinnantoperator==(const error_condition& __x, const error_code& __y) _NOEXCEPT
4073e519524SHoward Hinnant{
4083e519524SHoward Hinnant    return __y == __x;
4093e519524SHoward Hinnant}
4103e519524SHoward Hinnant
4113e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4123e519524SHoward Hinnantbool
413a62f2899SHoward Hinnantoperator==(const error_condition& __x, const error_condition& __y) _NOEXCEPT
4143e519524SHoward Hinnant{
4153e519524SHoward Hinnant    return __x.category() == __y.category() && __x.value() == __y.value();
4163e519524SHoward Hinnant}
4173e519524SHoward Hinnant
4183e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4193e519524SHoward Hinnantbool
420a62f2899SHoward Hinnantoperator!=(const error_code& __x, const error_code& __y) _NOEXCEPT
421a62f2899SHoward Hinnant{return !(__x == __y);}
4223e519524SHoward Hinnant
4233e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4243e519524SHoward Hinnantbool
425a62f2899SHoward Hinnantoperator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT
426a62f2899SHoward Hinnant{return !(__x == __y);}
4273e519524SHoward Hinnant
4283e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4293e519524SHoward Hinnantbool
430a62f2899SHoward Hinnantoperator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT
431a62f2899SHoward Hinnant{return !(__x == __y);}
4323e519524SHoward Hinnant
4333e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4343e519524SHoward Hinnantbool
435a62f2899SHoward Hinnantoperator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT
436a62f2899SHoward Hinnant{return !(__x == __y);}
4373e519524SHoward Hinnant
4383e519524SHoward Hinnanttemplate <>
439e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<error_code>
4403e519524SHoward Hinnant    : public unary_function<error_code, size_t>
4413e519524SHoward Hinnant{
442e0601335SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
443a62f2899SHoward Hinnant    size_t operator()(const error_code& __ec) const _NOEXCEPT
4443e519524SHoward Hinnant    {
4453e519524SHoward Hinnant        return static_cast<size_t>(__ec.value());
4463e519524SHoward Hinnant    }
4473e519524SHoward Hinnant};
4483e519524SHoward Hinnant
4491c7fe126SMarshall Clowtemplate <>
450e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<error_condition>
4511c7fe126SMarshall Clow    : public unary_function<error_condition, size_t>
4521c7fe126SMarshall Clow{
4531c7fe126SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
4541c7fe126SMarshall Clow    size_t operator()(const error_condition& __ec) const _NOEXCEPT
4551c7fe126SMarshall Clow    {
4561c7fe126SMarshall Clow        return static_cast<size_t>(__ec.value());
4571c7fe126SMarshall Clow    }
4581c7fe126SMarshall Clow};
4591c7fe126SMarshall Clow
4603e519524SHoward Hinnant// system_error
4613e519524SHoward Hinnant
4626e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS system_error
4633e519524SHoward Hinnant    : public runtime_error
4643e519524SHoward Hinnant{
4653e519524SHoward Hinnant    error_code __ec_;
4663e519524SHoward Hinnantpublic:
4673e519524SHoward Hinnant    system_error(error_code __ec, const string& __what_arg);
4683e519524SHoward Hinnant    system_error(error_code __ec, const char* __what_arg);
4693e519524SHoward Hinnant    system_error(error_code __ec);
4703e519524SHoward Hinnant    system_error(int __ev, const error_category& __ecat, const string& __what_arg);
4713e519524SHoward Hinnant    system_error(int __ev, const error_category& __ecat, const char* __what_arg);
4723e519524SHoward Hinnant    system_error(int __ev, const error_category& __ecat);
473a62f2899SHoward Hinnant    ~system_error() _NOEXCEPT;
4743e519524SHoward Hinnant
475dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
476a62f2899SHoward Hinnant    const error_code& code() const _NOEXCEPT {return __ec_;}
4773e519524SHoward Hinnant
4783e519524SHoward Hinnantprivate:
4793e519524SHoward Hinnant    static string __init(const error_code&, string);
4803e519524SHoward Hinnant};
4813e519524SHoward Hinnant
482d51f2a2aSAditya Kumar_LIBCPP_NORETURN _LIBCPP_FUNC_VIS
483d51f2a2aSAditya Kumarvoid __throw_system_error(int ev, const char* what_arg);
4843e519524SHoward Hinnant
4853e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD
4863e519524SHoward Hinnant
4873e519524SHoward Hinnant#endif  // _LIBCPP_SYSTEM_ERROR
488