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