13e519524SHoward Hinnant// -*- C++ -*- 23e519524SHoward Hinnant//===---------------------------- system_error ----------------------------===// 33e519524SHoward Hinnant// 457b08b09SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 557b08b09SChandler Carruth// See https://llvm.org/LICENSE.txt for license information. 657b08b09SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 73e519524SHoward Hinnant// 83e519524SHoward Hinnant//===----------------------------------------------------------------------===// 93e519524SHoward Hinnant 103e519524SHoward Hinnant#ifndef _LIBCPP_SYSTEM_ERROR 113e519524SHoward Hinnant#define _LIBCPP_SYSTEM_ERROR 123e519524SHoward Hinnant 133e519524SHoward Hinnant/* 143e519524SHoward Hinnant system_error synopsis 153e519524SHoward Hinnant 163e519524SHoward Hinnantnamespace std 173e519524SHoward Hinnant{ 183e519524SHoward Hinnant 193e519524SHoward Hinnantclass error_category 203e519524SHoward Hinnant{ 213e519524SHoward Hinnantpublic: 22a62f2899SHoward Hinnant virtual ~error_category() noexcept; 233e519524SHoward Hinnant 24a86d5162SMarshall Clow constexpr error_category(); 253e519524SHoward Hinnant error_category(const error_category&) = delete; 263e519524SHoward Hinnant error_category& operator=(const error_category&) = delete; 273e519524SHoward Hinnant 28a62f2899SHoward Hinnant virtual const char* name() const noexcept = 0; 29a62f2899SHoward Hinnant virtual error_condition default_error_condition(int ev) const noexcept; 30a62f2899SHoward Hinnant virtual bool equivalent(int code, const error_condition& condition) const noexcept; 31a62f2899SHoward Hinnant virtual bool equivalent(const error_code& code, int condition) const noexcept; 323e519524SHoward Hinnant virtual string message(int ev) const = 0; 333e519524SHoward Hinnant 34a62f2899SHoward Hinnant bool operator==(const error_category& rhs) const noexcept; 35a62f2899SHoward Hinnant bool operator!=(const error_category& rhs) const noexcept; 36a62f2899SHoward Hinnant bool operator<(const error_category& rhs) const noexcept; 373e519524SHoward Hinnant}; 383e519524SHoward Hinnant 39a62f2899SHoward Hinnantconst error_category& generic_category() noexcept; 40a62f2899SHoward Hinnantconst error_category& system_category() noexcept; 413e519524SHoward Hinnant 423e519524SHoward Hinnanttemplate <class T> struct is_error_code_enum 433e519524SHoward Hinnant : public false_type {}; 443e519524SHoward Hinnant 453e519524SHoward Hinnanttemplate <class T> struct is_error_condition_enum 463e519524SHoward Hinnant : public false_type {}; 473e519524SHoward Hinnant 48e69a08baSMarshall Clowtemplate <class _Tp> 4940a01d53SMarshall Clowinline constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17 50e69a08baSMarshall Clow 51e69a08baSMarshall Clowtemplate <class _Tp> 5240a01d53SMarshall Clowinline constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17 53e69a08baSMarshall Clow 543e519524SHoward Hinnantclass error_code 553e519524SHoward Hinnant{ 563e519524SHoward Hinnantpublic: 573e519524SHoward Hinnant // constructors: 58a62f2899SHoward Hinnant error_code() noexcept; 59a62f2899SHoward Hinnant error_code(int val, const error_category& cat) noexcept; 603e519524SHoward Hinnant template <class ErrorCodeEnum> 61a62f2899SHoward Hinnant error_code(ErrorCodeEnum e) noexcept; 623e519524SHoward Hinnant 633e519524SHoward Hinnant // modifiers: 64a62f2899SHoward Hinnant void assign(int val, const error_category& cat) noexcept; 653e519524SHoward Hinnant template <class ErrorCodeEnum> 66a62f2899SHoward Hinnant error_code& operator=(ErrorCodeEnum e) noexcept; 67a62f2899SHoward Hinnant void clear() noexcept; 683e519524SHoward Hinnant 693e519524SHoward Hinnant // observers: 70a62f2899SHoward Hinnant int value() const noexcept; 71a62f2899SHoward Hinnant const error_category& category() const noexcept; 72a62f2899SHoward Hinnant error_condition default_error_condition() const noexcept; 733e519524SHoward Hinnant string message() const; 74a62f2899SHoward Hinnant explicit operator bool() const noexcept; 753e519524SHoward Hinnant}; 763e519524SHoward Hinnant 773e519524SHoward Hinnant// non-member functions: 78a62f2899SHoward Hinnantbool operator<(const error_code& lhs, const error_code& rhs) noexcept; 793e519524SHoward Hinnanttemplate <class charT, class traits> 803e519524SHoward Hinnant basic_ostream<charT,traits>& 813e519524SHoward Hinnant operator<<(basic_ostream<charT,traits>& os, const error_code& ec); 823e519524SHoward Hinnant 833e519524SHoward Hinnantclass error_condition 843e519524SHoward Hinnant{ 853e519524SHoward Hinnantpublic: 863e519524SHoward Hinnant // constructors: 87a62f2899SHoward Hinnant error_condition() noexcept; 88a62f2899SHoward Hinnant error_condition(int val, const error_category& cat) noexcept; 893e519524SHoward Hinnant template <class ErrorConditionEnum> 90a62f2899SHoward Hinnant error_condition(ErrorConditionEnum e) noexcept; 913e519524SHoward Hinnant 923e519524SHoward Hinnant // modifiers: 93a62f2899SHoward Hinnant void assign(int val, const error_category& cat) noexcept; 943e519524SHoward Hinnant template <class ErrorConditionEnum> 95a62f2899SHoward Hinnant error_condition& operator=(ErrorConditionEnum e) noexcept; 96a62f2899SHoward Hinnant void clear() noexcept; 973e519524SHoward Hinnant 983e519524SHoward Hinnant // observers: 99a62f2899SHoward Hinnant int value() const noexcept; 100a62f2899SHoward Hinnant const error_category& category() const noexcept; 101a62f2899SHoward Hinnant string message() const noexcept; 102a62f2899SHoward Hinnant explicit operator bool() const noexcept; 1033e519524SHoward Hinnant}; 1043e519524SHoward Hinnant 105a62f2899SHoward Hinnantbool operator<(const error_condition& lhs, const error_condition& rhs) noexcept; 1063e519524SHoward Hinnant 1073e519524SHoward Hinnantclass system_error 1083e519524SHoward Hinnant : public runtime_error 1093e519524SHoward Hinnant{ 1103e519524SHoward Hinnantpublic: 1113e519524SHoward Hinnant system_error(error_code ec, const string& what_arg); 1123e519524SHoward Hinnant system_error(error_code ec, const char* what_arg); 1133e519524SHoward Hinnant system_error(error_code ec); 1143e519524SHoward Hinnant system_error(int ev, const error_category& ecat, const string& what_arg); 1153e519524SHoward Hinnant system_error(int ev, const error_category& ecat, const char* what_arg); 1163e519524SHoward Hinnant system_error(int ev, const error_category& ecat); 1173e519524SHoward Hinnant 118a62f2899SHoward Hinnant const error_code& code() const noexcept; 119a62f2899SHoward Hinnant const char* what() const noexcept; 1203e519524SHoward Hinnant}; 1213e519524SHoward Hinnant 1223e519524SHoward Hinnanttemplate <> struct is_error_condition_enum<errc> 1233e519524SHoward Hinnant : true_type { } 1243e519524SHoward Hinnant 125a62f2899SHoward Hinnanterror_code make_error_code(errc e) noexcept; 126a62f2899SHoward Hinnanterror_condition make_error_condition(errc e) noexcept; 1273e519524SHoward Hinnant 1283e519524SHoward Hinnant// Comparison operators: 129a62f2899SHoward Hinnantbool operator==(const error_code& lhs, const error_code& rhs) noexcept; 130a62f2899SHoward Hinnantbool operator==(const error_code& lhs, const error_condition& rhs) noexcept; 131a62f2899SHoward Hinnantbool operator==(const error_condition& lhs, const error_code& rhs) noexcept; 132a62f2899SHoward Hinnantbool operator==(const error_condition& lhs, const error_condition& rhs) noexcept; 133a62f2899SHoward Hinnantbool operator!=(const error_code& lhs, const error_code& rhs) noexcept; 134a62f2899SHoward Hinnantbool operator!=(const error_code& lhs, const error_condition& rhs) noexcept; 135a62f2899SHoward Hinnantbool operator!=(const error_condition& lhs, const error_code& rhs) noexcept; 136a62f2899SHoward Hinnantbool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept; 1373e519524SHoward Hinnant 1383e519524SHoward Hinnanttemplate <> struct hash<std::error_code>; 1391c7fe126SMarshall Clowtemplate <> struct hash<std::error_condition>; 1403e519524SHoward Hinnant 1413e519524SHoward Hinnant} // std 1423e519524SHoward Hinnant 1433e519524SHoward Hinnant*/ 1443e519524SHoward Hinnant 14543aaf871SArthur O'Dwyer#include <__config> 1464f4effd6SZhihao Yuan#include <__errc> 14743aaf871SArthur O'Dwyer#include <__functional_base> // unary_function 148*2d0f1fa4SArthur O'Dwyer#include <compare> 1493e519524SHoward Hinnant#include <stdexcept> 150bc455478SMarshall Clow#include <string> 15143aaf871SArthur O'Dwyer#include <type_traits> 1523e519524SHoward Hinnant 153073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1543e519524SHoward Hinnant#pragma GCC system_header 155073458b1SHoward Hinnant#endif 1563e519524SHoward Hinnant 1573e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD 1583e519524SHoward Hinnant 1593e519524SHoward Hinnant// is_error_code_enum 1603e519524SHoward Hinnant 161e0601335SHoward Hinnanttemplate <class _Tp> 162e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS is_error_code_enum 1633e519524SHoward Hinnant : public false_type {}; 1643e519524SHoward Hinnant 165e69a08baSMarshall Clow#if _LIBCPP_STD_VER > 14 166e69a08baSMarshall Clowtemplate <class _Tp> 16740a01d53SMarshall Clow_LIBCPP_INLINE_VAR constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; 168e69a08baSMarshall Clow#endif 169e69a08baSMarshall Clow 1703e519524SHoward Hinnant// is_error_condition_enum 1713e519524SHoward Hinnant 172e0601335SHoward Hinnanttemplate <class _Tp> 173e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum 1743e519524SHoward Hinnant : public false_type {}; 1753e519524SHoward Hinnant 176e69a08baSMarshall Clow#if _LIBCPP_STD_VER > 14 177e69a08baSMarshall Clowtemplate <class _Tp> 17840a01d53SMarshall Clow_LIBCPP_INLINE_VAR constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; 179e69a08baSMarshall Clow#endif 180e69a08baSMarshall Clow 181e0601335SHoward Hinnanttemplate <> 182e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc> 1833e519524SHoward Hinnant : true_type { }; 1843e519524SHoward Hinnant 18575689c10SHoward Hinnant#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS 186e0601335SHoward Hinnanttemplate <> 187e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc::__lx> 1883e519524SHoward Hinnant : true_type { }; 18975689c10SHoward Hinnant#endif 1903e519524SHoward Hinnant 1916e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_condition; 1926e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_code; 1933e519524SHoward Hinnant 1943e519524SHoward Hinnant// class error_category 1953e519524SHoward Hinnant 196aeb85680SHoward Hinnantclass _LIBCPP_HIDDEN __do_message; 1973e519524SHoward Hinnant 1986e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_category 1993e519524SHoward Hinnant{ 2003e519524SHoward Hinnantpublic: 201a62f2899SHoward Hinnant virtual ~error_category() _NOEXCEPT; 2023e519524SHoward Hinnant 203c8e84ff2SLouis Dionne#if defined(_LIBCPP_BUILDING_LIBRARY) && \ 20411f60453SEric Fiselier defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) 205a62f2899SHoward Hinnant error_category() _NOEXCEPT; 206a86d5162SMarshall Clow#else 207dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 208e57e3aebSEric Fiselier _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT _LIBCPP_DEFAULT 209a86d5162SMarshall Clow#endif 210cb16c680SHoward Hinnantprivate: 2113e519524SHoward Hinnant error_category(const error_category&);// = delete; 2123e519524SHoward Hinnant error_category& operator=(const error_category&);// = delete; 2133e519524SHoward Hinnant 2143e519524SHoward Hinnantpublic: 215a62f2899SHoward Hinnant virtual const char* name() const _NOEXCEPT = 0; 216a62f2899SHoward Hinnant virtual error_condition default_error_condition(int __ev) const _NOEXCEPT; 217a62f2899SHoward Hinnant virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT; 218a62f2899SHoward Hinnant virtual bool equivalent(const error_code& __code, int __condition) const _NOEXCEPT; 2193e519524SHoward Hinnant virtual string message(int __ev) const = 0; 2203e519524SHoward Hinnant 221dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 222a62f2899SHoward Hinnant bool operator==(const error_category& __rhs) const _NOEXCEPT {return this == &__rhs;} 2233e519524SHoward Hinnant 224dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 225a62f2899SHoward Hinnant bool operator!=(const error_category& __rhs) const _NOEXCEPT {return !(*this == __rhs);} 2263e519524SHoward Hinnant 227dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 228a62f2899SHoward Hinnant bool operator< (const error_category& __rhs) const _NOEXCEPT {return this < &__rhs;} 2293e519524SHoward Hinnant 230aeb85680SHoward Hinnant friend class _LIBCPP_HIDDEN __do_message; 2313e519524SHoward Hinnant}; 2323e519524SHoward Hinnant 2333e519524SHoward Hinnantclass _LIBCPP_HIDDEN __do_message 2343e519524SHoward Hinnant : public error_category 2353e519524SHoward Hinnant{ 2363e519524SHoward Hinnantpublic: 2373e519524SHoward Hinnant virtual string message(int ev) const; 2383e519524SHoward Hinnant}; 2393e519524SHoward Hinnant 240f0544c20SHoward Hinnant_LIBCPP_FUNC_VIS const error_category& generic_category() _NOEXCEPT; 241f0544c20SHoward Hinnant_LIBCPP_FUNC_VIS const error_category& system_category() _NOEXCEPT; 2423e519524SHoward Hinnant 2436e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_condition 2443e519524SHoward Hinnant{ 2453e519524SHoward Hinnant int __val_; 2463e519524SHoward Hinnant const error_category* __cat_; 2473e519524SHoward Hinnantpublic: 248dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 249a62f2899SHoward Hinnant error_condition() _NOEXCEPT : __val_(0), __cat_(&generic_category()) {} 2503e519524SHoward Hinnant 251dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 252a62f2899SHoward Hinnant error_condition(int __val, const error_category& __cat) _NOEXCEPT 2533e519524SHoward Hinnant : __val_(__val), __cat_(&__cat) {} 2543e519524SHoward Hinnant 255c003db1fSHoward Hinnant template <class _Ep> 256dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 257c003db1fSHoward Hinnant error_condition(_Ep __e, 258527a7fdfSBruce Mitchener typename enable_if<is_error_condition_enum<_Ep>::value>::type* = nullptr 259a62f2899SHoward Hinnant ) _NOEXCEPT 2603e519524SHoward Hinnant {*this = make_error_condition(__e);} 2613e519524SHoward Hinnant 262dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 263a62f2899SHoward Hinnant void assign(int __val, const error_category& __cat) _NOEXCEPT 2643e519524SHoward Hinnant { 2653e519524SHoward Hinnant __val_ = __val; 2663e519524SHoward Hinnant __cat_ = &__cat; 2673e519524SHoward Hinnant } 2683e519524SHoward Hinnant 269c003db1fSHoward Hinnant template <class _Ep> 270dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 2713e519524SHoward Hinnant typename enable_if 2723e519524SHoward Hinnant < 273c003db1fSHoward Hinnant is_error_condition_enum<_Ep>::value, 2743e519524SHoward Hinnant error_condition& 2753e519524SHoward Hinnant >::type 276c003db1fSHoward Hinnant operator=(_Ep __e) _NOEXCEPT 2773e519524SHoward Hinnant {*this = make_error_condition(__e); return *this;} 2783e519524SHoward Hinnant 279dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 280a62f2899SHoward Hinnant void clear() _NOEXCEPT 2813e519524SHoward Hinnant { 2823e519524SHoward Hinnant __val_ = 0; 2833e519524SHoward Hinnant __cat_ = &generic_category(); 2843e519524SHoward Hinnant } 2853e519524SHoward Hinnant 286dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 287a62f2899SHoward Hinnant int value() const _NOEXCEPT {return __val_;} 2883e519524SHoward Hinnant 289dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 290a62f2899SHoward Hinnant const error_category& category() const _NOEXCEPT {return *__cat_;} 2913e519524SHoward Hinnant string message() const; 2923e519524SHoward Hinnant 293dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 294f2f2d8b9SHoward Hinnant _LIBCPP_EXPLICIT 295a62f2899SHoward Hinnant operator bool() const _NOEXCEPT {return __val_ != 0;} 2963e519524SHoward Hinnant}; 2973e519524SHoward Hinnant 2983e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2993e519524SHoward Hinnanterror_condition 300a62f2899SHoward Hinnantmake_error_condition(errc __e) _NOEXCEPT 3013e519524SHoward Hinnant{ 3023e519524SHoward Hinnant return error_condition(static_cast<int>(__e), generic_category()); 3033e519524SHoward Hinnant} 3043e519524SHoward Hinnant 3053e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 3063e519524SHoward Hinnantbool 307a62f2899SHoward Hinnantoperator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT 3083e519524SHoward Hinnant{ 3093e519524SHoward Hinnant return __x.category() < __y.category() 310c206366fSHoward Hinnant || (__x.category() == __y.category() && __x.value() < __y.value()); 3113e519524SHoward Hinnant} 3123e519524SHoward Hinnant 3133e519524SHoward Hinnant// error_code 3143e519524SHoward Hinnant 3156e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS error_code 3163e519524SHoward Hinnant{ 3173e519524SHoward Hinnant int __val_; 3183e519524SHoward Hinnant const error_category* __cat_; 3193e519524SHoward Hinnantpublic: 320dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 321a62f2899SHoward Hinnant error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {} 3223e519524SHoward Hinnant 323dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 324a62f2899SHoward Hinnant error_code(int __val, const error_category& __cat) _NOEXCEPT 3253e519524SHoward Hinnant : __val_(__val), __cat_(&__cat) {} 3263e519524SHoward Hinnant 327c003db1fSHoward Hinnant template <class _Ep> 328dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 329c003db1fSHoward Hinnant error_code(_Ep __e, 330527a7fdfSBruce Mitchener typename enable_if<is_error_code_enum<_Ep>::value>::type* = nullptr 331a62f2899SHoward Hinnant ) _NOEXCEPT 3323e519524SHoward Hinnant {*this = make_error_code(__e);} 3333e519524SHoward Hinnant 334dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 335a62f2899SHoward Hinnant void assign(int __val, const error_category& __cat) _NOEXCEPT 3363e519524SHoward Hinnant { 3373e519524SHoward Hinnant __val_ = __val; 3383e519524SHoward Hinnant __cat_ = &__cat; 3393e519524SHoward Hinnant } 3403e519524SHoward Hinnant 341c003db1fSHoward Hinnant template <class _Ep> 342dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 3433e519524SHoward Hinnant typename enable_if 3443e519524SHoward Hinnant < 345c003db1fSHoward Hinnant is_error_code_enum<_Ep>::value, 3463e519524SHoward Hinnant error_code& 3473e519524SHoward Hinnant >::type 348c003db1fSHoward Hinnant operator=(_Ep __e) _NOEXCEPT 3493e519524SHoward Hinnant {*this = make_error_code(__e); return *this;} 3503e519524SHoward Hinnant 351dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 352a62f2899SHoward Hinnant void clear() _NOEXCEPT 3533e519524SHoward Hinnant { 3543e519524SHoward Hinnant __val_ = 0; 3553e519524SHoward Hinnant __cat_ = &system_category(); 3563e519524SHoward Hinnant } 3573e519524SHoward Hinnant 358dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 359a62f2899SHoward Hinnant int value() const _NOEXCEPT {return __val_;} 3603e519524SHoward Hinnant 361dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 362a62f2899SHoward Hinnant const error_category& category() const _NOEXCEPT {return *__cat_;} 3633e519524SHoward Hinnant 364dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 365a62f2899SHoward Hinnant error_condition default_error_condition() const _NOEXCEPT 3663e519524SHoward Hinnant {return __cat_->default_error_condition(__val_);} 3673e519524SHoward Hinnant 3683e519524SHoward Hinnant string message() const; 3693e519524SHoward Hinnant 370dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 371f2f2d8b9SHoward Hinnant _LIBCPP_EXPLICIT 372a62f2899SHoward Hinnant operator bool() const _NOEXCEPT {return __val_ != 0;} 3733e519524SHoward Hinnant}; 3743e519524SHoward Hinnant 3753e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 3763e519524SHoward Hinnanterror_code 377a62f2899SHoward Hinnantmake_error_code(errc __e) _NOEXCEPT 3783e519524SHoward Hinnant{ 3793e519524SHoward Hinnant return error_code(static_cast<int>(__e), generic_category()); 3803e519524SHoward Hinnant} 3813e519524SHoward Hinnant 3823e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 3833e519524SHoward Hinnantbool 384a62f2899SHoward Hinnantoperator<(const error_code& __x, const error_code& __y) _NOEXCEPT 3853e519524SHoward Hinnant{ 3863e519524SHoward Hinnant return __x.category() < __y.category() 387c206366fSHoward Hinnant || (__x.category() == __y.category() && __x.value() < __y.value()); 3883e519524SHoward Hinnant} 3893e519524SHoward Hinnant 3903e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 3913e519524SHoward Hinnantbool 392a62f2899SHoward Hinnantoperator==(const error_code& __x, const error_code& __y) _NOEXCEPT 3933e519524SHoward Hinnant{ 3943e519524SHoward Hinnant return __x.category() == __y.category() && __x.value() == __y.value(); 3953e519524SHoward Hinnant} 3963e519524SHoward Hinnant 3973e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 3983e519524SHoward Hinnantbool 399a62f2899SHoward Hinnantoperator==(const error_code& __x, const error_condition& __y) _NOEXCEPT 4003e519524SHoward Hinnant{ 4013e519524SHoward Hinnant return __x.category().equivalent(__x.value(), __y) 4023e519524SHoward Hinnant || __y.category().equivalent(__x, __y.value()); 4033e519524SHoward Hinnant} 4043e519524SHoward Hinnant 4053e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 4063e519524SHoward Hinnantbool 407a62f2899SHoward Hinnantoperator==(const error_condition& __x, const error_code& __y) _NOEXCEPT 4083e519524SHoward Hinnant{ 4093e519524SHoward Hinnant return __y == __x; 4103e519524SHoward Hinnant} 4113e519524SHoward Hinnant 4123e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 4133e519524SHoward Hinnantbool 414a62f2899SHoward Hinnantoperator==(const error_condition& __x, const error_condition& __y) _NOEXCEPT 4153e519524SHoward Hinnant{ 4163e519524SHoward Hinnant return __x.category() == __y.category() && __x.value() == __y.value(); 4173e519524SHoward Hinnant} 4183e519524SHoward Hinnant 4193e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 4203e519524SHoward Hinnantbool 421a62f2899SHoward Hinnantoperator!=(const error_code& __x, const error_code& __y) _NOEXCEPT 422a62f2899SHoward Hinnant{return !(__x == __y);} 4233e519524SHoward Hinnant 4243e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 4253e519524SHoward Hinnantbool 426a62f2899SHoward Hinnantoperator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT 427a62f2899SHoward Hinnant{return !(__x == __y);} 4283e519524SHoward Hinnant 4293e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 4303e519524SHoward Hinnantbool 431a62f2899SHoward Hinnantoperator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT 432a62f2899SHoward Hinnant{return !(__x == __y);} 4333e519524SHoward Hinnant 4343e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 4353e519524SHoward Hinnantbool 436a62f2899SHoward Hinnantoperator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT 437a62f2899SHoward Hinnant{return !(__x == __y);} 4383e519524SHoward Hinnant 4393e519524SHoward Hinnanttemplate <> 440e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<error_code> 4413e519524SHoward Hinnant : public unary_function<error_code, size_t> 4423e519524SHoward Hinnant{ 443e0601335SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 444a62f2899SHoward Hinnant size_t operator()(const error_code& __ec) const _NOEXCEPT 4453e519524SHoward Hinnant { 4463e519524SHoward Hinnant return static_cast<size_t>(__ec.value()); 4473e519524SHoward Hinnant } 4483e519524SHoward Hinnant}; 4493e519524SHoward Hinnant 4501c7fe126SMarshall Clowtemplate <> 451e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<error_condition> 4521c7fe126SMarshall Clow : public unary_function<error_condition, size_t> 4531c7fe126SMarshall Clow{ 4541c7fe126SMarshall Clow _LIBCPP_INLINE_VISIBILITY 4551c7fe126SMarshall Clow size_t operator()(const error_condition& __ec) const _NOEXCEPT 4561c7fe126SMarshall Clow { 4571c7fe126SMarshall Clow return static_cast<size_t>(__ec.value()); 4581c7fe126SMarshall Clow } 4591c7fe126SMarshall Clow}; 4601c7fe126SMarshall Clow 4613e519524SHoward Hinnant// system_error 4623e519524SHoward Hinnant 4636e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS system_error 4643e519524SHoward Hinnant : public runtime_error 4653e519524SHoward Hinnant{ 4663e519524SHoward Hinnant error_code __ec_; 4673e519524SHoward Hinnantpublic: 4683e519524SHoward Hinnant system_error(error_code __ec, const string& __what_arg); 4693e519524SHoward Hinnant system_error(error_code __ec, const char* __what_arg); 4703e519524SHoward Hinnant system_error(error_code __ec); 4713e519524SHoward Hinnant system_error(int __ev, const error_category& __ecat, const string& __what_arg); 4723e519524SHoward Hinnant system_error(int __ev, const error_category& __ecat, const char* __what_arg); 4733e519524SHoward Hinnant system_error(int __ev, const error_category& __ecat); 474585a3cc3SDimitry Andric system_error(const system_error&) _NOEXCEPT = default; 475a62f2899SHoward Hinnant ~system_error() _NOEXCEPT; 4763e519524SHoward Hinnant 477dc7200b4SLouis Dionne _LIBCPP_INLINE_VISIBILITY 478a62f2899SHoward Hinnant const error_code& code() const _NOEXCEPT {return __ec_;} 4793e519524SHoward Hinnant 4803e519524SHoward Hinnantprivate: 4813e519524SHoward Hinnant static string __init(const error_code&, string); 4823e519524SHoward Hinnant}; 4833e519524SHoward Hinnant 484d51f2a2aSAditya Kumar_LIBCPP_NORETURN _LIBCPP_FUNC_VIS 485d51f2a2aSAditya Kumarvoid __throw_system_error(int ev, const char* what_arg); 4863e519524SHoward Hinnant 4873e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD 4883e519524SHoward Hinnant 4893e519524SHoward Hinnant#endif // _LIBCPP_SYSTEM_ERROR 490