xref: /freebsd/contrib/llvm-project/libcxx/include/system_error (revision 04eeddc0aa8e0a417a16eaf9d7d095207f4a8623)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_SYSTEM_ERROR
110b57cec5SDimitry Andric#define _LIBCPP_SYSTEM_ERROR
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric    system_error synopsis
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricnamespace std
170b57cec5SDimitry Andric{
180b57cec5SDimitry Andric
190b57cec5SDimitry Andricclass error_category
200b57cec5SDimitry Andric{
210b57cec5SDimitry Andricpublic:
220b57cec5SDimitry Andric    virtual ~error_category() noexcept;
230b57cec5SDimitry Andric
240b57cec5SDimitry Andric    constexpr error_category();
250b57cec5SDimitry Andric    error_category(const error_category&) = delete;
260b57cec5SDimitry Andric    error_category& operator=(const error_category&) = delete;
270b57cec5SDimitry Andric
280b57cec5SDimitry Andric    virtual const char* name() const noexcept = 0;
290b57cec5SDimitry Andric    virtual error_condition default_error_condition(int ev) const noexcept;
300b57cec5SDimitry Andric    virtual bool equivalent(int code, const error_condition& condition) const noexcept;
310b57cec5SDimitry Andric    virtual bool equivalent(const error_code& code, int condition) const noexcept;
320b57cec5SDimitry Andric    virtual string message(int ev) const = 0;
330b57cec5SDimitry Andric
340b57cec5SDimitry Andric    bool operator==(const error_category& rhs) const noexcept;
350b57cec5SDimitry Andric    bool operator!=(const error_category& rhs) const noexcept;
360b57cec5SDimitry Andric    bool operator<(const error_category& rhs) const noexcept;
370b57cec5SDimitry Andric};
380b57cec5SDimitry Andric
390b57cec5SDimitry Andricconst error_category& generic_category() noexcept;
400b57cec5SDimitry Andricconst error_category& system_category() noexcept;
410b57cec5SDimitry Andric
420b57cec5SDimitry Andrictemplate <class T> struct is_error_code_enum
430b57cec5SDimitry Andric    : public false_type {};
440b57cec5SDimitry Andric
450b57cec5SDimitry Andrictemplate <class T> struct is_error_condition_enum
460b57cec5SDimitry Andric    : public false_type {};
470b57cec5SDimitry Andric
480b57cec5SDimitry Andrictemplate <class _Tp>
49349cc55cSDimitry Andricinline constexpr bool is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17
500b57cec5SDimitry Andric
510b57cec5SDimitry Andrictemplate <class _Tp>
52349cc55cSDimitry Andricinline constexpr bool is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17
530b57cec5SDimitry Andric
540b57cec5SDimitry Andricclass error_code
550b57cec5SDimitry Andric{
560b57cec5SDimitry Andricpublic:
570b57cec5SDimitry Andric    // constructors:
580b57cec5SDimitry Andric    error_code() noexcept;
590b57cec5SDimitry Andric    error_code(int val, const error_category& cat) noexcept;
600b57cec5SDimitry Andric    template <class ErrorCodeEnum>
610b57cec5SDimitry Andric        error_code(ErrorCodeEnum e) noexcept;
620b57cec5SDimitry Andric
630b57cec5SDimitry Andric    // modifiers:
640b57cec5SDimitry Andric    void assign(int val, const error_category& cat) noexcept;
650b57cec5SDimitry Andric    template <class ErrorCodeEnum>
660b57cec5SDimitry Andric        error_code& operator=(ErrorCodeEnum e) noexcept;
670b57cec5SDimitry Andric    void clear() noexcept;
680b57cec5SDimitry Andric
690b57cec5SDimitry Andric    // observers:
700b57cec5SDimitry Andric    int value() const noexcept;
710b57cec5SDimitry Andric    const error_category& category() const noexcept;
720b57cec5SDimitry Andric    error_condition default_error_condition() const noexcept;
730b57cec5SDimitry Andric    string message() const;
740b57cec5SDimitry Andric    explicit operator bool() const noexcept;
750b57cec5SDimitry Andric};
760b57cec5SDimitry Andric
770b57cec5SDimitry Andric// non-member functions:
780b57cec5SDimitry Andricbool operator<(const error_code& lhs, const error_code& rhs) noexcept;
790b57cec5SDimitry Andrictemplate <class charT, class traits>
800b57cec5SDimitry Andric    basic_ostream<charT,traits>&
810b57cec5SDimitry Andric    operator<<(basic_ostream<charT,traits>& os, const error_code& ec);
820b57cec5SDimitry Andric
830b57cec5SDimitry Andricclass error_condition
840b57cec5SDimitry Andric{
850b57cec5SDimitry Andricpublic:
860b57cec5SDimitry Andric    // constructors:
870b57cec5SDimitry Andric    error_condition() noexcept;
880b57cec5SDimitry Andric    error_condition(int val, const error_category& cat) noexcept;
890b57cec5SDimitry Andric    template <class ErrorConditionEnum>
900b57cec5SDimitry Andric        error_condition(ErrorConditionEnum e) noexcept;
910b57cec5SDimitry Andric
920b57cec5SDimitry Andric    // modifiers:
930b57cec5SDimitry Andric    void assign(int val, const error_category& cat) noexcept;
940b57cec5SDimitry Andric    template <class ErrorConditionEnum>
950b57cec5SDimitry Andric        error_condition& operator=(ErrorConditionEnum e) noexcept;
960b57cec5SDimitry Andric    void clear() noexcept;
970b57cec5SDimitry Andric
980b57cec5SDimitry Andric    // observers:
990b57cec5SDimitry Andric    int value() const noexcept;
1000b57cec5SDimitry Andric    const error_category& category() const noexcept;
1010b57cec5SDimitry Andric    string message() const noexcept;
1020b57cec5SDimitry Andric    explicit operator bool() const noexcept;
1030b57cec5SDimitry Andric};
1040b57cec5SDimitry Andric
1050b57cec5SDimitry Andricbool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
1060b57cec5SDimitry Andric
1070b57cec5SDimitry Andricclass system_error
1080b57cec5SDimitry Andric    : public runtime_error
1090b57cec5SDimitry Andric{
1100b57cec5SDimitry Andricpublic:
1110b57cec5SDimitry Andric    system_error(error_code ec, const string& what_arg);
1120b57cec5SDimitry Andric    system_error(error_code ec, const char* what_arg);
1130b57cec5SDimitry Andric    system_error(error_code ec);
1140b57cec5SDimitry Andric    system_error(int ev, const error_category& ecat, const string& what_arg);
1150b57cec5SDimitry Andric    system_error(int ev, const error_category& ecat, const char* what_arg);
1160b57cec5SDimitry Andric    system_error(int ev, const error_category& ecat);
1170b57cec5SDimitry Andric
1180b57cec5SDimitry Andric    const error_code& code() const noexcept;
1190b57cec5SDimitry Andric    const char* what() const noexcept;
1200b57cec5SDimitry Andric};
1210b57cec5SDimitry Andric
1220b57cec5SDimitry Andrictemplate <> struct is_error_condition_enum<errc>
1230b57cec5SDimitry Andric    : true_type { }
1240b57cec5SDimitry Andric
1250b57cec5SDimitry Andricerror_code make_error_code(errc e) noexcept;
1260b57cec5SDimitry Andricerror_condition make_error_condition(errc e) noexcept;
1270b57cec5SDimitry Andric
1280b57cec5SDimitry Andric// Comparison operators:
1290b57cec5SDimitry Andricbool operator==(const error_code& lhs, const error_code& rhs) noexcept;
1300b57cec5SDimitry Andricbool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
1310b57cec5SDimitry Andricbool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
1320b57cec5SDimitry Andricbool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
1330b57cec5SDimitry Andricbool operator!=(const error_code& lhs, const error_code& rhs) noexcept;
1340b57cec5SDimitry Andricbool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
1350b57cec5SDimitry Andricbool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
1360b57cec5SDimitry Andricbool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
1370b57cec5SDimitry Andric
1380b57cec5SDimitry Andrictemplate <> struct hash<std::error_code>;
1390b57cec5SDimitry Andrictemplate <> struct hash<std::error_condition>;
1400b57cec5SDimitry Andric
1410b57cec5SDimitry Andric}  // std
1420b57cec5SDimitry Andric
1430b57cec5SDimitry Andric*/
1440b57cec5SDimitry Andric
145fe6060f1SDimitry Andric#include <__config>
1460b57cec5SDimitry Andric#include <__errc>
147fe6060f1SDimitry Andric#include <__functional/unary_function.h>
1480b57cec5SDimitry Andric#include <__functional_base>
149fe6060f1SDimitry Andric#include <compare>
150fe6060f1SDimitry Andric#include <stdexcept>
1510b57cec5SDimitry Andric#include <string>
152fe6060f1SDimitry Andric#include <type_traits>
153*04eeddc0SDimitry Andric#include <version>
1540b57cec5SDimitry Andric
1550b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1560b57cec5SDimitry Andric#pragma GCC system_header
1570b57cec5SDimitry Andric#endif
1580b57cec5SDimitry Andric
1590b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
1600b57cec5SDimitry Andric
1610b57cec5SDimitry Andric// is_error_code_enum
1620b57cec5SDimitry Andric
1630b57cec5SDimitry Andrictemplate <class _Tp>
1640b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS is_error_code_enum
1650b57cec5SDimitry Andric    : public false_type {};
1660b57cec5SDimitry Andric
1670b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
1680b57cec5SDimitry Andrictemplate <class _Tp>
169349cc55cSDimitry Andricinline constexpr bool is_error_code_enum_v = is_error_code_enum<_Tp>::value;
1700b57cec5SDimitry Andric#endif
1710b57cec5SDimitry Andric
1720b57cec5SDimitry Andric// is_error_condition_enum
1730b57cec5SDimitry Andric
1740b57cec5SDimitry Andrictemplate <class _Tp>
1750b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum
1760b57cec5SDimitry Andric    : public false_type {};
1770b57cec5SDimitry Andric
1780b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
1790b57cec5SDimitry Andrictemplate <class _Tp>
180349cc55cSDimitry Andricinline constexpr bool is_error_condition_enum_v = is_error_condition_enum<_Tp>::value;
1810b57cec5SDimitry Andric#endif
1820b57cec5SDimitry Andric
1830b57cec5SDimitry Andrictemplate <>
1840b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc>
1850b57cec5SDimitry Andric    : true_type { };
1860b57cec5SDimitry Andric
1870b57cec5SDimitry Andric#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
1880b57cec5SDimitry Andrictemplate <>
1890b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc::__lx>
1900b57cec5SDimitry Andric    : true_type { };
1910b57cec5SDimitry Andric#endif
1920b57cec5SDimitry Andric
1930b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS error_condition;
1940b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS error_code;
1950b57cec5SDimitry Andric
1960b57cec5SDimitry Andric// class error_category
1970b57cec5SDimitry Andric
1980b57cec5SDimitry Andricclass _LIBCPP_HIDDEN __do_message;
1990b57cec5SDimitry Andric
2000b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS error_category
2010b57cec5SDimitry Andric{
2020b57cec5SDimitry Andricpublic:
2030b57cec5SDimitry Andric    virtual ~error_category() _NOEXCEPT;
2040b57cec5SDimitry Andric
2050b57cec5SDimitry Andric#if defined(_LIBCPP_BUILDING_LIBRARY) && \
2060b57cec5SDimitry Andric    defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
2070b57cec5SDimitry Andric    error_category() _NOEXCEPT;
2080b57cec5SDimitry Andric#else
2090b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2100eae32dcSDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT = default;
2110b57cec5SDimitry Andric#endif
2120eae32dcSDimitry Andric    error_category(const error_category&) = delete;
2130eae32dcSDimitry Andric    error_category& operator=(const error_category&) = delete;
2140b57cec5SDimitry Andric
2150b57cec5SDimitry Andric    virtual const char* name() const _NOEXCEPT = 0;
2160b57cec5SDimitry Andric    virtual error_condition default_error_condition(int __ev) const _NOEXCEPT;
2170b57cec5SDimitry Andric    virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT;
2180b57cec5SDimitry Andric    virtual bool equivalent(const error_code& __code, int __condition) const _NOEXCEPT;
2190b57cec5SDimitry Andric    virtual string message(int __ev) const = 0;
2200b57cec5SDimitry Andric
2210b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2220b57cec5SDimitry Andric    bool operator==(const error_category& __rhs) const _NOEXCEPT {return this == &__rhs;}
2230b57cec5SDimitry Andric
2240b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2250b57cec5SDimitry Andric    bool operator!=(const error_category& __rhs) const _NOEXCEPT {return !(*this == __rhs);}
2260b57cec5SDimitry Andric
2270b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2280b57cec5SDimitry Andric    bool operator< (const error_category& __rhs) const _NOEXCEPT {return this < &__rhs;}
2290b57cec5SDimitry Andric
2300b57cec5SDimitry Andric    friend class _LIBCPP_HIDDEN __do_message;
2310b57cec5SDimitry Andric};
2320b57cec5SDimitry Andric
2330b57cec5SDimitry Andricclass _LIBCPP_HIDDEN __do_message
2340b57cec5SDimitry Andric    : public error_category
2350b57cec5SDimitry Andric{
2360b57cec5SDimitry Andricpublic:
2370b57cec5SDimitry Andric    virtual string message(int ev) const;
2380b57cec5SDimitry Andric};
2390b57cec5SDimitry Andric
2400b57cec5SDimitry Andric_LIBCPP_FUNC_VIS const error_category& generic_category() _NOEXCEPT;
2410b57cec5SDimitry Andric_LIBCPP_FUNC_VIS const error_category& system_category() _NOEXCEPT;
2420b57cec5SDimitry Andric
2430b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS error_condition
2440b57cec5SDimitry Andric{
2450b57cec5SDimitry Andric    int __val_;
2460b57cec5SDimitry Andric    const error_category* __cat_;
2470b57cec5SDimitry Andricpublic:
2480b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2490b57cec5SDimitry Andric    error_condition() _NOEXCEPT : __val_(0), __cat_(&generic_category()) {}
2500b57cec5SDimitry Andric
2510b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2520b57cec5SDimitry Andric    error_condition(int __val, const error_category& __cat) _NOEXCEPT
2530b57cec5SDimitry Andric        : __val_(__val), __cat_(&__cat) {}
2540b57cec5SDimitry Andric
2550b57cec5SDimitry Andric    template <class _Ep>
2560b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
2570b57cec5SDimitry Andric        error_condition(_Ep __e,
258e8d8bef9SDimitry Andric              typename enable_if<is_error_condition_enum<_Ep>::value>::type* = nullptr
2590b57cec5SDimitry Andric                                                                     ) _NOEXCEPT
2600b57cec5SDimitry Andric            {*this = make_error_condition(__e);}
2610b57cec5SDimitry Andric
2620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2630b57cec5SDimitry Andric    void assign(int __val, const error_category& __cat) _NOEXCEPT
2640b57cec5SDimitry Andric    {
2650b57cec5SDimitry Andric        __val_ = __val;
2660b57cec5SDimitry Andric        __cat_ = &__cat;
2670b57cec5SDimitry Andric    }
2680b57cec5SDimitry Andric
2690b57cec5SDimitry Andric    template <class _Ep>
2700b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
2710b57cec5SDimitry Andric        typename enable_if
2720b57cec5SDimitry Andric        <
2730b57cec5SDimitry Andric            is_error_condition_enum<_Ep>::value,
2740b57cec5SDimitry Andric            error_condition&
2750b57cec5SDimitry Andric        >::type
2760b57cec5SDimitry Andric        operator=(_Ep __e) _NOEXCEPT
2770b57cec5SDimitry Andric            {*this = make_error_condition(__e); return *this;}
2780b57cec5SDimitry Andric
2790b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2800b57cec5SDimitry Andric    void clear() _NOEXCEPT
2810b57cec5SDimitry Andric    {
2820b57cec5SDimitry Andric        __val_ = 0;
2830b57cec5SDimitry Andric        __cat_ = &generic_category();
2840b57cec5SDimitry Andric    }
2850b57cec5SDimitry Andric
2860b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2870b57cec5SDimitry Andric    int value() const _NOEXCEPT {return __val_;}
2880b57cec5SDimitry Andric
2890b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2900b57cec5SDimitry Andric    const error_category& category() const _NOEXCEPT {return *__cat_;}
2910b57cec5SDimitry Andric    string message() const;
2920b57cec5SDimitry Andric
2930b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
294fe6060f1SDimitry Andric    explicit operator bool() const _NOEXCEPT {return __val_ != 0;}
2950b57cec5SDimitry Andric};
2960b57cec5SDimitry Andric
2970b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
2980b57cec5SDimitry Andricerror_condition
2990b57cec5SDimitry Andricmake_error_condition(errc __e) _NOEXCEPT
3000b57cec5SDimitry Andric{
3010b57cec5SDimitry Andric    return error_condition(static_cast<int>(__e), generic_category());
3020b57cec5SDimitry Andric}
3030b57cec5SDimitry Andric
3040b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
3050b57cec5SDimitry Andricbool
3060b57cec5SDimitry Andricoperator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT
3070b57cec5SDimitry Andric{
3080b57cec5SDimitry Andric    return __x.category() < __y.category()
3090b57cec5SDimitry Andric        || (__x.category() == __y.category() && __x.value() < __y.value());
3100b57cec5SDimitry Andric}
3110b57cec5SDimitry Andric
3120b57cec5SDimitry Andric// error_code
3130b57cec5SDimitry Andric
3140b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS error_code
3150b57cec5SDimitry Andric{
3160b57cec5SDimitry Andric    int __val_;
3170b57cec5SDimitry Andric    const error_category* __cat_;
3180b57cec5SDimitry Andricpublic:
3190b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3200b57cec5SDimitry Andric    error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {}
3210b57cec5SDimitry Andric
3220b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3230b57cec5SDimitry Andric    error_code(int __val, const error_category& __cat) _NOEXCEPT
3240b57cec5SDimitry Andric        : __val_(__val), __cat_(&__cat) {}
3250b57cec5SDimitry Andric
3260b57cec5SDimitry Andric    template <class _Ep>
3270b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
3280b57cec5SDimitry Andric        error_code(_Ep __e,
329e8d8bef9SDimitry Andric                   typename enable_if<is_error_code_enum<_Ep>::value>::type* = nullptr
3300b57cec5SDimitry Andric                                                                     ) _NOEXCEPT
3310b57cec5SDimitry Andric            {*this = make_error_code(__e);}
3320b57cec5SDimitry Andric
3330b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3340b57cec5SDimitry Andric    void assign(int __val, const error_category& __cat) _NOEXCEPT
3350b57cec5SDimitry Andric    {
3360b57cec5SDimitry Andric        __val_ = __val;
3370b57cec5SDimitry Andric        __cat_ = &__cat;
3380b57cec5SDimitry Andric    }
3390b57cec5SDimitry Andric
3400b57cec5SDimitry Andric    template <class _Ep>
3410b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
3420b57cec5SDimitry Andric        typename enable_if
3430b57cec5SDimitry Andric        <
3440b57cec5SDimitry Andric            is_error_code_enum<_Ep>::value,
3450b57cec5SDimitry Andric            error_code&
3460b57cec5SDimitry Andric        >::type
3470b57cec5SDimitry Andric        operator=(_Ep __e) _NOEXCEPT
3480b57cec5SDimitry Andric            {*this = make_error_code(__e); return *this;}
3490b57cec5SDimitry Andric
3500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3510b57cec5SDimitry Andric    void clear() _NOEXCEPT
3520b57cec5SDimitry Andric    {
3530b57cec5SDimitry Andric        __val_ = 0;
3540b57cec5SDimitry Andric        __cat_ = &system_category();
3550b57cec5SDimitry Andric    }
3560b57cec5SDimitry Andric
3570b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3580b57cec5SDimitry Andric    int value() const _NOEXCEPT {return __val_;}
3590b57cec5SDimitry Andric
3600b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3610b57cec5SDimitry Andric    const error_category& category() const _NOEXCEPT {return *__cat_;}
3620b57cec5SDimitry Andric
3630b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3640b57cec5SDimitry Andric    error_condition default_error_condition() const _NOEXCEPT
3650b57cec5SDimitry Andric        {return __cat_->default_error_condition(__val_);}
3660b57cec5SDimitry Andric
3670b57cec5SDimitry Andric    string message() const;
3680b57cec5SDimitry Andric
3690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
370fe6060f1SDimitry Andric    explicit operator bool() const _NOEXCEPT {return __val_ != 0;}
3710b57cec5SDimitry Andric};
3720b57cec5SDimitry Andric
3730b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
3740b57cec5SDimitry Andricerror_code
3750b57cec5SDimitry Andricmake_error_code(errc __e) _NOEXCEPT
3760b57cec5SDimitry Andric{
3770b57cec5SDimitry Andric    return error_code(static_cast<int>(__e), generic_category());
3780b57cec5SDimitry Andric}
3790b57cec5SDimitry Andric
3800b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
3810b57cec5SDimitry Andricbool
3820b57cec5SDimitry Andricoperator<(const error_code& __x, const error_code& __y) _NOEXCEPT
3830b57cec5SDimitry Andric{
3840b57cec5SDimitry Andric    return __x.category() < __y.category()
3850b57cec5SDimitry Andric        || (__x.category() == __y.category() && __x.value() < __y.value());
3860b57cec5SDimitry Andric}
3870b57cec5SDimitry Andric
3880b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
3890b57cec5SDimitry Andricbool
3900b57cec5SDimitry Andricoperator==(const error_code& __x, const error_code& __y) _NOEXCEPT
3910b57cec5SDimitry Andric{
3920b57cec5SDimitry Andric    return __x.category() == __y.category() && __x.value() == __y.value();
3930b57cec5SDimitry Andric}
3940b57cec5SDimitry Andric
3950b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
3960b57cec5SDimitry Andricbool
3970b57cec5SDimitry Andricoperator==(const error_code& __x, const error_condition& __y) _NOEXCEPT
3980b57cec5SDimitry Andric{
3990b57cec5SDimitry Andric    return __x.category().equivalent(__x.value(), __y)
4000b57cec5SDimitry Andric        || __y.category().equivalent(__x, __y.value());
4010b57cec5SDimitry Andric}
4020b57cec5SDimitry Andric
4030b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4040b57cec5SDimitry Andricbool
4050b57cec5SDimitry Andricoperator==(const error_condition& __x, const error_code& __y) _NOEXCEPT
4060b57cec5SDimitry Andric{
4070b57cec5SDimitry Andric    return __y == __x;
4080b57cec5SDimitry Andric}
4090b57cec5SDimitry Andric
4100b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4110b57cec5SDimitry Andricbool
4120b57cec5SDimitry Andricoperator==(const error_condition& __x, const error_condition& __y) _NOEXCEPT
4130b57cec5SDimitry Andric{
4140b57cec5SDimitry Andric    return __x.category() == __y.category() && __x.value() == __y.value();
4150b57cec5SDimitry Andric}
4160b57cec5SDimitry Andric
4170b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4180b57cec5SDimitry Andricbool
4190b57cec5SDimitry Andricoperator!=(const error_code& __x, const error_code& __y) _NOEXCEPT
4200b57cec5SDimitry Andric{return !(__x == __y);}
4210b57cec5SDimitry Andric
4220b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4230b57cec5SDimitry Andricbool
4240b57cec5SDimitry Andricoperator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT
4250b57cec5SDimitry Andric{return !(__x == __y);}
4260b57cec5SDimitry Andric
4270b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4280b57cec5SDimitry Andricbool
4290b57cec5SDimitry Andricoperator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT
4300b57cec5SDimitry Andric{return !(__x == __y);}
4310b57cec5SDimitry Andric
4320b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4330b57cec5SDimitry Andricbool
4340b57cec5SDimitry Andricoperator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT
4350b57cec5SDimitry Andric{return !(__x == __y);}
4360b57cec5SDimitry Andric
4370b57cec5SDimitry Andrictemplate <>
4380b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<error_code>
4390b57cec5SDimitry Andric    : public unary_function<error_code, size_t>
4400b57cec5SDimitry Andric{
4410b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4420b57cec5SDimitry Andric    size_t operator()(const error_code& __ec) const _NOEXCEPT
4430b57cec5SDimitry Andric    {
4440b57cec5SDimitry Andric        return static_cast<size_t>(__ec.value());
4450b57cec5SDimitry Andric    }
4460b57cec5SDimitry Andric};
4470b57cec5SDimitry Andric
4480b57cec5SDimitry Andrictemplate <>
4490b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<error_condition>
4500b57cec5SDimitry Andric    : public unary_function<error_condition, size_t>
4510b57cec5SDimitry Andric{
4520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4530b57cec5SDimitry Andric    size_t operator()(const error_condition& __ec) const _NOEXCEPT
4540b57cec5SDimitry Andric    {
4550b57cec5SDimitry Andric        return static_cast<size_t>(__ec.value());
4560b57cec5SDimitry Andric    }
4570b57cec5SDimitry Andric};
4580b57cec5SDimitry Andric
4590b57cec5SDimitry Andric// system_error
4600b57cec5SDimitry Andric
4610b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS system_error
4620b57cec5SDimitry Andric    : public runtime_error
4630b57cec5SDimitry Andric{
4640b57cec5SDimitry Andric    error_code __ec_;
4650b57cec5SDimitry Andricpublic:
4660b57cec5SDimitry Andric    system_error(error_code __ec, const string& __what_arg);
4670b57cec5SDimitry Andric    system_error(error_code __ec, const char* __what_arg);
4680b57cec5SDimitry Andric    system_error(error_code __ec);
4690b57cec5SDimitry Andric    system_error(int __ev, const error_category& __ecat, const string& __what_arg);
4700b57cec5SDimitry Andric    system_error(int __ev, const error_category& __ecat, const char* __what_arg);
4710b57cec5SDimitry Andric    system_error(int __ev, const error_category& __ecat);
4729ec406dcSDimitry Andric    system_error(const system_error&) _NOEXCEPT = default;
4730b57cec5SDimitry Andric    ~system_error() _NOEXCEPT;
4740b57cec5SDimitry Andric
4750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4760b57cec5SDimitry Andric    const error_code& code() const _NOEXCEPT {return __ec_;}
4770b57cec5SDimitry Andric
4780b57cec5SDimitry Andricprivate:
4790b57cec5SDimitry Andric    static string __init(const error_code&, string);
4800b57cec5SDimitry Andric};
4810b57cec5SDimitry Andric
4820b57cec5SDimitry Andric_LIBCPP_NORETURN _LIBCPP_FUNC_VIS
4830b57cec5SDimitry Andricvoid __throw_system_error(int ev, const char* what_arg);
4840b57cec5SDimitry Andric
4850b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
4860b57cec5SDimitry Andric
4870b57cec5SDimitry Andric#endif // _LIBCPP_SYSTEM_ERROR
488