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>
148050b064fSChristopher Di Bella#include <__functional/unary_function.h>
1492d0f1fa4SArthur O'Dwyer#include <compare>
1503e519524SHoward Hinnant#include <stdexcept>
151bc455478SMarshall Clow#include <string>
15243aaf871SArthur O'Dwyer#include <type_traits>
153bd6e6846SMark de Wever#include <version>
1543e519524SHoward Hinnant
155073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1563e519524SHoward Hinnant#  pragma GCC system_header
157073458b1SHoward Hinnant#endif
1583e519524SHoward Hinnant
1593e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
1603e519524SHoward Hinnant
1613e519524SHoward Hinnant// is_error_code_enum
1623e519524SHoward Hinnant
163e0601335SHoward Hinnanttemplate <class _Tp>
164e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS is_error_code_enum
1653e519524SHoward Hinnant    : public false_type {};
1663e519524SHoward Hinnant
167e69a08baSMarshall Clow#if _LIBCPP_STD_VER > 14
168e69a08baSMarshall Clowtemplate <class _Tp>
16993df7b9fSJoe Loserinline constexpr bool is_error_code_enum_v = is_error_code_enum<_Tp>::value;
170e69a08baSMarshall Clow#endif
171e69a08baSMarshall Clow
1723e519524SHoward Hinnant// is_error_condition_enum
1733e519524SHoward Hinnant
174e0601335SHoward Hinnanttemplate <class _Tp>
175e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum
1763e519524SHoward Hinnant    : public false_type {};
1773e519524SHoward Hinnant
178e69a08baSMarshall Clow#if _LIBCPP_STD_VER > 14
179e69a08baSMarshall Clowtemplate <class _Tp>
18093df7b9fSJoe Loserinline constexpr bool is_error_condition_enum_v = is_error_condition_enum<_Tp>::value;
181e69a08baSMarshall Clow#endif
182e69a08baSMarshall Clow
183e0601335SHoward Hinnanttemplate <>
184e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc>
1853e519524SHoward Hinnant    : true_type { };
1863e519524SHoward Hinnant
18793b33390SMark de Wever#ifdef _LIBCPP_CXX03_LANG
188e0601335SHoward Hinnanttemplate <>
189e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc::__lx>
1903e519524SHoward Hinnant    : true_type { };
19175689c10SHoward Hinnant#endif
1923e519524SHoward Hinnant
1936e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_condition;
1946e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_code;
1953e519524SHoward Hinnant
1963e519524SHoward Hinnant// class error_category
1973e519524SHoward Hinnant
198aeb85680SHoward Hinnantclass _LIBCPP_HIDDEN __do_message;
1993e519524SHoward Hinnant
2006e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_category
2013e519524SHoward Hinnant{
2023e519524SHoward Hinnantpublic:
203a62f2899SHoward Hinnant    virtual ~error_category() _NOEXCEPT;
2043e519524SHoward Hinnant
205*0cc34ca7SLouis Dionne#if defined(_LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS)
206b9ca1e5aSLouis Dionne    error_category() noexcept;
207a86d5162SMarshall Clow#else
208dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
2094955095fSNikolas Klauser    _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT = default;
210a86d5162SMarshall Clow#endif
211feb80aa9SNikolas Klauser    error_category(const error_category&) = delete;
212feb80aa9SNikolas Klauser    error_category& operator=(const error_category&) = delete;
2133e519524SHoward Hinnant
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,
257527a7fdfSBruce Mitchener              typename enable_if<is_error_condition_enum<_Ep>::value>::type* = nullptr
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
293317e92a3SArthur O'Dwyer    explicit operator bool() const _NOEXCEPT {return __val_ != 0;}
2943e519524SHoward Hinnant};
2953e519524SHoward Hinnant
2963e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
2973e519524SHoward Hinnanterror_condition
298a62f2899SHoward Hinnantmake_error_condition(errc __e) _NOEXCEPT
2993e519524SHoward Hinnant{
3003e519524SHoward Hinnant    return error_condition(static_cast<int>(__e), generic_category());
3013e519524SHoward Hinnant}
3023e519524SHoward Hinnant
3033e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3043e519524SHoward Hinnantbool
305a62f2899SHoward Hinnantoperator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT
3063e519524SHoward Hinnant{
3073e519524SHoward Hinnant    return __x.category() < __y.category()
308c206366fSHoward Hinnant        || (__x.category() == __y.category() && __x.value() < __y.value());
3093e519524SHoward Hinnant}
3103e519524SHoward Hinnant
3113e519524SHoward Hinnant// error_code
3123e519524SHoward Hinnant
3136e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_code
3143e519524SHoward Hinnant{
3153e519524SHoward Hinnant    int __val_;
3163e519524SHoward Hinnant    const error_category* __cat_;
3173e519524SHoward Hinnantpublic:
318dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
319a62f2899SHoward Hinnant    error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {}
3203e519524SHoward Hinnant
321dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
322a62f2899SHoward Hinnant    error_code(int __val, const error_category& __cat) _NOEXCEPT
3233e519524SHoward Hinnant        : __val_(__val), __cat_(&__cat) {}
3243e519524SHoward Hinnant
325c003db1fSHoward Hinnant    template <class _Ep>
326dc7200b4SLouis Dionne        _LIBCPP_INLINE_VISIBILITY
327c003db1fSHoward Hinnant        error_code(_Ep __e,
328527a7fdfSBruce Mitchener                   typename enable_if<is_error_code_enum<_Ep>::value>::type* = nullptr
329a62f2899SHoward Hinnant                                                                     ) _NOEXCEPT
3303e519524SHoward Hinnant            {*this = make_error_code(__e);}
3313e519524SHoward Hinnant
332dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
333a62f2899SHoward Hinnant    void assign(int __val, const error_category& __cat) _NOEXCEPT
3343e519524SHoward Hinnant    {
3353e519524SHoward Hinnant        __val_ = __val;
3363e519524SHoward Hinnant        __cat_ = &__cat;
3373e519524SHoward Hinnant    }
3383e519524SHoward Hinnant
339c003db1fSHoward Hinnant    template <class _Ep>
340dc7200b4SLouis Dionne        _LIBCPP_INLINE_VISIBILITY
3413e519524SHoward Hinnant        typename enable_if
3423e519524SHoward Hinnant        <
343c003db1fSHoward Hinnant            is_error_code_enum<_Ep>::value,
3443e519524SHoward Hinnant            error_code&
3453e519524SHoward Hinnant        >::type
346c003db1fSHoward Hinnant        operator=(_Ep __e) _NOEXCEPT
3473e519524SHoward Hinnant            {*this = make_error_code(__e); return *this;}
3483e519524SHoward Hinnant
349dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
350a62f2899SHoward Hinnant    void clear() _NOEXCEPT
3513e519524SHoward Hinnant    {
3523e519524SHoward Hinnant        __val_ = 0;
3533e519524SHoward Hinnant        __cat_ = &system_category();
3543e519524SHoward Hinnant    }
3553e519524SHoward Hinnant
356dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
357a62f2899SHoward Hinnant    int value() const _NOEXCEPT {return __val_;}
3583e519524SHoward Hinnant
359dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
360a62f2899SHoward Hinnant    const error_category& category() const _NOEXCEPT {return *__cat_;}
3613e519524SHoward Hinnant
362dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
363a62f2899SHoward Hinnant    error_condition default_error_condition() const _NOEXCEPT
3643e519524SHoward Hinnant        {return __cat_->default_error_condition(__val_);}
3653e519524SHoward Hinnant
3663e519524SHoward Hinnant    string message() const;
3673e519524SHoward Hinnant
368dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
369317e92a3SArthur O'Dwyer    explicit operator bool() const _NOEXCEPT {return __val_ != 0;}
3703e519524SHoward Hinnant};
3713e519524SHoward Hinnant
3723e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3733e519524SHoward Hinnanterror_code
374a62f2899SHoward Hinnantmake_error_code(errc __e) _NOEXCEPT
3753e519524SHoward Hinnant{
3763e519524SHoward Hinnant    return error_code(static_cast<int>(__e), generic_category());
3773e519524SHoward Hinnant}
3783e519524SHoward Hinnant
3793e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3803e519524SHoward Hinnantbool
381a62f2899SHoward Hinnantoperator<(const error_code& __x, const error_code& __y) _NOEXCEPT
3823e519524SHoward Hinnant{
3833e519524SHoward Hinnant    return __x.category() < __y.category()
384c206366fSHoward Hinnant        || (__x.category() == __y.category() && __x.value() < __y.value());
3853e519524SHoward Hinnant}
3863e519524SHoward Hinnant
3873e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3883e519524SHoward Hinnantbool
389a62f2899SHoward Hinnantoperator==(const error_code& __x, const error_code& __y) _NOEXCEPT
3903e519524SHoward Hinnant{
3913e519524SHoward Hinnant    return __x.category() == __y.category() && __x.value() == __y.value();
3923e519524SHoward Hinnant}
3933e519524SHoward Hinnant
3943e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3953e519524SHoward Hinnantbool
396a62f2899SHoward Hinnantoperator==(const error_code& __x, const error_condition& __y) _NOEXCEPT
3973e519524SHoward Hinnant{
3983e519524SHoward Hinnant    return __x.category().equivalent(__x.value(), __y)
3993e519524SHoward Hinnant        || __y.category().equivalent(__x, __y.value());
4003e519524SHoward Hinnant}
4013e519524SHoward Hinnant
4023e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4033e519524SHoward Hinnantbool
404a62f2899SHoward Hinnantoperator==(const error_condition& __x, const error_code& __y) _NOEXCEPT
4053e519524SHoward Hinnant{
4063e519524SHoward Hinnant    return __y == __x;
4073e519524SHoward Hinnant}
4083e519524SHoward Hinnant
4093e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4103e519524SHoward Hinnantbool
411a62f2899SHoward Hinnantoperator==(const error_condition& __x, const error_condition& __y) _NOEXCEPT
4123e519524SHoward Hinnant{
4133e519524SHoward Hinnant    return __x.category() == __y.category() && __x.value() == __y.value();
4143e519524SHoward Hinnant}
4153e519524SHoward Hinnant
4163e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4173e519524SHoward Hinnantbool
418a62f2899SHoward Hinnantoperator!=(const error_code& __x, const error_code& __y) _NOEXCEPT
419a62f2899SHoward Hinnant{return !(__x == __y);}
4203e519524SHoward Hinnant
4213e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4223e519524SHoward Hinnantbool
423a62f2899SHoward Hinnantoperator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT
424a62f2899SHoward Hinnant{return !(__x == __y);}
4253e519524SHoward Hinnant
4263e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4273e519524SHoward Hinnantbool
428a62f2899SHoward Hinnantoperator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT
429a62f2899SHoward Hinnant{return !(__x == __y);}
4303e519524SHoward Hinnant
4313e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4323e519524SHoward Hinnantbool
433a62f2899SHoward Hinnantoperator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT
434a62f2899SHoward Hinnant{return !(__x == __y);}
4353e519524SHoward Hinnant
4363e519524SHoward Hinnanttemplate <>
437e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<error_code>
4383e519524SHoward Hinnant    : public unary_function<error_code, size_t>
4393e519524SHoward Hinnant{
440e0601335SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
441a62f2899SHoward Hinnant    size_t operator()(const error_code& __ec) const _NOEXCEPT
4423e519524SHoward Hinnant    {
4433e519524SHoward Hinnant        return static_cast<size_t>(__ec.value());
4443e519524SHoward Hinnant    }
4453e519524SHoward Hinnant};
4463e519524SHoward Hinnant
4471c7fe126SMarshall Clowtemplate <>
448e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<error_condition>
4491c7fe126SMarshall Clow    : public unary_function<error_condition, size_t>
4501c7fe126SMarshall Clow{
4511c7fe126SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
4521c7fe126SMarshall Clow    size_t operator()(const error_condition& __ec) const _NOEXCEPT
4531c7fe126SMarshall Clow    {
4541c7fe126SMarshall Clow        return static_cast<size_t>(__ec.value());
4551c7fe126SMarshall Clow    }
4561c7fe126SMarshall Clow};
4571c7fe126SMarshall Clow
4583e519524SHoward Hinnant// system_error
4593e519524SHoward Hinnant
4606e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS system_error
4613e519524SHoward Hinnant    : public runtime_error
4623e519524SHoward Hinnant{
4633e519524SHoward Hinnant    error_code __ec_;
4643e519524SHoward Hinnantpublic:
4653e519524SHoward Hinnant    system_error(error_code __ec, const string& __what_arg);
4663e519524SHoward Hinnant    system_error(error_code __ec, const char* __what_arg);
4673e519524SHoward Hinnant    system_error(error_code __ec);
4683e519524SHoward Hinnant    system_error(int __ev, const error_category& __ecat, const string& __what_arg);
4693e519524SHoward Hinnant    system_error(int __ev, const error_category& __ecat, const char* __what_arg);
4703e519524SHoward Hinnant    system_error(int __ev, const error_category& __ecat);
471585a3cc3SDimitry Andric    system_error(const system_error&) _NOEXCEPT = default;
472a62f2899SHoward Hinnant    ~system_error() _NOEXCEPT;
4733e519524SHoward Hinnant
474dc7200b4SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
475a62f2899SHoward Hinnant    const error_code& code() const _NOEXCEPT {return __ec_;}
4763e519524SHoward Hinnant
4773e519524SHoward Hinnantprivate:
4783e519524SHoward Hinnant    static string __init(const error_code&, string);
4793e519524SHoward Hinnant};
4803e519524SHoward Hinnant
481d51f2a2aSAditya Kumar_LIBCPP_NORETURN _LIBCPP_FUNC_VIS
482d51f2a2aSAditya Kumarvoid __throw_system_error(int ev, const char* what_arg);
4833e519524SHoward Hinnant
4843e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD
4853e519524SHoward Hinnant
4863e519524SHoward Hinnant#endif // _LIBCPP_SYSTEM_ERROR
487