Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===---------------------------- system_error ----------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_SYSTEM_ERROR |
| 12 | #define _LIBCPP_SYSTEM_ERROR |
| 13 | |
| 14 | /* |
| 15 | system_error synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | class error_category |
| 21 | { |
| 22 | public: |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 23 | virtual ~error_category() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 24 | |
Marshall Clow | 5c316a6 | 2013-08-21 02:57:19 +0000 | [diff] [blame] | 25 | constexpr error_category(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 26 | error_category(const error_category&) = delete; |
| 27 | error_category& operator=(const error_category&) = delete; |
| 28 | |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 29 | virtual const char* name() const noexcept = 0; |
| 30 | virtual error_condition default_error_condition(int ev) const noexcept; |
| 31 | virtual bool equivalent(int code, const error_condition& condition) const noexcept; |
| 32 | virtual bool equivalent(const error_code& code, int condition) const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 33 | virtual string message(int ev) const = 0; |
| 34 | |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 35 | bool operator==(const error_category& rhs) const noexcept; |
| 36 | bool operator!=(const error_category& rhs) const noexcept; |
| 37 | bool operator<(const error_category& rhs) const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 40 | const error_category& generic_category() noexcept; |
| 41 | const error_category& system_category() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 42 | |
| 43 | template <class T> struct is_error_code_enum |
| 44 | : public false_type {}; |
| 45 | |
| 46 | template <class T> struct is_error_condition_enum |
| 47 | : public false_type {}; |
| 48 | |
Marshall Clow | db86684 | 2016-09-24 17:36:14 +0000 | [diff] [blame] | 49 | template <class _Tp> |
| 50 | constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17 |
| 51 | |
| 52 | template <class _Tp> |
| 53 | constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17 |
| 54 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 55 | class error_code |
| 56 | { |
| 57 | public: |
| 58 | // constructors: |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 59 | error_code() noexcept; |
| 60 | error_code(int val, const error_category& cat) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 61 | template <class ErrorCodeEnum> |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 62 | error_code(ErrorCodeEnum e) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 63 | |
| 64 | // modifiers: |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 65 | void assign(int val, const error_category& cat) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 66 | template <class ErrorCodeEnum> |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 67 | error_code& operator=(ErrorCodeEnum e) noexcept; |
| 68 | void clear() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 69 | |
| 70 | // observers: |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 71 | int value() const noexcept; |
| 72 | const error_category& category() const noexcept; |
| 73 | error_condition default_error_condition() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 74 | string message() const; |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 75 | explicit operator bool() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | // non-member functions: |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 79 | bool operator<(const error_code& lhs, const error_code& rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 80 | template <class charT, class traits> |
| 81 | basic_ostream<charT,traits>& |
| 82 | operator<<(basic_ostream<charT,traits>& os, const error_code& ec); |
| 83 | |
| 84 | class error_condition |
| 85 | { |
| 86 | public: |
| 87 | // constructors: |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 88 | error_condition() noexcept; |
| 89 | error_condition(int val, const error_category& cat) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 90 | template <class ErrorConditionEnum> |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 91 | error_condition(ErrorConditionEnum e) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 92 | |
| 93 | // modifiers: |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 94 | void assign(int val, const error_category& cat) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 95 | template <class ErrorConditionEnum> |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 96 | error_condition& operator=(ErrorConditionEnum e) noexcept; |
| 97 | void clear() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 98 | |
| 99 | // observers: |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 100 | int value() const noexcept; |
| 101 | const error_category& category() const noexcept; |
| 102 | string message() const noexcept; |
| 103 | explicit operator bool() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 106 | bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 107 | |
| 108 | class system_error |
| 109 | : public runtime_error |
| 110 | { |
| 111 | public: |
| 112 | system_error(error_code ec, const string& what_arg); |
| 113 | system_error(error_code ec, const char* what_arg); |
| 114 | system_error(error_code ec); |
| 115 | system_error(int ev, const error_category& ecat, const string& what_arg); |
| 116 | system_error(int ev, const error_category& ecat, const char* what_arg); |
| 117 | system_error(int ev, const error_category& ecat); |
| 118 | |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 119 | const error_code& code() const noexcept; |
| 120 | const char* what() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | enum class errc |
| 124 | { |
| 125 | address_family_not_supported, // EAFNOSUPPORT |
| 126 | address_in_use, // EADDRINUSE |
| 127 | address_not_available, // EADDRNOTAVAIL |
| 128 | already_connected, // EISCONN |
| 129 | argument_list_too_long, // E2BIG |
| 130 | argument_out_of_domain, // EDOM |
| 131 | bad_address, // EFAULT |
| 132 | bad_file_descriptor, // EBADF |
| 133 | bad_message, // EBADMSG |
| 134 | broken_pipe, // EPIPE |
| 135 | connection_aborted, // ECONNABORTED |
| 136 | connection_already_in_progress, // EALREADY |
| 137 | connection_refused, // ECONNREFUSED |
| 138 | connection_reset, // ECONNRESET |
| 139 | cross_device_link, // EXDEV |
| 140 | destination_address_required, // EDESTADDRREQ |
| 141 | device_or_resource_busy, // EBUSY |
| 142 | directory_not_empty, // ENOTEMPTY |
| 143 | executable_format_error, // ENOEXEC |
| 144 | file_exists, // EEXIST |
| 145 | file_too_large, // EFBIG |
| 146 | filename_too_long, // ENAMETOOLONG |
| 147 | function_not_supported, // ENOSYS |
| 148 | host_unreachable, // EHOSTUNREACH |
| 149 | identifier_removed, // EIDRM |
| 150 | illegal_byte_sequence, // EILSEQ |
| 151 | inappropriate_io_control_operation, // ENOTTY |
| 152 | interrupted, // EINTR |
| 153 | invalid_argument, // EINVAL |
| 154 | invalid_seek, // ESPIPE |
| 155 | io_error, // EIO |
| 156 | is_a_directory, // EISDIR |
| 157 | message_size, // EMSGSIZE |
| 158 | network_down, // ENETDOWN |
| 159 | network_reset, // ENETRESET |
| 160 | network_unreachable, // ENETUNREACH |
| 161 | no_buffer_space, // ENOBUFS |
| 162 | no_child_process, // ECHILD |
| 163 | no_link, // ENOLINK |
| 164 | no_lock_available, // ENOLCK |
| 165 | no_message_available, // ENODATA |
| 166 | no_message, // ENOMSG |
| 167 | no_protocol_option, // ENOPROTOOPT |
| 168 | no_space_on_device, // ENOSPC |
| 169 | no_stream_resources, // ENOSR |
| 170 | no_such_device_or_address, // ENXIO |
| 171 | no_such_device, // ENODEV |
| 172 | no_such_file_or_directory, // ENOENT |
| 173 | no_such_process, // ESRCH |
| 174 | not_a_directory, // ENOTDIR |
| 175 | not_a_socket, // ENOTSOCK |
| 176 | not_a_stream, // ENOSTR |
| 177 | not_connected, // ENOTCONN |
| 178 | not_enough_memory, // ENOMEM |
| 179 | not_supported, // ENOTSUP |
| 180 | operation_canceled, // ECANCELED |
| 181 | operation_in_progress, // EINPROGRESS |
| 182 | operation_not_permitted, // EPERM |
| 183 | operation_not_supported, // EOPNOTSUPP |
| 184 | operation_would_block, // EWOULDBLOCK |
| 185 | owner_dead, // EOWNERDEAD |
| 186 | permission_denied, // EACCES |
| 187 | protocol_error, // EPROTO |
| 188 | protocol_not_supported, // EPROTONOSUPPORT |
| 189 | read_only_file_system, // EROFS |
| 190 | resource_deadlock_would_occur, // EDEADLK |
| 191 | resource_unavailable_try_again, // EAGAIN |
| 192 | result_out_of_range, // ERANGE |
| 193 | state_not_recoverable, // ENOTRECOVERABLE |
| 194 | stream_timeout, // ETIME |
| 195 | text_file_busy, // ETXTBSY |
| 196 | timed_out, // ETIMEDOUT |
| 197 | too_many_files_open_in_system, // ENFILE |
| 198 | too_many_files_open, // EMFILE |
| 199 | too_many_links, // EMLINK |
| 200 | too_many_symbolic_link_levels, // ELOOP |
| 201 | value_too_large, // EOVERFLOW |
| 202 | wrong_protocol_type // EPROTOTYPE |
| 203 | }; |
| 204 | |
| 205 | template <> struct is_error_condition_enum<errc> |
| 206 | : true_type { } |
| 207 | |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 208 | error_code make_error_code(errc e) noexcept; |
| 209 | error_condition make_error_condition(errc e) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 210 | |
| 211 | // Comparison operators: |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 212 | bool operator==(const error_code& lhs, const error_code& rhs) noexcept; |
| 213 | bool operator==(const error_code& lhs, const error_condition& rhs) noexcept; |
| 214 | bool operator==(const error_condition& lhs, const error_code& rhs) noexcept; |
| 215 | bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept; |
| 216 | bool operator!=(const error_code& lhs, const error_code& rhs) noexcept; |
| 217 | bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept; |
| 218 | bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept; |
| 219 | bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 220 | |
| 221 | template <> struct hash<std::error_code>; |
Marshall Clow | db7fa11 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 222 | template <> struct hash<std::error_condition>; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 223 | |
| 224 | } // std |
| 225 | |
| 226 | */ |
| 227 | |
| 228 | #include <__config> |
| 229 | #include <cerrno> |
| 230 | #include <type_traits> |
| 231 | #include <stdexcept> |
| 232 | #include <__functional_base> |
| 233 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 234 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 235 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 236 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 237 | |
| 238 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 239 | |
| 240 | // is_error_code_enum |
| 241 | |
Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 242 | template <class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 243 | struct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 244 | : public false_type {}; |
| 245 | |
Marshall Clow | db86684 | 2016-09-24 17:36:14 +0000 | [diff] [blame] | 246 | #if _LIBCPP_STD_VER > 14 |
| 247 | template <class _Tp> |
| 248 | constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; |
| 249 | #endif |
| 250 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 251 | // is_error_condition_enum |
| 252 | |
Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 253 | template <class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 254 | struct _LIBCPP_TYPE_VIS_ONLY is_error_condition_enum |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 255 | : public false_type {}; |
| 256 | |
Marshall Clow | db86684 | 2016-09-24 17:36:14 +0000 | [diff] [blame] | 257 | #if _LIBCPP_STD_VER > 14 |
| 258 | template <class _Tp> |
| 259 | constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; |
| 260 | #endif |
| 261 | |
David Chisnall | 81e6858 | 2010-08-11 16:52:41 +0000 | [diff] [blame] | 262 | // Some error codes are not present on all platforms, so we provide equivalents |
| 263 | // for them: |
| 264 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 265 | //enum class errc |
Howard Hinnant | f6d875f | 2011-12-02 19:36:40 +0000 | [diff] [blame] | 266 | _LIBCPP_DECLARE_STRONG_ENUM(errc) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 267 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 268 | address_family_not_supported = EAFNOSUPPORT, |
| 269 | address_in_use = EADDRINUSE, |
| 270 | address_not_available = EADDRNOTAVAIL, |
| 271 | already_connected = EISCONN, |
| 272 | argument_list_too_long = E2BIG, |
| 273 | argument_out_of_domain = EDOM, |
| 274 | bad_address = EFAULT, |
| 275 | bad_file_descriptor = EBADF, |
| 276 | bad_message = EBADMSG, |
| 277 | broken_pipe = EPIPE, |
| 278 | connection_aborted = ECONNABORTED, |
| 279 | connection_already_in_progress = EALREADY, |
| 280 | connection_refused = ECONNREFUSED, |
| 281 | connection_reset = ECONNRESET, |
| 282 | cross_device_link = EXDEV, |
| 283 | destination_address_required = EDESTADDRREQ, |
| 284 | device_or_resource_busy = EBUSY, |
| 285 | directory_not_empty = ENOTEMPTY, |
| 286 | executable_format_error = ENOEXEC, |
| 287 | file_exists = EEXIST, |
| 288 | file_too_large = EFBIG, |
| 289 | filename_too_long = ENAMETOOLONG, |
| 290 | function_not_supported = ENOSYS, |
| 291 | host_unreachable = EHOSTUNREACH, |
| 292 | identifier_removed = EIDRM, |
| 293 | illegal_byte_sequence = EILSEQ, |
| 294 | inappropriate_io_control_operation = ENOTTY, |
| 295 | interrupted = EINTR, |
| 296 | invalid_argument = EINVAL, |
| 297 | invalid_seek = ESPIPE, |
| 298 | io_error = EIO, |
| 299 | is_a_directory = EISDIR, |
| 300 | message_size = EMSGSIZE, |
| 301 | network_down = ENETDOWN, |
| 302 | network_reset = ENETRESET, |
| 303 | network_unreachable = ENETUNREACH, |
| 304 | no_buffer_space = ENOBUFS, |
| 305 | no_child_process = ECHILD, |
| 306 | no_link = ENOLINK, |
| 307 | no_lock_available = ENOLCK, |
David Chisnall | 81e6858 | 2010-08-11 16:52:41 +0000 | [diff] [blame] | 308 | #ifdef ENODATA |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 309 | no_message_available = ENODATA, |
David Chisnall | 81e6858 | 2010-08-11 16:52:41 +0000 | [diff] [blame] | 310 | #else |
| 311 | no_message_available = ENOMSG, |
| 312 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 313 | no_message = ENOMSG, |
| 314 | no_protocol_option = ENOPROTOOPT, |
| 315 | no_space_on_device = ENOSPC, |
David Chisnall | 81e6858 | 2010-08-11 16:52:41 +0000 | [diff] [blame] | 316 | #ifdef ENOSR |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 317 | no_stream_resources = ENOSR, |
David Chisnall | 81e6858 | 2010-08-11 16:52:41 +0000 | [diff] [blame] | 318 | #else |
| 319 | no_stream_resources = ENOMEM, |
| 320 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 321 | no_such_device_or_address = ENXIO, |
| 322 | no_such_device = ENODEV, |
| 323 | no_such_file_or_directory = ENOENT, |
| 324 | no_such_process = ESRCH, |
| 325 | not_a_directory = ENOTDIR, |
| 326 | not_a_socket = ENOTSOCK, |
David Chisnall | 81e6858 | 2010-08-11 16:52:41 +0000 | [diff] [blame] | 327 | #ifdef ENOSTR |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 328 | not_a_stream = ENOSTR, |
David Chisnall | 81e6858 | 2010-08-11 16:52:41 +0000 | [diff] [blame] | 329 | #else |
| 330 | not_a_stream = EINVAL, |
| 331 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 332 | not_connected = ENOTCONN, |
| 333 | not_enough_memory = ENOMEM, |
| 334 | not_supported = ENOTSUP, |
| 335 | operation_canceled = ECANCELED, |
| 336 | operation_in_progress = EINPROGRESS, |
| 337 | operation_not_permitted = EPERM, |
| 338 | operation_not_supported = EOPNOTSUPP, |
| 339 | operation_would_block = EWOULDBLOCK, |
| 340 | owner_dead = EOWNERDEAD, |
| 341 | permission_denied = EACCES, |
| 342 | protocol_error = EPROTO, |
| 343 | protocol_not_supported = EPROTONOSUPPORT, |
| 344 | read_only_file_system = EROFS, |
| 345 | resource_deadlock_would_occur = EDEADLK, |
| 346 | resource_unavailable_try_again = EAGAIN, |
| 347 | result_out_of_range = ERANGE, |
| 348 | state_not_recoverable = ENOTRECOVERABLE, |
David Chisnall | 81e6858 | 2010-08-11 16:52:41 +0000 | [diff] [blame] | 349 | #ifdef ETIME |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 350 | stream_timeout = ETIME, |
David Chisnall | 81e6858 | 2010-08-11 16:52:41 +0000 | [diff] [blame] | 351 | #else |
| 352 | stream_timeout = ETIMEDOUT, |
| 353 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 354 | text_file_busy = ETXTBSY, |
| 355 | timed_out = ETIMEDOUT, |
| 356 | too_many_files_open_in_system = ENFILE, |
| 357 | too_many_files_open = EMFILE, |
| 358 | too_many_links = EMLINK, |
| 359 | too_many_symbolic_link_levels = ELOOP, |
| 360 | value_too_large = EOVERFLOW, |
| 361 | wrong_protocol_type = EPROTOTYPE |
| 362 | }; |
Howard Hinnant | f6d875f | 2011-12-02 19:36:40 +0000 | [diff] [blame] | 363 | _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(errc) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 364 | |
Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 365 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 366 | struct _LIBCPP_TYPE_VIS_ONLY is_error_condition_enum<errc> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 367 | : true_type { }; |
| 368 | |
Howard Hinnant | f6d875f | 2011-12-02 19:36:40 +0000 | [diff] [blame] | 369 | #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS |
Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 370 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 371 | struct _LIBCPP_TYPE_VIS_ONLY is_error_condition_enum<errc::__lx> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 372 | : true_type { }; |
Howard Hinnant | f6d875f | 2011-12-02 19:36:40 +0000 | [diff] [blame] | 373 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 374 | |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 375 | class _LIBCPP_TYPE_VIS error_condition; |
| 376 | class _LIBCPP_TYPE_VIS error_code; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 377 | |
| 378 | // class error_category |
| 379 | |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 380 | class _LIBCPP_HIDDEN __do_message; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 381 | |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 382 | class _LIBCPP_TYPE_VIS error_category |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 383 | { |
| 384 | public: |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 385 | virtual ~error_category() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 386 | |
Eric Fiselier | 4b07f98 | 2017-01-02 22:17:51 +0000 | [diff] [blame] | 387 | #if defined(_LIBCPP_BUILDING_SYSTEM_ERROR) && \ |
| 388 | defined(_LIBCPP_DEPRECATED_ABI_EXTERNAL_ERROR_CATEGORY_CONSTRUCTOR) |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 389 | error_category() _NOEXCEPT; |
Marshall Clow | 5c316a6 | 2013-08-21 02:57:19 +0000 | [diff] [blame] | 390 | #else |
Howard Hinnant | 8a1df3c | 2013-08-22 17:41:48 +0000 | [diff] [blame] | 391 | _LIBCPP_ALWAYS_INLINE |
Eric Fiselier | e2d4892 | 2015-08-28 07:02:42 +0000 | [diff] [blame] | 392 | _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT _LIBCPP_DEFAULT |
Marshall Clow | 5c316a6 | 2013-08-21 02:57:19 +0000 | [diff] [blame] | 393 | #endif |
Howard Hinnant | 9aa4e11 | 2012-03-21 16:18:57 +0000 | [diff] [blame] | 394 | private: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 395 | error_category(const error_category&);// = delete; |
| 396 | error_category& operator=(const error_category&);// = delete; |
| 397 | |
| 398 | public: |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 399 | virtual const char* name() const _NOEXCEPT = 0; |
| 400 | virtual error_condition default_error_condition(int __ev) const _NOEXCEPT; |
| 401 | virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT; |
| 402 | virtual bool equivalent(const error_code& __code, int __condition) const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 403 | virtual string message(int __ev) const = 0; |
| 404 | |
| 405 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 406 | bool operator==(const error_category& __rhs) const _NOEXCEPT {return this == &__rhs;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 407 | |
| 408 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 409 | bool operator!=(const error_category& __rhs) const _NOEXCEPT {return !(*this == __rhs);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 410 | |
| 411 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 412 | bool operator< (const error_category& __rhs) const _NOEXCEPT {return this < &__rhs;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 413 | |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 414 | friend class _LIBCPP_HIDDEN __do_message; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 415 | }; |
| 416 | |
| 417 | class _LIBCPP_HIDDEN __do_message |
| 418 | : public error_category |
| 419 | { |
| 420 | public: |
| 421 | virtual string message(int ev) const; |
| 422 | }; |
| 423 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 424 | _LIBCPP_FUNC_VIS const error_category& generic_category() _NOEXCEPT; |
| 425 | _LIBCPP_FUNC_VIS const error_category& system_category() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 426 | |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 427 | class _LIBCPP_TYPE_VIS error_condition |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 428 | { |
| 429 | int __val_; |
| 430 | const error_category* __cat_; |
| 431 | public: |
| 432 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 433 | error_condition() _NOEXCEPT : __val_(0), __cat_(&generic_category()) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 434 | |
| 435 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 436 | error_condition(int __val, const error_category& __cat) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 437 | : __val_(__val), __cat_(&__cat) {} |
| 438 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 439 | template <class _Ep> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 440 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 441 | error_condition(_Ep __e, |
| 442 | typename enable_if<is_error_condition_enum<_Ep>::value>::type* = 0 |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 443 | ) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 444 | {*this = make_error_condition(__e);} |
| 445 | |
| 446 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 447 | void assign(int __val, const error_category& __cat) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 448 | { |
| 449 | __val_ = __val; |
| 450 | __cat_ = &__cat; |
| 451 | } |
| 452 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 453 | template <class _Ep> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 454 | _LIBCPP_ALWAYS_INLINE |
| 455 | typename enable_if |
| 456 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 457 | is_error_condition_enum<_Ep>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 458 | error_condition& |
| 459 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 460 | operator=(_Ep __e) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 461 | {*this = make_error_condition(__e); return *this;} |
| 462 | |
| 463 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 464 | void clear() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 465 | { |
| 466 | __val_ = 0; |
| 467 | __cat_ = &generic_category(); |
| 468 | } |
| 469 | |
| 470 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 471 | int value() const _NOEXCEPT {return __val_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 472 | |
| 473 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 474 | const error_category& category() const _NOEXCEPT {return *__cat_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 475 | string message() const; |
| 476 | |
| 477 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 7786188 | 2012-02-21 21:46:43 +0000 | [diff] [blame] | 478 | _LIBCPP_EXPLICIT |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 479 | operator bool() const _NOEXCEPT {return __val_ != 0;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 480 | }; |
| 481 | |
| 482 | inline _LIBCPP_INLINE_VISIBILITY |
| 483 | error_condition |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 484 | make_error_condition(errc __e) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 485 | { |
| 486 | return error_condition(static_cast<int>(__e), generic_category()); |
| 487 | } |
| 488 | |
| 489 | inline _LIBCPP_INLINE_VISIBILITY |
| 490 | bool |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 491 | operator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 492 | { |
| 493 | return __x.category() < __y.category() |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 494 | || (__x.category() == __y.category() && __x.value() < __y.value()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | // error_code |
| 498 | |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 499 | class _LIBCPP_TYPE_VIS error_code |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 500 | { |
| 501 | int __val_; |
| 502 | const error_category* __cat_; |
| 503 | public: |
| 504 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 505 | error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 506 | |
| 507 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 508 | error_code(int __val, const error_category& __cat) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 509 | : __val_(__val), __cat_(&__cat) {} |
| 510 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 511 | template <class _Ep> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 512 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 513 | error_code(_Ep __e, |
| 514 | typename enable_if<is_error_code_enum<_Ep>::value>::type* = 0 |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 515 | ) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 516 | {*this = make_error_code(__e);} |
| 517 | |
| 518 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 519 | void assign(int __val, const error_category& __cat) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 520 | { |
| 521 | __val_ = __val; |
| 522 | __cat_ = &__cat; |
| 523 | } |
| 524 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 525 | template <class _Ep> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 526 | _LIBCPP_ALWAYS_INLINE |
| 527 | typename enable_if |
| 528 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 529 | is_error_code_enum<_Ep>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 530 | error_code& |
| 531 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 532 | operator=(_Ep __e) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 533 | {*this = make_error_code(__e); return *this;} |
| 534 | |
| 535 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 536 | void clear() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 537 | { |
| 538 | __val_ = 0; |
| 539 | __cat_ = &system_category(); |
| 540 | } |
| 541 | |
| 542 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 543 | int value() const _NOEXCEPT {return __val_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 544 | |
| 545 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 546 | const error_category& category() const _NOEXCEPT {return *__cat_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 547 | |
| 548 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 549 | error_condition default_error_condition() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 550 | {return __cat_->default_error_condition(__val_);} |
| 551 | |
| 552 | string message() const; |
| 553 | |
| 554 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 7786188 | 2012-02-21 21:46:43 +0000 | [diff] [blame] | 555 | _LIBCPP_EXPLICIT |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 556 | operator bool() const _NOEXCEPT {return __val_ != 0;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 557 | }; |
| 558 | |
| 559 | inline _LIBCPP_INLINE_VISIBILITY |
| 560 | error_code |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 561 | make_error_code(errc __e) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 562 | { |
| 563 | return error_code(static_cast<int>(__e), generic_category()); |
| 564 | } |
| 565 | |
| 566 | inline _LIBCPP_INLINE_VISIBILITY |
| 567 | bool |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 568 | operator<(const error_code& __x, const error_code& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 569 | { |
| 570 | return __x.category() < __y.category() |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 571 | || (__x.category() == __y.category() && __x.value() < __y.value()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | inline _LIBCPP_INLINE_VISIBILITY |
| 575 | bool |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 576 | operator==(const error_code& __x, const error_code& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 577 | { |
| 578 | return __x.category() == __y.category() && __x.value() == __y.value(); |
| 579 | } |
| 580 | |
| 581 | inline _LIBCPP_INLINE_VISIBILITY |
| 582 | bool |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 583 | operator==(const error_code& __x, const error_condition& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 584 | { |
| 585 | return __x.category().equivalent(__x.value(), __y) |
| 586 | || __y.category().equivalent(__x, __y.value()); |
| 587 | } |
| 588 | |
| 589 | inline _LIBCPP_INLINE_VISIBILITY |
| 590 | bool |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 591 | operator==(const error_condition& __x, const error_code& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 592 | { |
| 593 | return __y == __x; |
| 594 | } |
| 595 | |
| 596 | inline _LIBCPP_INLINE_VISIBILITY |
| 597 | bool |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 598 | operator==(const error_condition& __x, const error_condition& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 599 | { |
| 600 | return __x.category() == __y.category() && __x.value() == __y.value(); |
| 601 | } |
| 602 | |
| 603 | inline _LIBCPP_INLINE_VISIBILITY |
| 604 | bool |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 605 | operator!=(const error_code& __x, const error_code& __y) _NOEXCEPT |
| 606 | {return !(__x == __y);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 607 | |
| 608 | inline _LIBCPP_INLINE_VISIBILITY |
| 609 | bool |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 610 | operator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT |
| 611 | {return !(__x == __y);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 612 | |
| 613 | inline _LIBCPP_INLINE_VISIBILITY |
| 614 | bool |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 615 | operator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT |
| 616 | {return !(__x == __y);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 617 | |
| 618 | inline _LIBCPP_INLINE_VISIBILITY |
| 619 | bool |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 620 | operator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT |
| 621 | {return !(__x == __y);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 622 | |
| 623 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 624 | struct _LIBCPP_TYPE_VIS_ONLY hash<error_code> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 625 | : public unary_function<error_code, size_t> |
| 626 | { |
Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 627 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 628 | size_t operator()(const error_code& __ec) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 629 | { |
| 630 | return static_cast<size_t>(__ec.value()); |
| 631 | } |
| 632 | }; |
| 633 | |
Marshall Clow | db7fa11 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 634 | template <> |
| 635 | struct _LIBCPP_TYPE_VIS_ONLY hash<error_condition> |
| 636 | : public unary_function<error_condition, size_t> |
| 637 | { |
| 638 | _LIBCPP_INLINE_VISIBILITY |
| 639 | size_t operator()(const error_condition& __ec) const _NOEXCEPT |
| 640 | { |
| 641 | return static_cast<size_t>(__ec.value()); |
| 642 | } |
| 643 | }; |
| 644 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 645 | // system_error |
| 646 | |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 647 | class _LIBCPP_TYPE_VIS system_error |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 648 | : public runtime_error |
| 649 | { |
| 650 | error_code __ec_; |
| 651 | public: |
| 652 | system_error(error_code __ec, const string& __what_arg); |
| 653 | system_error(error_code __ec, const char* __what_arg); |
| 654 | system_error(error_code __ec); |
| 655 | system_error(int __ev, const error_category& __ecat, const string& __what_arg); |
| 656 | system_error(int __ev, const error_category& __ecat, const char* __what_arg); |
| 657 | system_error(int __ev, const error_category& __ecat); |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 658 | ~system_error() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 659 | |
| 660 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 1e15fd1 | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 661 | const error_code& code() const _NOEXCEPT {return __ec_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 662 | |
| 663 | private: |
| 664 | static string __init(const error_code&, string); |
| 665 | }; |
| 666 | |
Aditya Kumar | 5db6737 | 2016-08-27 02:26:42 +0000 | [diff] [blame] | 667 | _LIBCPP_NORETURN _LIBCPP_FUNC_VIS |
| 668 | void __throw_system_error(int ev, const char* what_arg); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 669 | |
| 670 | _LIBCPP_END_NAMESPACE_STD |
| 671 | |
| 672 | #endif // _LIBCPP_SYSTEM_ERROR |