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