13e519524SHoward Hinnant// -*- C++ -*-
2eb8650a7SLouis Dionne//===----------------------------------------------------------------------===//
33e519524SHoward Hinnant//
457b08b09SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
557b08b09SChandler Carruth// See https://llvm.org/LICENSE.txt for license information.
657b08b09SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
73e519524SHoward Hinnant//
83e519524SHoward Hinnant//===----------------------------------------------------------------------===//
93e519524SHoward Hinnant
103e519524SHoward Hinnant#ifndef _LIBCPP_SYSTEM_ERROR
113e519524SHoward Hinnant#define _LIBCPP_SYSTEM_ERROR
123e519524SHoward Hinnant
133e519524SHoward Hinnant/*
143e519524SHoward Hinnant    system_error synopsis
153e519524SHoward Hinnant
163e519524SHoward Hinnantnamespace std
173e519524SHoward Hinnant{
183e519524SHoward Hinnant
193e519524SHoward Hinnantclass error_category
203e519524SHoward Hinnant{
213e519524SHoward Hinnantpublic:
22a62f2899SHoward Hinnant    virtual ~error_category() noexcept;
233e519524SHoward Hinnant
24a86d5162SMarshall Clow    constexpr error_category();
253e519524SHoward Hinnant    error_category(const error_category&) = delete;
263e519524SHoward Hinnant    error_category& operator=(const error_category&) = delete;
273e519524SHoward Hinnant
28a62f2899SHoward Hinnant    virtual const char* name() const noexcept = 0;
29a62f2899SHoward Hinnant    virtual error_condition default_error_condition(int ev) const noexcept;
30a62f2899SHoward Hinnant    virtual bool equivalent(int code, const error_condition& condition) const noexcept;
31a62f2899SHoward Hinnant    virtual bool equivalent(const error_code& code, int condition) const noexcept;
323e519524SHoward Hinnant    virtual string message(int ev) const = 0;
333e519524SHoward Hinnant
34a62f2899SHoward Hinnant    bool operator==(const error_category& rhs) const noexcept;
35a62f2899SHoward Hinnant    bool operator!=(const error_category& rhs) const noexcept;
36a62f2899SHoward Hinnant    bool operator<(const error_category& rhs) const noexcept;
373e519524SHoward Hinnant};
383e519524SHoward Hinnant
39a62f2899SHoward Hinnantconst error_category& generic_category() noexcept;
40a62f2899SHoward Hinnantconst error_category& system_category() noexcept;
413e519524SHoward Hinnant
423e519524SHoward Hinnanttemplate <class T> struct is_error_code_enum
433e519524SHoward Hinnant    : public false_type {};
443e519524SHoward Hinnant
453e519524SHoward Hinnanttemplate <class T> struct is_error_condition_enum
463e519524SHoward Hinnant    : public false_type {};
473e519524SHoward Hinnant
48e69a08baSMarshall Clowtemplate <class _Tp>
4993df7b9fSJoe Loserinline constexpr bool is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17
50e69a08baSMarshall Clow
51e69a08baSMarshall Clowtemplate <class _Tp>
5293df7b9fSJoe Loserinline constexpr bool is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17
53e69a08baSMarshall Clow
543e519524SHoward Hinnantclass error_code
553e519524SHoward Hinnant{
563e519524SHoward Hinnantpublic:
573e519524SHoward Hinnant    // constructors:
58a62f2899SHoward Hinnant    error_code() noexcept;
59a62f2899SHoward Hinnant    error_code(int val, const error_category& cat) noexcept;
603e519524SHoward Hinnant    template <class ErrorCodeEnum>
61a62f2899SHoward Hinnant        error_code(ErrorCodeEnum e) noexcept;
623e519524SHoward Hinnant
633e519524SHoward Hinnant    // modifiers:
64a62f2899SHoward Hinnant    void assign(int val, const error_category& cat) noexcept;
653e519524SHoward Hinnant    template <class ErrorCodeEnum>
66a62f2899SHoward Hinnant        error_code& operator=(ErrorCodeEnum e) noexcept;
67a62f2899SHoward Hinnant    void clear() noexcept;
683e519524SHoward Hinnant
693e519524SHoward Hinnant    // observers:
70a62f2899SHoward Hinnant    int value() const noexcept;
71a62f2899SHoward Hinnant    const error_category& category() const noexcept;
72a62f2899SHoward Hinnant    error_condition default_error_condition() const noexcept;
733e519524SHoward Hinnant    string message() const;
74a62f2899SHoward Hinnant    explicit operator bool() const noexcept;
753e519524SHoward Hinnant};
763e519524SHoward Hinnant
773e519524SHoward Hinnant// non-member functions:
78a62f2899SHoward Hinnantbool operator<(const error_code& lhs, const error_code& rhs) noexcept;
793e519524SHoward Hinnanttemplate <class charT, class traits>
803e519524SHoward Hinnant    basic_ostream<charT,traits>&
813e519524SHoward Hinnant    operator<<(basic_ostream<charT,traits>& os, const error_code& ec);
823e519524SHoward Hinnant
833e519524SHoward Hinnantclass error_condition
843e519524SHoward Hinnant{
853e519524SHoward Hinnantpublic:
863e519524SHoward Hinnant    // constructors:
87a62f2899SHoward Hinnant    error_condition() noexcept;
88a62f2899SHoward Hinnant    error_condition(int val, const error_category& cat) noexcept;
893e519524SHoward Hinnant    template <class ErrorConditionEnum>
90a62f2899SHoward Hinnant        error_condition(ErrorConditionEnum e) noexcept;
913e519524SHoward Hinnant
923e519524SHoward Hinnant    // modifiers:
93a62f2899SHoward Hinnant    void assign(int val, const error_category& cat) noexcept;
943e519524SHoward Hinnant    template <class ErrorConditionEnum>
95a62f2899SHoward Hinnant        error_condition& operator=(ErrorConditionEnum e) noexcept;
96a62f2899SHoward Hinnant    void clear() noexcept;
973e519524SHoward Hinnant
983e519524SHoward Hinnant    // observers:
99a62f2899SHoward Hinnant    int value() const noexcept;
100a62f2899SHoward Hinnant    const error_category& category() const noexcept;
101a62f2899SHoward Hinnant    string message() const noexcept;
102a62f2899SHoward Hinnant    explicit operator bool() const noexcept;
1033e519524SHoward Hinnant};
1043e519524SHoward Hinnant
105a62f2899SHoward Hinnantbool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
1063e519524SHoward Hinnant
1073e519524SHoward Hinnantclass system_error
1083e519524SHoward Hinnant    : public runtime_error
1093e519524SHoward Hinnant{
1103e519524SHoward Hinnantpublic:
1113e519524SHoward Hinnant    system_error(error_code ec, const string& what_arg);
1123e519524SHoward Hinnant    system_error(error_code ec, const char* what_arg);
1133e519524SHoward Hinnant    system_error(error_code ec);
1143e519524SHoward Hinnant    system_error(int ev, const error_category& ecat, const string& what_arg);
1153e519524SHoward Hinnant    system_error(int ev, const error_category& ecat, const char* what_arg);
1163e519524SHoward Hinnant    system_error(int ev, const error_category& ecat);
1173e519524SHoward Hinnant
118a62f2899SHoward Hinnant    const error_code& code() const noexcept;
119a62f2899SHoward Hinnant    const char* what() const noexcept;
1203e519524SHoward Hinnant};
1213e519524SHoward Hinnant
1223e519524SHoward Hinnanttemplate <> struct is_error_condition_enum<errc>
1233e519524SHoward Hinnant    : true_type { }
1243e519524SHoward Hinnant
125a62f2899SHoward Hinnanterror_code make_error_code(errc e) noexcept;
126a62f2899SHoward Hinnanterror_condition make_error_condition(errc e) noexcept;
1273e519524SHoward Hinnant
1283e519524SHoward Hinnant// Comparison operators:
129a62f2899SHoward Hinnantbool operator==(const error_code& lhs, const error_code& rhs) noexcept;
130a62f2899SHoward Hinnantbool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
131a62f2899SHoward Hinnantbool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
132a62f2899SHoward Hinnantbool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
133a62f2899SHoward Hinnantbool operator!=(const error_code& lhs, const error_code& rhs) noexcept;
134a62f2899SHoward Hinnantbool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
135a62f2899SHoward Hinnantbool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
136a62f2899SHoward Hinnantbool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
1373e519524SHoward Hinnant
1383e519524SHoward Hinnanttemplate <> struct hash<std::error_code>;
1391c7fe126SMarshall Clowtemplate <> struct hash<std::error_condition>;
1403e519524SHoward Hinnant
1413e519524SHoward Hinnant}  // std
1423e519524SHoward Hinnant
1433e519524SHoward Hinnant*/
1443e519524SHoward Hinnant
145385cc25aSLouis Dionne#include <__assert> // all public C++ headers provide the assertion handler
14643aaf871SArthur O'Dwyer#include <__config>
1474f4effd6SZhihao Yuan#include <__errc>
148976f3705SNikolas Klauser#include <__functional/hash.h>
149050b064fSChristopher Di Bella#include <__functional/unary_function.h>
1503e519524SHoward Hinnant#include <stdexcept>
151bc455478SMarshall Clow#include <string>
15243aaf871SArthur O'Dwyer#include <type_traits>
153bd6e6846SMark de Wever#include <version>
1543e519524SHoward Hinnant
155db1978b6SNikolas Klauser// standard-mandated includes
156db1978b6SNikolas Klauser#include <compare>
157db1978b6SNikolas Klauser
158073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1593e519524SHoward Hinnant#  pragma GCC system_header
160073458b1SHoward Hinnant#endif
1613e519524SHoward Hinnant
1623e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
1633e519524SHoward Hinnant
1643e519524SHoward Hinnant// is_error_code_enum
1653e519524SHoward Hinnant
166e0601335SHoward Hinnanttemplate <class _Tp>
167e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS is_error_code_enum
1683e519524SHoward Hinnant    : public false_type {};
1693e519524SHoward Hinnant
170e69a08baSMarshall Clow#if _LIBCPP_STD_VER > 14
171e69a08baSMarshall Clowtemplate <class _Tp>
17293df7b9fSJoe Loserinline constexpr bool is_error_code_enum_v = is_error_code_enum<_Tp>::value;
173e69a08baSMarshall Clow#endif
174e69a08baSMarshall Clow
1753e519524SHoward Hinnant// is_error_condition_enum
1763e519524SHoward Hinnant
177e0601335SHoward Hinnanttemplate <class _Tp>
178e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum
1793e519524SHoward Hinnant    : public false_type {};
1803e519524SHoward Hinnant
181e69a08baSMarshall Clow#if _LIBCPP_STD_VER > 14
182e69a08baSMarshall Clowtemplate <class _Tp>
18393df7b9fSJoe Loserinline constexpr bool is_error_condition_enum_v = is_error_condition_enum<_Tp>::value;
184e69a08baSMarshall Clow#endif
185e69a08baSMarshall Clow
186e0601335SHoward Hinnanttemplate <>
187e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc>
1883e519524SHoward Hinnant    : true_type { };
1893e519524SHoward Hinnant
19093b33390SMark de Wever#ifdef _LIBCPP_CXX03_LANG
191e0601335SHoward Hinnanttemplate <>
192e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc::__lx>
1933e519524SHoward Hinnant    : true_type { };
19475689c10SHoward Hinnant#endif
1953e519524SHoward Hinnant
1966e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_condition;
1976e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_code;
1983e519524SHoward Hinnant
1993e519524SHoward Hinnant// class error_category
2003e519524SHoward Hinnant
201aeb85680SHoward Hinnantclass _LIBCPP_HIDDEN __do_message;
2023e519524SHoward Hinnant
2036e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_category
2043e519524SHoward Hinnant{
2053e519524SHoward Hinnantpublic:
206a62f2899SHoward Hinnant    virtual ~error_category() _NOEXCEPT;
2073e519524SHoward Hinnant
2080cc34ca7SLouis Dionne#if defined(_LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS)
209b9ca1e5aSLouis Dionne    error_category() noexcept;
210a86d5162SMarshall Clow#else
211dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
2124955095fSNikolas Klauser    _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT = default;
213a86d5162SMarshall Clow#endif
214feb80aa9SNikolas Klauser    error_category(const error_category&) = delete;
215feb80aa9SNikolas Klauser    error_category& operator=(const error_category&) = delete;
2163e519524SHoward Hinnant
217a62f2899SHoward Hinnant    virtual const char* name() const _NOEXCEPT = 0;
218a62f2899SHoward Hinnant    virtual error_condition default_error_condition(int __ev) const _NOEXCEPT;
219a62f2899SHoward Hinnant    virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT;
220a62f2899SHoward Hinnant    virtual bool equivalent(const error_code& __code, int __condition) const _NOEXCEPT;
2213e519524SHoward Hinnant    virtual string message(int __ev) const = 0;
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
229dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
230a62f2899SHoward Hinnant    bool operator< (const error_category& __rhs) const _NOEXCEPT {return this < &__rhs;}
2313e519524SHoward Hinnant
232aeb85680SHoward Hinnant    friend class _LIBCPP_HIDDEN __do_message;
2333e519524SHoward Hinnant};
2343e519524SHoward Hinnant
2353e519524SHoward Hinnantclass _LIBCPP_HIDDEN __do_message
2363e519524SHoward Hinnant    : public error_category
2373e519524SHoward Hinnant{
2383e519524SHoward Hinnantpublic:
239*b48c5010SNikolas Klauser    virtual string message(int __ev) const;
2403e519524SHoward Hinnant};
2413e519524SHoward Hinnant
242f0544c20SHoward Hinnant_LIBCPP_FUNC_VIS const error_category& generic_category() _NOEXCEPT;
243f0544c20SHoward Hinnant_LIBCPP_FUNC_VIS const error_category& system_category() _NOEXCEPT;
2443e519524SHoward Hinnant
2456e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_condition
2463e519524SHoward Hinnant{
2473e519524SHoward Hinnant    int __val_;
2483e519524SHoward Hinnant    const error_category* __cat_;
2493e519524SHoward Hinnantpublic:
250dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
251a62f2899SHoward Hinnant    error_condition() _NOEXCEPT : __val_(0), __cat_(&generic_category()) {}
2523e519524SHoward Hinnant
253dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
254a62f2899SHoward Hinnant    error_condition(int __val, const error_category& __cat) _NOEXCEPT
2553e519524SHoward Hinnant        : __val_(__val), __cat_(&__cat) {}
2563e519524SHoward Hinnant
257c003db1fSHoward Hinnant    template <class _Ep>
258dc7200b4SLouis Dionne        _LIBCPP_INLINE_VISIBILITY
259c003db1fSHoward Hinnant        error_condition(_Ep __e,
260527a7fdfSBruce Mitchener              typename enable_if<is_error_condition_enum<_Ep>::value>::type* = nullptr
261a62f2899SHoward Hinnant                                                                     ) _NOEXCEPT
2623e519524SHoward Hinnant            {*this = make_error_condition(__e);}
2633e519524SHoward Hinnant
264dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
265a62f2899SHoward Hinnant    void assign(int __val, const error_category& __cat) _NOEXCEPT
2663e519524SHoward Hinnant    {
2673e519524SHoward Hinnant        __val_ = __val;
2683e519524SHoward Hinnant        __cat_ = &__cat;
2693e519524SHoward Hinnant    }
2703e519524SHoward Hinnant
271c003db1fSHoward Hinnant    template <class _Ep>
272dc7200b4SLouis Dionne        _LIBCPP_INLINE_VISIBILITY
2733e519524SHoward Hinnant        typename enable_if
2743e519524SHoward Hinnant        <
275c003db1fSHoward Hinnant            is_error_condition_enum<_Ep>::value,
2763e519524SHoward Hinnant            error_condition&
2773e519524SHoward Hinnant        >::type
278c003db1fSHoward Hinnant        operator=(_Ep __e) _NOEXCEPT
2793e519524SHoward Hinnant            {*this = make_error_condition(__e); return *this;}
2803e519524SHoward Hinnant
281dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
282a62f2899SHoward Hinnant    void clear() _NOEXCEPT
2833e519524SHoward Hinnant    {
2843e519524SHoward Hinnant        __val_ = 0;
2853e519524SHoward Hinnant        __cat_ = &generic_category();
2863e519524SHoward Hinnant    }
2873e519524SHoward Hinnant
288dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
289a62f2899SHoward Hinnant    int value() const _NOEXCEPT {return __val_;}
2903e519524SHoward Hinnant
291dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
292a62f2899SHoward Hinnant    const error_category& category() const _NOEXCEPT {return *__cat_;}
2933e519524SHoward Hinnant    string message() const;
2943e519524SHoward Hinnant
295dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
296317e92a3SArthur O'Dwyer    explicit operator bool() const _NOEXCEPT {return __val_ != 0;}
2973e519524SHoward Hinnant};
2983e519524SHoward Hinnant
2993e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3003e519524SHoward Hinnanterror_condition
301a62f2899SHoward Hinnantmake_error_condition(errc __e) _NOEXCEPT
3023e519524SHoward Hinnant{
3033e519524SHoward Hinnant    return error_condition(static_cast<int>(__e), generic_category());
3043e519524SHoward Hinnant}
3053e519524SHoward Hinnant
3063e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3073e519524SHoward Hinnantbool
308a62f2899SHoward Hinnantoperator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT
3093e519524SHoward Hinnant{
3103e519524SHoward Hinnant    return __x.category() < __y.category()
311c206366fSHoward Hinnant        || (__x.category() == __y.category() && __x.value() < __y.value());
3123e519524SHoward Hinnant}
3133e519524SHoward Hinnant
3143e519524SHoward Hinnant// error_code
3153e519524SHoward Hinnant
3166e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_code
3173e519524SHoward Hinnant{
3183e519524SHoward Hinnant    int __val_;
3193e519524SHoward Hinnant    const error_category* __cat_;
3203e519524SHoward Hinnantpublic:
321dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
322a62f2899SHoward Hinnant    error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {}
3233e519524SHoward Hinnant
324dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
325a62f2899SHoward Hinnant    error_code(int __val, const error_category& __cat) _NOEXCEPT
3263e519524SHoward Hinnant        : __val_(__val), __cat_(&__cat) {}
3273e519524SHoward Hinnant
328c003db1fSHoward Hinnant    template <class _Ep>
329dc7200b4SLouis Dionne        _LIBCPP_INLINE_VISIBILITY
330c003db1fSHoward Hinnant        error_code(_Ep __e,
331527a7fdfSBruce Mitchener                   typename enable_if<is_error_code_enum<_Ep>::value>::type* = nullptr
332a62f2899SHoward Hinnant                                                                     ) _NOEXCEPT
3333e519524SHoward Hinnant            {*this = make_error_code(__e);}
3343e519524SHoward Hinnant
335dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
336a62f2899SHoward Hinnant    void assign(int __val, const error_category& __cat) _NOEXCEPT
3373e519524SHoward Hinnant    {
3383e519524SHoward Hinnant        __val_ = __val;
3393e519524SHoward Hinnant        __cat_ = &__cat;
3403e519524SHoward Hinnant    }
3413e519524SHoward Hinnant
342c003db1fSHoward Hinnant    template <class _Ep>
343dc7200b4SLouis Dionne        _LIBCPP_INLINE_VISIBILITY
3443e519524SHoward Hinnant        typename enable_if
3453e519524SHoward Hinnant        <
346c003db1fSHoward Hinnant            is_error_code_enum<_Ep>::value,
3473e519524SHoward Hinnant            error_code&
3483e519524SHoward Hinnant        >::type
349c003db1fSHoward Hinnant        operator=(_Ep __e) _NOEXCEPT
3503e519524SHoward Hinnant            {*this = make_error_code(__e); return *this;}
3513e519524SHoward Hinnant
352dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
353a62f2899SHoward Hinnant    void clear() _NOEXCEPT
3543e519524SHoward Hinnant    {
3553e519524SHoward Hinnant        __val_ = 0;
3563e519524SHoward Hinnant        __cat_ = &system_category();
3573e519524SHoward Hinnant    }
3583e519524SHoward Hinnant
359dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
360a62f2899SHoward Hinnant    int value() const _NOEXCEPT {return __val_;}
3613e519524SHoward Hinnant
362dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
363a62f2899SHoward Hinnant    const error_category& category() const _NOEXCEPT {return *__cat_;}
3643e519524SHoward Hinnant
365dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
366a62f2899SHoward Hinnant    error_condition default_error_condition() const _NOEXCEPT
3673e519524SHoward Hinnant        {return __cat_->default_error_condition(__val_);}
3683e519524SHoward Hinnant
3693e519524SHoward Hinnant    string message() const;
3703e519524SHoward Hinnant
371dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
372317e92a3SArthur O'Dwyer    explicit operator bool() const _NOEXCEPT {return __val_ != 0;}
3733e519524SHoward Hinnant};
3743e519524SHoward Hinnant
3753e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3763e519524SHoward Hinnanterror_code
377a62f2899SHoward Hinnantmake_error_code(errc __e) _NOEXCEPT
3783e519524SHoward Hinnant{
3793e519524SHoward Hinnant    return error_code(static_cast<int>(__e), generic_category());
3803e519524SHoward Hinnant}
3813e519524SHoward Hinnant
3823e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3833e519524SHoward Hinnantbool
384a62f2899SHoward Hinnantoperator<(const error_code& __x, const error_code& __y) _NOEXCEPT
3853e519524SHoward Hinnant{
3863e519524SHoward Hinnant    return __x.category() < __y.category()
387c206366fSHoward Hinnant        || (__x.category() == __y.category() && __x.value() < __y.value());
3883e519524SHoward Hinnant}
3893e519524SHoward Hinnant
3903e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3913e519524SHoward Hinnantbool
392a62f2899SHoward Hinnantoperator==(const error_code& __x, const error_code& __y) _NOEXCEPT
3933e519524SHoward Hinnant{
3943e519524SHoward Hinnant    return __x.category() == __y.category() && __x.value() == __y.value();
3953e519524SHoward Hinnant}
3963e519524SHoward Hinnant
3973e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3983e519524SHoward Hinnantbool
399a62f2899SHoward Hinnantoperator==(const error_code& __x, const error_condition& __y) _NOEXCEPT
4003e519524SHoward Hinnant{
4013e519524SHoward Hinnant    return __x.category().equivalent(__x.value(), __y)
4023e519524SHoward Hinnant        || __y.category().equivalent(__x, __y.value());
4033e519524SHoward Hinnant}
4043e519524SHoward Hinnant
4053e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4063e519524SHoward Hinnantbool
407a62f2899SHoward Hinnantoperator==(const error_condition& __x, const error_code& __y) _NOEXCEPT
4083e519524SHoward Hinnant{
4093e519524SHoward Hinnant    return __y == __x;
4103e519524SHoward Hinnant}
4113e519524SHoward Hinnant
4123e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4133e519524SHoward Hinnantbool
414a62f2899SHoward Hinnantoperator==(const error_condition& __x, const error_condition& __y) _NOEXCEPT
4153e519524SHoward Hinnant{
4163e519524SHoward Hinnant    return __x.category() == __y.category() && __x.value() == __y.value();
4173e519524SHoward Hinnant}
4183e519524SHoward Hinnant
4193e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4203e519524SHoward Hinnantbool
421a62f2899SHoward Hinnantoperator!=(const error_code& __x, const error_code& __y) _NOEXCEPT
422a62f2899SHoward Hinnant{return !(__x == __y);}
4233e519524SHoward Hinnant
4243e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4253e519524SHoward Hinnantbool
426a62f2899SHoward Hinnantoperator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT
427a62f2899SHoward Hinnant{return !(__x == __y);}
4283e519524SHoward Hinnant
4293e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4303e519524SHoward Hinnantbool
431a62f2899SHoward Hinnantoperator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT
432a62f2899SHoward Hinnant{return !(__x == __y);}
4333e519524SHoward Hinnant
4343e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4353e519524SHoward Hinnantbool
436a62f2899SHoward Hinnantoperator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT
437a62f2899SHoward Hinnant{return !(__x == __y);}
4383e519524SHoward Hinnant
4393e519524SHoward Hinnanttemplate <>
440e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<error_code>
441681cde7dSNikolas Klauser    : public __unary_function<error_code, size_t>
4423e519524SHoward Hinnant{
443e0601335SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
444a62f2899SHoward Hinnant    size_t operator()(const error_code& __ec) const _NOEXCEPT
4453e519524SHoward Hinnant    {
4463e519524SHoward Hinnant        return static_cast<size_t>(__ec.value());
4473e519524SHoward Hinnant    }
4483e519524SHoward Hinnant};
4493e519524SHoward Hinnant
4501c7fe126SMarshall Clowtemplate <>
451e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<error_condition>
452681cde7dSNikolas Klauser    : public __unary_function<error_condition, size_t>
4531c7fe126SMarshall Clow{
4541c7fe126SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
4551c7fe126SMarshall Clow    size_t operator()(const error_condition& __ec) const _NOEXCEPT
4561c7fe126SMarshall Clow    {
4571c7fe126SMarshall Clow        return static_cast<size_t>(__ec.value());
4581c7fe126SMarshall Clow    }
4591c7fe126SMarshall Clow};
4601c7fe126SMarshall Clow
4613e519524SHoward Hinnant// system_error
4623e519524SHoward Hinnant
4636e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS system_error
4643e519524SHoward Hinnant    : public runtime_error
4653e519524SHoward Hinnant{
4663e519524SHoward Hinnant    error_code __ec_;
4673e519524SHoward Hinnantpublic:
4683e519524SHoward Hinnant    system_error(error_code __ec, const string& __what_arg);
4693e519524SHoward Hinnant    system_error(error_code __ec, const char* __what_arg);
4703e519524SHoward Hinnant    system_error(error_code __ec);
4713e519524SHoward Hinnant    system_error(int __ev, const error_category& __ecat, const string& __what_arg);
4723e519524SHoward Hinnant    system_error(int __ev, const error_category& __ecat, const char* __what_arg);
4733e519524SHoward Hinnant    system_error(int __ev, const error_category& __ecat);
474585a3cc3SDimitry Andric    system_error(const system_error&) _NOEXCEPT = default;
475a62f2899SHoward Hinnant    ~system_error() _NOEXCEPT;
4763e519524SHoward Hinnant
477dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
478a62f2899SHoward Hinnant    const error_code& code() const _NOEXCEPT {return __ec_;}
4793e519524SHoward Hinnant
4803e519524SHoward Hinnantprivate:
4813e519524SHoward Hinnant    static string __init(const error_code&, string);
4823e519524SHoward Hinnant};
4833e519524SHoward Hinnant
484d51f2a2aSAditya Kumar_LIBCPP_NORETURN _LIBCPP_FUNC_VIS
485*b48c5010SNikolas Klauservoid __throw_system_error(int __ev, const char* __what_arg);
4863e519524SHoward Hinnant
4873e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD
4883e519524SHoward Hinnant
4893e519524SHoward Hinnant#endif // _LIBCPP_SYSTEM_ERROR
490