17a984708SDavid Chisnall// -*- C++ -*-
27a984708SDavid Chisnall//===---------------------------- system_error ----------------------------===//
37a984708SDavid Chisnall//
47a984708SDavid Chisnall//                     The LLVM Compiler Infrastructure
57a984708SDavid Chisnall//
67a984708SDavid Chisnall// This file is dual licensed under the MIT and the University of Illinois Open
77a984708SDavid Chisnall// Source Licenses. See LICENSE.TXT for details.
87a984708SDavid Chisnall//
97a984708SDavid Chisnall//===----------------------------------------------------------------------===//
107a984708SDavid Chisnall
117a984708SDavid Chisnall#ifndef _LIBCPP_SYSTEM_ERROR
127a984708SDavid Chisnall#define _LIBCPP_SYSTEM_ERROR
137a984708SDavid Chisnall
147a984708SDavid Chisnall/*
157a984708SDavid Chisnall    system_error synopsis
167a984708SDavid Chisnall
177a984708SDavid Chisnallnamespace std
187a984708SDavid Chisnall{
197a984708SDavid Chisnall
207a984708SDavid Chisnallclass error_category
217a984708SDavid Chisnall{
227a984708SDavid Chisnallpublic:
237a984708SDavid Chisnall    virtual ~error_category() noexcept;
247a984708SDavid Chisnall
254f7ab58eSDimitry Andric    constexpr error_category();
267a984708SDavid Chisnall    error_category(const error_category&) = delete;
277a984708SDavid Chisnall    error_category& operator=(const error_category&) = delete;
287a984708SDavid Chisnall
297a984708SDavid Chisnall    virtual const char* name() const noexcept = 0;
307a984708SDavid Chisnall    virtual error_condition default_error_condition(int ev) const noexcept;
317a984708SDavid Chisnall    virtual bool equivalent(int code, const error_condition& condition) const noexcept;
327a984708SDavid Chisnall    virtual bool equivalent(const error_code& code, int condition) const noexcept;
337a984708SDavid Chisnall    virtual string message(int ev) const = 0;
347a984708SDavid Chisnall
357a984708SDavid Chisnall    bool operator==(const error_category& rhs) const noexcept;
367a984708SDavid Chisnall    bool operator!=(const error_category& rhs) const noexcept;
377a984708SDavid Chisnall    bool operator<(const error_category& rhs) const noexcept;
387a984708SDavid Chisnall};
397a984708SDavid Chisnall
407a984708SDavid Chisnallconst error_category& generic_category() noexcept;
417a984708SDavid Chisnallconst error_category& system_category() noexcept;
427a984708SDavid Chisnall
437a984708SDavid Chisnalltemplate <class T> struct is_error_code_enum
447a984708SDavid Chisnall    : public false_type {};
457a984708SDavid Chisnall
467a984708SDavid Chisnalltemplate <class T> struct is_error_condition_enum
477a984708SDavid Chisnall    : public false_type {};
487a984708SDavid Chisnall
49aed8d94eSDimitry Andrictemplate <class _Tp>
5030785c0eSDimitry Andricinline constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17
51aed8d94eSDimitry Andric
52aed8d94eSDimitry Andrictemplate <class _Tp>
5330785c0eSDimitry Andricinline constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17
54aed8d94eSDimitry Andric
557a984708SDavid Chisnallclass error_code
567a984708SDavid Chisnall{
577a984708SDavid Chisnallpublic:
587a984708SDavid Chisnall    // constructors:
597a984708SDavid Chisnall    error_code() noexcept;
607a984708SDavid Chisnall    error_code(int val, const error_category& cat) noexcept;
617a984708SDavid Chisnall    template <class ErrorCodeEnum>
627a984708SDavid Chisnall        error_code(ErrorCodeEnum e) noexcept;
637a984708SDavid Chisnall
647a984708SDavid Chisnall    // modifiers:
657a984708SDavid Chisnall    void assign(int val, const error_category& cat) noexcept;
667a984708SDavid Chisnall    template <class ErrorCodeEnum>
677a984708SDavid Chisnall        error_code& operator=(ErrorCodeEnum e) noexcept;
687a984708SDavid Chisnall    void clear() noexcept;
697a984708SDavid Chisnall
707a984708SDavid Chisnall    // observers:
717a984708SDavid Chisnall    int value() const noexcept;
727a984708SDavid Chisnall    const error_category& category() const noexcept;
737a984708SDavid Chisnall    error_condition default_error_condition() const noexcept;
747a984708SDavid Chisnall    string message() const;
757a984708SDavid Chisnall    explicit operator bool() const noexcept;
767a984708SDavid Chisnall};
777a984708SDavid Chisnall
787a984708SDavid Chisnall// non-member functions:
797a984708SDavid Chisnallbool operator<(const error_code& lhs, const error_code& rhs) noexcept;
807a984708SDavid Chisnalltemplate <class charT, class traits>
817a984708SDavid Chisnall    basic_ostream<charT,traits>&
827a984708SDavid Chisnall    operator<<(basic_ostream<charT,traits>& os, const error_code& ec);
837a984708SDavid Chisnall
847a984708SDavid Chisnallclass error_condition
857a984708SDavid Chisnall{
867a984708SDavid Chisnallpublic:
877a984708SDavid Chisnall    // constructors:
887a984708SDavid Chisnall    error_condition() noexcept;
897a984708SDavid Chisnall    error_condition(int val, const error_category& cat) noexcept;
907a984708SDavid Chisnall    template <class ErrorConditionEnum>
917a984708SDavid Chisnall        error_condition(ErrorConditionEnum e) noexcept;
927a984708SDavid Chisnall
937a984708SDavid Chisnall    // modifiers:
947a984708SDavid Chisnall    void assign(int val, const error_category& cat) noexcept;
957a984708SDavid Chisnall    template <class ErrorConditionEnum>
967a984708SDavid Chisnall        error_condition& operator=(ErrorConditionEnum e) noexcept;
977a984708SDavid Chisnall    void clear() noexcept;
987a984708SDavid Chisnall
997a984708SDavid Chisnall    // observers:
1007a984708SDavid Chisnall    int value() const noexcept;
1017a984708SDavid Chisnall    const error_category& category() const noexcept;
1027a984708SDavid Chisnall    string message() const noexcept;
1037a984708SDavid Chisnall    explicit operator bool() const noexcept;
1047a984708SDavid Chisnall};
1057a984708SDavid Chisnall
1067a984708SDavid Chisnallbool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
1077a984708SDavid Chisnall
1087a984708SDavid Chisnallclass system_error
1097a984708SDavid Chisnall    : public runtime_error
1107a984708SDavid Chisnall{
1117a984708SDavid Chisnallpublic:
1127a984708SDavid Chisnall    system_error(error_code ec, const string& what_arg);
1137a984708SDavid Chisnall    system_error(error_code ec, const char* what_arg);
1147a984708SDavid Chisnall    system_error(error_code ec);
1157a984708SDavid Chisnall    system_error(int ev, const error_category& ecat, const string& what_arg);
1167a984708SDavid Chisnall    system_error(int ev, const error_category& ecat, const char* what_arg);
1177a984708SDavid Chisnall    system_error(int ev, const error_category& ecat);
1187a984708SDavid Chisnall
1197a984708SDavid Chisnall    const error_code& code() const noexcept;
1207a984708SDavid Chisnall    const char* what() const noexcept;
1217a984708SDavid Chisnall};
1227a984708SDavid Chisnall
1237a984708SDavid Chisnalltemplate <> struct is_error_condition_enum<errc>
1247a984708SDavid Chisnall    : true_type { }
1257a984708SDavid Chisnall
1267a984708SDavid Chisnallerror_code make_error_code(errc e) noexcept;
1277a984708SDavid Chisnallerror_condition make_error_condition(errc e) noexcept;
1287a984708SDavid Chisnall
1297a984708SDavid Chisnall// Comparison operators:
1307a984708SDavid Chisnallbool operator==(const error_code& lhs, const error_code& rhs) noexcept;
1317a984708SDavid Chisnallbool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
1327a984708SDavid Chisnallbool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
1337a984708SDavid Chisnallbool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
1347a984708SDavid Chisnallbool operator!=(const error_code& lhs, const error_code& rhs) noexcept;
1357a984708SDavid Chisnallbool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
1367a984708SDavid Chisnallbool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
1377a984708SDavid Chisnallbool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
1387a984708SDavid Chisnall
1397a984708SDavid Chisnalltemplate <> struct hash<std::error_code>;
140aed8d94eSDimitry Andrictemplate <> struct hash<std::error_condition>;
1417a984708SDavid Chisnall
1427a984708SDavid Chisnall}  // std
1437a984708SDavid Chisnall
1447a984708SDavid Chisnall*/
1457a984708SDavid Chisnall
146*4ba319b5SDimitry Andric#include <__errc>
1477a984708SDavid Chisnall#include <type_traits>
1487a984708SDavid Chisnall#include <stdexcept>
1497a984708SDavid Chisnall#include <__functional_base>
150b2c7081bSDimitry Andric#include <string>
1517a984708SDavid Chisnall
1527a984708SDavid Chisnall#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1537a984708SDavid Chisnall#pragma GCC system_header
1547a984708SDavid Chisnall#endif
1557a984708SDavid Chisnall
1567a984708SDavid Chisnall_LIBCPP_BEGIN_NAMESPACE_STD
1577a984708SDavid Chisnall
1587a984708SDavid Chisnall// is_error_code_enum
1597a984708SDavid Chisnall
1607a984708SDavid Chisnalltemplate <class _Tp>
161aed8d94eSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS is_error_code_enum
1627a984708SDavid Chisnall    : public false_type {};
1637a984708SDavid Chisnall
164aed8d94eSDimitry Andric#if _LIBCPP_STD_VER > 14
165aed8d94eSDimitry Andrictemplate <class _Tp>
16630785c0eSDimitry Andric_LIBCPP_INLINE_VAR constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value;
167aed8d94eSDimitry Andric#endif
168aed8d94eSDimitry Andric
1697a984708SDavid Chisnall// is_error_condition_enum
1707a984708SDavid Chisnall
1717a984708SDavid Chisnalltemplate <class _Tp>
172aed8d94eSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum
1737a984708SDavid Chisnall    : public false_type {};
1747a984708SDavid Chisnall
175aed8d94eSDimitry Andric#if _LIBCPP_STD_VER > 14
176aed8d94eSDimitry Andrictemplate <class _Tp>
17730785c0eSDimitry Andric_LIBCPP_INLINE_VAR constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value;
178aed8d94eSDimitry Andric#endif
179aed8d94eSDimitry Andric
1807a984708SDavid Chisnalltemplate <>
181aed8d94eSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc>
1827a984708SDavid Chisnall    : true_type { };
1837a984708SDavid Chisnall
18494e3ee44SDavid Chisnall#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
1857a984708SDavid Chisnalltemplate <>
186aed8d94eSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc::__lx>
1877a984708SDavid Chisnall    : true_type { };
18894e3ee44SDavid Chisnall#endif
1897a984708SDavid Chisnall
1901bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS error_condition;
1911bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS error_code;
1927a984708SDavid Chisnall
1937a984708SDavid Chisnall// class error_category
1947a984708SDavid Chisnall
195936e9439SDimitry Andricclass _LIBCPP_HIDDEN __do_message;
1967a984708SDavid Chisnall
1971bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS error_category
1987a984708SDavid Chisnall{
1997a984708SDavid Chisnallpublic:
2007a984708SDavid Chisnall    virtual ~error_category() _NOEXCEPT;
2017a984708SDavid Chisnall
202*4ba319b5SDimitry Andric#if defined(_LIBCPP_BUILDING_LIBRARY) && \
203540d2a8bSDimitry Andric    defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
2047a984708SDavid Chisnall    error_category() _NOEXCEPT;
2054f7ab58eSDimitry Andric#else
206*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
207163c8ab6SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT _LIBCPP_DEFAULT
2084f7ab58eSDimitry Andric#endif
209b03f91a8SDavid Chisnallprivate:
2107a984708SDavid Chisnall    error_category(const error_category&);// = delete;
2117a984708SDavid Chisnall    error_category& operator=(const error_category&);// = delete;
2127a984708SDavid Chisnall
2137a984708SDavid Chisnallpublic:
2147a984708SDavid Chisnall    virtual const char* name() const _NOEXCEPT = 0;
2157a984708SDavid Chisnall    virtual error_condition default_error_condition(int __ev) const _NOEXCEPT;
2167a984708SDavid Chisnall    virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT;
2177a984708SDavid Chisnall    virtual bool equivalent(const error_code& __code, int __condition) const _NOEXCEPT;
2187a984708SDavid Chisnall    virtual string message(int __ev) const = 0;
2197a984708SDavid Chisnall
220*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2217a984708SDavid Chisnall    bool operator==(const error_category& __rhs) const _NOEXCEPT {return this == &__rhs;}
2227a984708SDavid Chisnall
223*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2247a984708SDavid Chisnall    bool operator!=(const error_category& __rhs) const _NOEXCEPT {return !(*this == __rhs);}
2257a984708SDavid Chisnall
226*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2277a984708SDavid Chisnall    bool operator< (const error_category& __rhs) const _NOEXCEPT {return this < &__rhs;}
2287a984708SDavid Chisnall
229936e9439SDimitry Andric    friend class _LIBCPP_HIDDEN __do_message;
2307a984708SDavid Chisnall};
2317a984708SDavid Chisnall
2327a984708SDavid Chisnallclass _LIBCPP_HIDDEN __do_message
2337a984708SDavid Chisnall    : public error_category
2347a984708SDavid Chisnall{
2357a984708SDavid Chisnallpublic:
2367a984708SDavid Chisnall    virtual string message(int ev) const;
2377a984708SDavid Chisnall};
2387a984708SDavid Chisnall
2394f7ab58eSDimitry Andric_LIBCPP_FUNC_VIS const error_category& generic_category() _NOEXCEPT;
2404f7ab58eSDimitry Andric_LIBCPP_FUNC_VIS const error_category& system_category() _NOEXCEPT;
2417a984708SDavid Chisnall
2421bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS error_condition
2437a984708SDavid Chisnall{
2447a984708SDavid Chisnall    int __val_;
2457a984708SDavid Chisnall    const error_category* __cat_;
2467a984708SDavid Chisnallpublic:
247*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2487a984708SDavid Chisnall    error_condition() _NOEXCEPT : __val_(0), __cat_(&generic_category()) {}
2497a984708SDavid Chisnall
250*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2517a984708SDavid Chisnall    error_condition(int __val, const error_category& __cat) _NOEXCEPT
2527a984708SDavid Chisnall        : __val_(__val), __cat_(&__cat) {}
2537a984708SDavid Chisnall
25494e3ee44SDavid Chisnall    template <class _Ep>
255*4ba319b5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
25694e3ee44SDavid Chisnall        error_condition(_Ep __e,
25794e3ee44SDavid Chisnall              typename enable_if<is_error_condition_enum<_Ep>::value>::type* = 0
2587a984708SDavid Chisnall                                                                     ) _NOEXCEPT
2597a984708SDavid Chisnall            {*this = make_error_condition(__e);}
2607a984708SDavid Chisnall
261*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2627a984708SDavid Chisnall    void assign(int __val, const error_category& __cat) _NOEXCEPT
2637a984708SDavid Chisnall    {
2647a984708SDavid Chisnall        __val_ = __val;
2657a984708SDavid Chisnall        __cat_ = &__cat;
2667a984708SDavid Chisnall    }
2677a984708SDavid Chisnall
26894e3ee44SDavid Chisnall    template <class _Ep>
269*4ba319b5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
2707a984708SDavid Chisnall        typename enable_if
2717a984708SDavid Chisnall        <
27294e3ee44SDavid Chisnall            is_error_condition_enum<_Ep>::value,
2737a984708SDavid Chisnall            error_condition&
2747a984708SDavid Chisnall        >::type
27594e3ee44SDavid Chisnall        operator=(_Ep __e) _NOEXCEPT
2767a984708SDavid Chisnall            {*this = make_error_condition(__e); return *this;}
2777a984708SDavid Chisnall
278*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2797a984708SDavid Chisnall    void clear() _NOEXCEPT
2807a984708SDavid Chisnall    {
2817a984708SDavid Chisnall        __val_ = 0;
2827a984708SDavid Chisnall        __cat_ = &generic_category();
2837a984708SDavid Chisnall    }
2847a984708SDavid Chisnall
285*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2867a984708SDavid Chisnall    int value() const _NOEXCEPT {return __val_;}
2877a984708SDavid Chisnall
288*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2897a984708SDavid Chisnall    const error_category& category() const _NOEXCEPT {return *__cat_;}
2907a984708SDavid Chisnall    string message() const;
2917a984708SDavid Chisnall
292*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
29394e3ee44SDavid Chisnall        _LIBCPP_EXPLICIT
2947a984708SDavid Chisnall        operator bool() const _NOEXCEPT {return __val_ != 0;}
2957a984708SDavid Chisnall};
2967a984708SDavid Chisnall
2977a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
2987a984708SDavid Chisnallerror_condition
2997a984708SDavid Chisnallmake_error_condition(errc __e) _NOEXCEPT
3007a984708SDavid Chisnall{
3017a984708SDavid Chisnall    return error_condition(static_cast<int>(__e), generic_category());
3027a984708SDavid Chisnall}
3037a984708SDavid Chisnall
3047a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
3057a984708SDavid Chisnallbool
3067a984708SDavid Chisnalloperator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT
3077a984708SDavid Chisnall{
3087a984708SDavid Chisnall    return __x.category() < __y.category()
30994e3ee44SDavid Chisnall        || (__x.category() == __y.category() && __x.value() < __y.value());
3107a984708SDavid Chisnall}
3117a984708SDavid Chisnall
3127a984708SDavid Chisnall// error_code
3137a984708SDavid Chisnall
3141bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS error_code
3157a984708SDavid Chisnall{
3167a984708SDavid Chisnall    int __val_;
3177a984708SDavid Chisnall    const error_category* __cat_;
3187a984708SDavid Chisnallpublic:
319*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3207a984708SDavid Chisnall    error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {}
3217a984708SDavid Chisnall
322*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3237a984708SDavid Chisnall    error_code(int __val, const error_category& __cat) _NOEXCEPT
3247a984708SDavid Chisnall        : __val_(__val), __cat_(&__cat) {}
3257a984708SDavid Chisnall
32694e3ee44SDavid Chisnall    template <class _Ep>
327*4ba319b5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
32894e3ee44SDavid Chisnall        error_code(_Ep __e,
32994e3ee44SDavid Chisnall                   typename enable_if<is_error_code_enum<_Ep>::value>::type* = 0
3307a984708SDavid Chisnall                                                                     ) _NOEXCEPT
3317a984708SDavid Chisnall            {*this = make_error_code(__e);}
3327a984708SDavid Chisnall
333*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3347a984708SDavid Chisnall    void assign(int __val, const error_category& __cat) _NOEXCEPT
3357a984708SDavid Chisnall    {
3367a984708SDavid Chisnall        __val_ = __val;
3377a984708SDavid Chisnall        __cat_ = &__cat;
3387a984708SDavid Chisnall    }
3397a984708SDavid Chisnall
34094e3ee44SDavid Chisnall    template <class _Ep>
341*4ba319b5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
3427a984708SDavid Chisnall        typename enable_if
3437a984708SDavid Chisnall        <
34494e3ee44SDavid Chisnall            is_error_code_enum<_Ep>::value,
3457a984708SDavid Chisnall            error_code&
3467a984708SDavid Chisnall        >::type
34794e3ee44SDavid Chisnall        operator=(_Ep __e) _NOEXCEPT
3487a984708SDavid Chisnall            {*this = make_error_code(__e); return *this;}
3497a984708SDavid Chisnall
350*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3517a984708SDavid Chisnall    void clear() _NOEXCEPT
3527a984708SDavid Chisnall    {
3537a984708SDavid Chisnall        __val_ = 0;
3547a984708SDavid Chisnall        __cat_ = &system_category();
3557a984708SDavid Chisnall    }
3567a984708SDavid Chisnall
357*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3587a984708SDavid Chisnall    int value() const _NOEXCEPT {return __val_;}
3597a984708SDavid Chisnall
360*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3617a984708SDavid Chisnall    const error_category& category() const _NOEXCEPT {return *__cat_;}
3627a984708SDavid Chisnall
363*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3647a984708SDavid Chisnall    error_condition default_error_condition() const _NOEXCEPT
3657a984708SDavid Chisnall        {return __cat_->default_error_condition(__val_);}
3667a984708SDavid Chisnall
3677a984708SDavid Chisnall    string message() const;
3687a984708SDavid Chisnall
369*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
37094e3ee44SDavid Chisnall        _LIBCPP_EXPLICIT
3717a984708SDavid Chisnall        operator bool() const _NOEXCEPT {return __val_ != 0;}
3727a984708SDavid Chisnall};
3737a984708SDavid Chisnall
3747a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
3757a984708SDavid Chisnallerror_code
3767a984708SDavid Chisnallmake_error_code(errc __e) _NOEXCEPT
3777a984708SDavid Chisnall{
3787a984708SDavid Chisnall    return error_code(static_cast<int>(__e), generic_category());
3797a984708SDavid Chisnall}
3807a984708SDavid Chisnall
3817a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
3827a984708SDavid Chisnallbool
3837a984708SDavid Chisnalloperator<(const error_code& __x, const error_code& __y) _NOEXCEPT
3847a984708SDavid Chisnall{
3857a984708SDavid Chisnall    return __x.category() < __y.category()
38694e3ee44SDavid Chisnall        || (__x.category() == __y.category() && __x.value() < __y.value());
3877a984708SDavid Chisnall}
3887a984708SDavid Chisnall
3897a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
3907a984708SDavid Chisnallbool
3917a984708SDavid Chisnalloperator==(const error_code& __x, const error_code& __y) _NOEXCEPT
3927a984708SDavid Chisnall{
3937a984708SDavid Chisnall    return __x.category() == __y.category() && __x.value() == __y.value();
3947a984708SDavid Chisnall}
3957a984708SDavid Chisnall
3967a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
3977a984708SDavid Chisnallbool
3987a984708SDavid Chisnalloperator==(const error_code& __x, const error_condition& __y) _NOEXCEPT
3997a984708SDavid Chisnall{
4007a984708SDavid Chisnall    return __x.category().equivalent(__x.value(), __y)
4017a984708SDavid Chisnall        || __y.category().equivalent(__x, __y.value());
4027a984708SDavid Chisnall}
4037a984708SDavid Chisnall
4047a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
4057a984708SDavid Chisnallbool
4067a984708SDavid Chisnalloperator==(const error_condition& __x, const error_code& __y) _NOEXCEPT
4077a984708SDavid Chisnall{
4087a984708SDavid Chisnall    return __y == __x;
4097a984708SDavid Chisnall}
4107a984708SDavid Chisnall
4117a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
4127a984708SDavid Chisnallbool
4137a984708SDavid Chisnalloperator==(const error_condition& __x, const error_condition& __y) _NOEXCEPT
4147a984708SDavid Chisnall{
4157a984708SDavid Chisnall    return __x.category() == __y.category() && __x.value() == __y.value();
4167a984708SDavid Chisnall}
4177a984708SDavid Chisnall
4187a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
4197a984708SDavid Chisnallbool
4207a984708SDavid Chisnalloperator!=(const error_code& __x, const error_code& __y) _NOEXCEPT
4217a984708SDavid Chisnall{return !(__x == __y);}
4227a984708SDavid Chisnall
4237a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
4247a984708SDavid Chisnallbool
4257a984708SDavid Chisnalloperator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT
4267a984708SDavid Chisnall{return !(__x == __y);}
4277a984708SDavid Chisnall
4287a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
4297a984708SDavid Chisnallbool
4307a984708SDavid Chisnalloperator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT
4317a984708SDavid Chisnall{return !(__x == __y);}
4327a984708SDavid Chisnall
4337a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
4347a984708SDavid Chisnallbool
4357a984708SDavid Chisnalloperator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT
4367a984708SDavid Chisnall{return !(__x == __y);}
4377a984708SDavid Chisnall
4387a984708SDavid Chisnalltemplate <>
439aed8d94eSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<error_code>
4407a984708SDavid Chisnall    : public unary_function<error_code, size_t>
4417a984708SDavid Chisnall{
4427a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4437a984708SDavid Chisnall    size_t operator()(const error_code& __ec) const _NOEXCEPT
4447a984708SDavid Chisnall    {
4457a984708SDavid Chisnall        return static_cast<size_t>(__ec.value());
4467a984708SDavid Chisnall    }
4477a984708SDavid Chisnall};
4487a984708SDavid Chisnall
449aed8d94eSDimitry Andrictemplate <>
450aed8d94eSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<error_condition>
451aed8d94eSDimitry Andric    : public unary_function<error_condition, size_t>
452aed8d94eSDimitry Andric{
453aed8d94eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
454aed8d94eSDimitry Andric    size_t operator()(const error_condition& __ec) const _NOEXCEPT
455aed8d94eSDimitry Andric    {
456aed8d94eSDimitry Andric        return static_cast<size_t>(__ec.value());
457aed8d94eSDimitry Andric    }
458aed8d94eSDimitry Andric};
459aed8d94eSDimitry Andric
4607a984708SDavid Chisnall// system_error
4617a984708SDavid Chisnall
4621bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS system_error
4637a984708SDavid Chisnall    : public runtime_error
4647a984708SDavid Chisnall{
4657a984708SDavid Chisnall    error_code __ec_;
4667a984708SDavid Chisnallpublic:
4677a984708SDavid Chisnall    system_error(error_code __ec, const string& __what_arg);
4687a984708SDavid Chisnall    system_error(error_code __ec, const char* __what_arg);
4697a984708SDavid Chisnall    system_error(error_code __ec);
4707a984708SDavid Chisnall    system_error(int __ev, const error_category& __ecat, const string& __what_arg);
4717a984708SDavid Chisnall    system_error(int __ev, const error_category& __ecat, const char* __what_arg);
4727a984708SDavid Chisnall    system_error(int __ev, const error_category& __ecat);
4737a984708SDavid Chisnall    ~system_error() _NOEXCEPT;
4747a984708SDavid Chisnall
475*4ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4767a984708SDavid Chisnall    const error_code& code() const _NOEXCEPT {return __ec_;}
4777a984708SDavid Chisnall
4787a984708SDavid Chisnallprivate:
4797a984708SDavid Chisnall    static string __init(const error_code&, string);
4807a984708SDavid Chisnall};
4817a984708SDavid Chisnall
482aed8d94eSDimitry Andric_LIBCPP_NORETURN _LIBCPP_FUNC_VIS
483aed8d94eSDimitry Andricvoid __throw_system_error(int ev, const char* what_arg);
4847a984708SDavid Chisnall
4857a984708SDavid Chisnall_LIBCPP_END_NAMESPACE_STD
4867a984708SDavid Chisnall
4877a984708SDavid Chisnall#endif  // _LIBCPP_SYSTEM_ERROR
488