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 145*81ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler 146fe6060f1SDimitry Andric#include <__config> 1470b57cec5SDimitry Andric#include <__errc> 148*81ad6265SDimitry Andric#include <__functional/hash.h> 149fe6060f1SDimitry Andric#include <__functional/unary_function.h> 150fe6060f1SDimitry Andric#include <stdexcept> 1510b57cec5SDimitry Andric#include <string> 152fe6060f1SDimitry Andric#include <type_traits> 15304eeddc0SDimitry Andric#include <version> 1540b57cec5SDimitry Andric 155*81ad6265SDimitry Andric// standard-mandated includes 156*81ad6265SDimitry Andric#include <compare> 157*81ad6265SDimitry Andric 1580b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1590b57cec5SDimitry Andric# pragma GCC system_header 1600b57cec5SDimitry Andric#endif 1610b57cec5SDimitry Andric 1620b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 1630b57cec5SDimitry Andric 1640b57cec5SDimitry Andric// is_error_code_enum 1650b57cec5SDimitry Andric 1660b57cec5SDimitry Andrictemplate <class _Tp> 1670b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS is_error_code_enum 1680b57cec5SDimitry Andric : public false_type {}; 1690b57cec5SDimitry Andric 1700b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 1710b57cec5SDimitry Andrictemplate <class _Tp> 172349cc55cSDimitry Andricinline constexpr bool is_error_code_enum_v = is_error_code_enum<_Tp>::value; 1730b57cec5SDimitry Andric#endif 1740b57cec5SDimitry Andric 1750b57cec5SDimitry Andric// is_error_condition_enum 1760b57cec5SDimitry Andric 1770b57cec5SDimitry Andrictemplate <class _Tp> 1780b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum 1790b57cec5SDimitry Andric : public false_type {}; 1800b57cec5SDimitry Andric 1810b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 1820b57cec5SDimitry Andrictemplate <class _Tp> 183349cc55cSDimitry Andricinline constexpr bool is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; 1840b57cec5SDimitry Andric#endif 1850b57cec5SDimitry Andric 1860b57cec5SDimitry Andrictemplate <> 1870b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc> 1880b57cec5SDimitry Andric : true_type { }; 1890b57cec5SDimitry Andric 190*81ad6265SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 1910b57cec5SDimitry Andrictemplate <> 1920b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc::__lx> 1930b57cec5SDimitry Andric : true_type { }; 1940b57cec5SDimitry Andric#endif 1950b57cec5SDimitry Andric 1960b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS error_condition; 1970b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS error_code; 1980b57cec5SDimitry Andric 1990b57cec5SDimitry Andric// class error_category 2000b57cec5SDimitry Andric 2010b57cec5SDimitry Andricclass _LIBCPP_HIDDEN __do_message; 2020b57cec5SDimitry Andric 2030b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS error_category 2040b57cec5SDimitry Andric{ 2050b57cec5SDimitry Andricpublic: 2060b57cec5SDimitry Andric virtual ~error_category() _NOEXCEPT; 2070b57cec5SDimitry Andric 208*81ad6265SDimitry Andric#if defined(_LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS) 209*81ad6265SDimitry Andric error_category() noexcept; 2100b57cec5SDimitry Andric#else 2110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2120eae32dcSDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT = default; 2130b57cec5SDimitry Andric#endif 2140eae32dcSDimitry Andric error_category(const error_category&) = delete; 2150eae32dcSDimitry Andric error_category& operator=(const error_category&) = delete; 2160b57cec5SDimitry Andric 2170b57cec5SDimitry Andric virtual const char* name() const _NOEXCEPT = 0; 2180b57cec5SDimitry Andric virtual error_condition default_error_condition(int __ev) const _NOEXCEPT; 2190b57cec5SDimitry Andric virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT; 2200b57cec5SDimitry Andric virtual bool equivalent(const error_code& __code, int __condition) const _NOEXCEPT; 2210b57cec5SDimitry Andric virtual string message(int __ev) const = 0; 2220b57cec5SDimitry Andric 2230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2240b57cec5SDimitry Andric bool operator==(const error_category& __rhs) const _NOEXCEPT {return this == &__rhs;} 2250b57cec5SDimitry Andric 2260b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2270b57cec5SDimitry Andric bool operator!=(const error_category& __rhs) const _NOEXCEPT {return !(*this == __rhs);} 2280b57cec5SDimitry Andric 2290b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2300b57cec5SDimitry Andric bool operator< (const error_category& __rhs) const _NOEXCEPT {return this < &__rhs;} 2310b57cec5SDimitry Andric 2320b57cec5SDimitry Andric friend class _LIBCPP_HIDDEN __do_message; 2330b57cec5SDimitry Andric}; 2340b57cec5SDimitry Andric 2350b57cec5SDimitry Andricclass _LIBCPP_HIDDEN __do_message 2360b57cec5SDimitry Andric : public error_category 2370b57cec5SDimitry Andric{ 2380b57cec5SDimitry Andricpublic: 2390b57cec5SDimitry Andric virtual string message(int ev) const; 2400b57cec5SDimitry Andric}; 2410b57cec5SDimitry Andric 2420b57cec5SDimitry Andric_LIBCPP_FUNC_VIS const error_category& generic_category() _NOEXCEPT; 2430b57cec5SDimitry Andric_LIBCPP_FUNC_VIS const error_category& system_category() _NOEXCEPT; 2440b57cec5SDimitry Andric 2450b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS error_condition 2460b57cec5SDimitry Andric{ 2470b57cec5SDimitry Andric int __val_; 2480b57cec5SDimitry Andric const error_category* __cat_; 2490b57cec5SDimitry Andricpublic: 2500b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2510b57cec5SDimitry Andric error_condition() _NOEXCEPT : __val_(0), __cat_(&generic_category()) {} 2520b57cec5SDimitry Andric 2530b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2540b57cec5SDimitry Andric error_condition(int __val, const error_category& __cat) _NOEXCEPT 2550b57cec5SDimitry Andric : __val_(__val), __cat_(&__cat) {} 2560b57cec5SDimitry Andric 2570b57cec5SDimitry Andric template <class _Ep> 2580b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2590b57cec5SDimitry Andric error_condition(_Ep __e, 260e8d8bef9SDimitry Andric typename enable_if<is_error_condition_enum<_Ep>::value>::type* = nullptr 2610b57cec5SDimitry Andric ) _NOEXCEPT 2620b57cec5SDimitry Andric {*this = make_error_condition(__e);} 2630b57cec5SDimitry Andric 2640b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2650b57cec5SDimitry Andric void assign(int __val, const error_category& __cat) _NOEXCEPT 2660b57cec5SDimitry Andric { 2670b57cec5SDimitry Andric __val_ = __val; 2680b57cec5SDimitry Andric __cat_ = &__cat; 2690b57cec5SDimitry Andric } 2700b57cec5SDimitry Andric 2710b57cec5SDimitry Andric template <class _Ep> 2720b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2730b57cec5SDimitry Andric typename enable_if 2740b57cec5SDimitry Andric < 2750b57cec5SDimitry Andric is_error_condition_enum<_Ep>::value, 2760b57cec5SDimitry Andric error_condition& 2770b57cec5SDimitry Andric >::type 2780b57cec5SDimitry Andric operator=(_Ep __e) _NOEXCEPT 2790b57cec5SDimitry Andric {*this = make_error_condition(__e); return *this;} 2800b57cec5SDimitry Andric 2810b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2820b57cec5SDimitry Andric void clear() _NOEXCEPT 2830b57cec5SDimitry Andric { 2840b57cec5SDimitry Andric __val_ = 0; 2850b57cec5SDimitry Andric __cat_ = &generic_category(); 2860b57cec5SDimitry Andric } 2870b57cec5SDimitry Andric 2880b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2890b57cec5SDimitry Andric int value() const _NOEXCEPT {return __val_;} 2900b57cec5SDimitry Andric 2910b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2920b57cec5SDimitry Andric const error_category& category() const _NOEXCEPT {return *__cat_;} 2930b57cec5SDimitry Andric string message() const; 2940b57cec5SDimitry Andric 2950b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 296fe6060f1SDimitry Andric explicit operator bool() const _NOEXCEPT {return __val_ != 0;} 2970b57cec5SDimitry Andric}; 2980b57cec5SDimitry Andric 2990b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3000b57cec5SDimitry Andricerror_condition 3010b57cec5SDimitry Andricmake_error_condition(errc __e) _NOEXCEPT 3020b57cec5SDimitry Andric{ 3030b57cec5SDimitry Andric return error_condition(static_cast<int>(__e), generic_category()); 3040b57cec5SDimitry Andric} 3050b57cec5SDimitry Andric 3060b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3070b57cec5SDimitry Andricbool 3080b57cec5SDimitry Andricoperator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT 3090b57cec5SDimitry Andric{ 3100b57cec5SDimitry Andric return __x.category() < __y.category() 3110b57cec5SDimitry Andric || (__x.category() == __y.category() && __x.value() < __y.value()); 3120b57cec5SDimitry Andric} 3130b57cec5SDimitry Andric 3140b57cec5SDimitry Andric// error_code 3150b57cec5SDimitry Andric 3160b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS error_code 3170b57cec5SDimitry Andric{ 3180b57cec5SDimitry Andric int __val_; 3190b57cec5SDimitry Andric const error_category* __cat_; 3200b57cec5SDimitry Andricpublic: 3210b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3220b57cec5SDimitry Andric error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {} 3230b57cec5SDimitry Andric 3240b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3250b57cec5SDimitry Andric error_code(int __val, const error_category& __cat) _NOEXCEPT 3260b57cec5SDimitry Andric : __val_(__val), __cat_(&__cat) {} 3270b57cec5SDimitry Andric 3280b57cec5SDimitry Andric template <class _Ep> 3290b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3300b57cec5SDimitry Andric error_code(_Ep __e, 331e8d8bef9SDimitry Andric typename enable_if<is_error_code_enum<_Ep>::value>::type* = nullptr 3320b57cec5SDimitry Andric ) _NOEXCEPT 3330b57cec5SDimitry Andric {*this = make_error_code(__e);} 3340b57cec5SDimitry Andric 3350b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3360b57cec5SDimitry Andric void assign(int __val, const error_category& __cat) _NOEXCEPT 3370b57cec5SDimitry Andric { 3380b57cec5SDimitry Andric __val_ = __val; 3390b57cec5SDimitry Andric __cat_ = &__cat; 3400b57cec5SDimitry Andric } 3410b57cec5SDimitry Andric 3420b57cec5SDimitry Andric template <class _Ep> 3430b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3440b57cec5SDimitry Andric typename enable_if 3450b57cec5SDimitry Andric < 3460b57cec5SDimitry Andric is_error_code_enum<_Ep>::value, 3470b57cec5SDimitry Andric error_code& 3480b57cec5SDimitry Andric >::type 3490b57cec5SDimitry Andric operator=(_Ep __e) _NOEXCEPT 3500b57cec5SDimitry Andric {*this = make_error_code(__e); return *this;} 3510b57cec5SDimitry Andric 3520b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3530b57cec5SDimitry Andric void clear() _NOEXCEPT 3540b57cec5SDimitry Andric { 3550b57cec5SDimitry Andric __val_ = 0; 3560b57cec5SDimitry Andric __cat_ = &system_category(); 3570b57cec5SDimitry Andric } 3580b57cec5SDimitry Andric 3590b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3600b57cec5SDimitry Andric int value() const _NOEXCEPT {return __val_;} 3610b57cec5SDimitry Andric 3620b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3630b57cec5SDimitry Andric const error_category& category() const _NOEXCEPT {return *__cat_;} 3640b57cec5SDimitry Andric 3650b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3660b57cec5SDimitry Andric error_condition default_error_condition() const _NOEXCEPT 3670b57cec5SDimitry Andric {return __cat_->default_error_condition(__val_);} 3680b57cec5SDimitry Andric 3690b57cec5SDimitry Andric string message() const; 3700b57cec5SDimitry Andric 3710b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 372fe6060f1SDimitry Andric explicit operator bool() const _NOEXCEPT {return __val_ != 0;} 3730b57cec5SDimitry Andric}; 3740b57cec5SDimitry Andric 3750b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3760b57cec5SDimitry Andricerror_code 3770b57cec5SDimitry Andricmake_error_code(errc __e) _NOEXCEPT 3780b57cec5SDimitry Andric{ 3790b57cec5SDimitry Andric return error_code(static_cast<int>(__e), generic_category()); 3800b57cec5SDimitry Andric} 3810b57cec5SDimitry Andric 3820b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3830b57cec5SDimitry Andricbool 3840b57cec5SDimitry Andricoperator<(const error_code& __x, const error_code& __y) _NOEXCEPT 3850b57cec5SDimitry Andric{ 3860b57cec5SDimitry Andric return __x.category() < __y.category() 3870b57cec5SDimitry Andric || (__x.category() == __y.category() && __x.value() < __y.value()); 3880b57cec5SDimitry Andric} 3890b57cec5SDimitry Andric 3900b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3910b57cec5SDimitry Andricbool 3920b57cec5SDimitry Andricoperator==(const error_code& __x, const error_code& __y) _NOEXCEPT 3930b57cec5SDimitry Andric{ 3940b57cec5SDimitry Andric return __x.category() == __y.category() && __x.value() == __y.value(); 3950b57cec5SDimitry Andric} 3960b57cec5SDimitry Andric 3970b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3980b57cec5SDimitry Andricbool 3990b57cec5SDimitry Andricoperator==(const error_code& __x, const error_condition& __y) _NOEXCEPT 4000b57cec5SDimitry Andric{ 4010b57cec5SDimitry Andric return __x.category().equivalent(__x.value(), __y) 4020b57cec5SDimitry Andric || __y.category().equivalent(__x, __y.value()); 4030b57cec5SDimitry Andric} 4040b57cec5SDimitry Andric 4050b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4060b57cec5SDimitry Andricbool 4070b57cec5SDimitry Andricoperator==(const error_condition& __x, const error_code& __y) _NOEXCEPT 4080b57cec5SDimitry Andric{ 4090b57cec5SDimitry Andric return __y == __x; 4100b57cec5SDimitry Andric} 4110b57cec5SDimitry Andric 4120b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4130b57cec5SDimitry Andricbool 4140b57cec5SDimitry Andricoperator==(const error_condition& __x, const error_condition& __y) _NOEXCEPT 4150b57cec5SDimitry Andric{ 4160b57cec5SDimitry Andric return __x.category() == __y.category() && __x.value() == __y.value(); 4170b57cec5SDimitry Andric} 4180b57cec5SDimitry Andric 4190b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4200b57cec5SDimitry Andricbool 4210b57cec5SDimitry Andricoperator!=(const error_code& __x, const error_code& __y) _NOEXCEPT 4220b57cec5SDimitry Andric{return !(__x == __y);} 4230b57cec5SDimitry Andric 4240b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4250b57cec5SDimitry Andricbool 4260b57cec5SDimitry Andricoperator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT 4270b57cec5SDimitry Andric{return !(__x == __y);} 4280b57cec5SDimitry Andric 4290b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4300b57cec5SDimitry Andricbool 4310b57cec5SDimitry Andricoperator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT 4320b57cec5SDimitry Andric{return !(__x == __y);} 4330b57cec5SDimitry Andric 4340b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4350b57cec5SDimitry Andricbool 4360b57cec5SDimitry Andricoperator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT 4370b57cec5SDimitry Andric{return !(__x == __y);} 4380b57cec5SDimitry Andric 4390b57cec5SDimitry Andrictemplate <> 4400b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<error_code> 441*81ad6265SDimitry Andric : public __unary_function<error_code, size_t> 4420b57cec5SDimitry Andric{ 4430b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4440b57cec5SDimitry Andric size_t operator()(const error_code& __ec) const _NOEXCEPT 4450b57cec5SDimitry Andric { 4460b57cec5SDimitry Andric return static_cast<size_t>(__ec.value()); 4470b57cec5SDimitry Andric } 4480b57cec5SDimitry Andric}; 4490b57cec5SDimitry Andric 4500b57cec5SDimitry Andrictemplate <> 4510b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<error_condition> 452*81ad6265SDimitry Andric : public __unary_function<error_condition, size_t> 4530b57cec5SDimitry Andric{ 4540b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4550b57cec5SDimitry Andric size_t operator()(const error_condition& __ec) const _NOEXCEPT 4560b57cec5SDimitry Andric { 4570b57cec5SDimitry Andric return static_cast<size_t>(__ec.value()); 4580b57cec5SDimitry Andric } 4590b57cec5SDimitry Andric}; 4600b57cec5SDimitry Andric 4610b57cec5SDimitry Andric// system_error 4620b57cec5SDimitry Andric 4630b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS system_error 4640b57cec5SDimitry Andric : public runtime_error 4650b57cec5SDimitry Andric{ 4660b57cec5SDimitry Andric error_code __ec_; 4670b57cec5SDimitry Andricpublic: 4680b57cec5SDimitry Andric system_error(error_code __ec, const string& __what_arg); 4690b57cec5SDimitry Andric system_error(error_code __ec, const char* __what_arg); 4700b57cec5SDimitry Andric system_error(error_code __ec); 4710b57cec5SDimitry Andric system_error(int __ev, const error_category& __ecat, const string& __what_arg); 4720b57cec5SDimitry Andric system_error(int __ev, const error_category& __ecat, const char* __what_arg); 4730b57cec5SDimitry Andric system_error(int __ev, const error_category& __ecat); 4749ec406dcSDimitry Andric system_error(const system_error&) _NOEXCEPT = default; 4750b57cec5SDimitry Andric ~system_error() _NOEXCEPT; 4760b57cec5SDimitry Andric 4770b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4780b57cec5SDimitry Andric const error_code& code() const _NOEXCEPT {return __ec_;} 4790b57cec5SDimitry Andric 4800b57cec5SDimitry Andricprivate: 4810b57cec5SDimitry Andric static string __init(const error_code&, string); 4820b57cec5SDimitry Andric}; 4830b57cec5SDimitry Andric 4840b57cec5SDimitry Andric_LIBCPP_NORETURN _LIBCPP_FUNC_VIS 4850b57cec5SDimitry Andricvoid __throw_system_error(int ev, const char* what_arg); 4860b57cec5SDimitry Andric 4870b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 4880b57cec5SDimitry Andric 4890b57cec5SDimitry Andric#endif // _LIBCPP_SYSTEM_ERROR 490