1//// 2Copyright 2003-2017 Beman Dawes 3Copyright 2018 Peter Dimov 4 5Distributed under the Boost Software License, Version 1.0. 6 7See accompanying file LICENSE_1_0.txt or copy at 8http://www.boost.org/LICENSE_1_0.txt 9//// 10 11[#reference] 12# Reference 13:idprefix: ref_ 14 15## Use of {cpp}11 and {cpp}14 Features 16 17The library is documented to use several {cpp}11 and {cpp}14 features, 18including `noexcept`, explicit conversion operators and `constexpr`. The 19actual implementation uses {cpp}11 and {cpp}14 features only when they are 20available, and otherwise falls back on {cpp}03 features. 21 22## Macros 23 24When `BOOST_SYSTEM_ENABLE_DEPRECATED` is defined, the library provides 25deprecated features for compatibility. These features are bound to eventually 26disappear. 27 28When `BOOST_SYSTEM_USE_UTF8` is defined, on Windows the library returns 29UTF-8 messages using code page `CP_UTF8` instead of the default `CP_ACP`. 30This macro has no effect on POSIX. 31 32## Deprecated Names 33 34In the process of adding Boost.System to the {cpp}11 standard library, the 35{cpp} committee changed some names. To ease transition, Boost.System deprecates 36the old names, but will provide them when the macro `BOOST_SYSTEM_ENABLE_DEPRECATED` is defined. 37 38|=== 39|Old usage, now deprecated|Replacement 40 41|`get_generic_category()`|`generic_category()` 42|`get_system_category()`|`system_category()` 43|`namespace posix`|`namespace errc` 44|`namespace posix_error`|`namespace errc` 45|`get_posix_category()`|`generic_category()` 46|`posix_category`|`generic_category()` 47|`errno_ecat`|`generic_category()` 48|`native_ecat`|`system_category()` 49|=== 50 51## <boost/system/error_code.hpp> 52 53### Synopsis 54 55``` 56namespace boost { 57 namespace system { 58 59 class error_category; 60 61 constexpr const error_category & system_category() noexcept; 62 constexpr const error_category & generic_category() noexcept; 63 64 class error_code; 65 class error_condition; 66 67 // "Concept" helpers 68 69 template<class T> 70 struct is_error_code_enum { static const bool value = false; }; 71 72 template<class T> 73 struct is_error_condition_enum { static const bool value = false; }; 74 75 // generic error conditions 76 77 namespace errc { 78 enum errc_t 79 { 80 success = 0, 81 address_family_not_supported, //EAFNOSUPPORT 82 address_in_use, //EADDRINUSE 83 address_not_available, //EADDRNOTAVAIL 84 already_connected, //EISCONN 85 argument_list_too_long, //E2BIG 86 argument_out_of_domain, //EDOM 87 bad_address, //EFAULT 88 bad_file_descriptor, //EBADF 89 bad_message, //EBADMSG 90 broken_pipe, //EPIPE 91 connection_aborted, //ECONNABORTED 92 connection_already_in_progress, //EALREADY 93 connection_refused, //ECONNREFUSED 94 connection_reset, //ECONNRESET 95 cross_device_link, //EXDEV 96 destination_address_required, //EDESTADDRREQ 97 device_or_resource_busy, //EBUSY 98 directory_not_empty, //ENOTEMPTY 99 executable_format_error, //ENOEXEC 100 file_exists, //EEXIST 101 file_too_large, //EFBIG 102 filename_too_long, //ENAMETOOLONG 103 function_not_supported, //ENOSYS 104 host_unreachable, //EHOSTUNREACH 105 identifier_removed, //EIDRM 106 illegal_byte_sequence, //EILSEQ 107 inappropriate_io_control_operation, //ENOTTY 108 interrupted, //EINTR 109 invalid_argument, //EINVAL 110 invalid_seek, //ESPIPE 111 io_error, //EIO 112 is_a_directory, //EISDIR 113 message_size, //EMSGSIZE 114 network_down, //ENETDOWN 115 network_reset, //ENETRESET 116 network_unreachable, //ENETUNREACH 117 no_buffer_space, //ENOBUFS 118 no_child_process, //ECHILD 119 no_link, //ENOLINK 120 no_lock_available, //ENOLCK 121 no_message_available, //ENODATA 122 no_message, //ENOMSG 123 no_protocol_option, //ENOPROTOOPT 124 no_space_on_device, //ENOSPC 125 no_stream_resources, //ENOSR 126 no_such_device_or_address, //ENXIO 127 no_such_device, //ENODEV 128 no_such_file_or_directory, //ENOENT 129 no_such_process, //ESRCH 130 not_a_directory, //ENOTDIR 131 not_a_socket, //ENOTSOCK 132 not_a_stream, //ENOSTR 133 not_connected, //ENOTCONN 134 not_enough_memory, //ENOMEM 135 not_supported, //ENOTSUP 136 operation_canceled, //ECANCELED 137 operation_in_progress, //EINPROGRESS 138 operation_not_permitted, //EPERM 139 operation_not_supported, //EOPNOTSUPP 140 operation_would_block, //EWOULDBLOCK 141 owner_dead, //EOWNERDEAD 142 permission_denied, //EACCES 143 protocol_error, //EPROTO 144 protocol_not_supported, //EPROTONOSUPPORT 145 read_only_file_system, //EROFS 146 resource_deadlock_would_occur, //EDEADLK 147 resource_unavailable_try_again, //EAGAIN 148 result_out_of_range, //ERANGE 149 state_not_recoverable, //ENOTRECOVERABLE 150 stream_timeout, //ETIME 151 text_file_busy, //ETXTBSY 152 timed_out, //ETIMEDOUT 153 too_many_files_open_in_system, //ENFILE 154 too_many_files_open, //EMFILE 155 too_many_links, //EMLINK 156 too_many_synbolic_link_levels, //ELOOP 157 value_too_large, //EOVERFLOW 158 wrong_protocol_type //EPROTOTYPE 159 }; 160 161 } // namespace errc 162 163 template<> struct is_error_condition_enum<errc::errc_t> 164 { static const bool value = true; }; 165 166 // non-member functions 167 168 constexpr bool operator==( const error_code & lhs, 169 const error_code & rhs ) noexcept; 170 bool operator==( const error_code & code, 171 const error_condition & condition ) noexcept; 172 bool operator==( const error_condition & condition, 173 const error_code & code ) noexcept; 174 constexpr bool operator==( const error_condition & lhs, 175 const error_condition & rhs ) noexcept; 176 177 constexpr bool operator!=( const error_code & lhs, 178 const error_code & rhs ) noexcept; 179 bool operator!=( const error_code & code, 180 const error_condition & condition ) noexcept; 181 bool operator!=( const error_condition & condition, 182 const error_code & code ) noexcept; 183 constexpr bool operator!=( const error_condition & lhs, 184 const error_condition & rhs ) noexcept; 185 186 constexpr bool operator<( const error_code & lhs, 187 const error_code & rhs ) noexcept; 188 constexpr bool operator<( const error_condition & lhs, 189 const error_condition & rhs ) noexcept; 190 191 constexpr error_code make_error_code( errc::errc_t e ) noexcept; 192 constexpr error_condition make_error_condition( errc::errc_t e ) noexcept; 193 194 template <class charT, class traits> 195 std::basic_ostream<charT, traits>& 196 operator<<( basic_ostream<charT, traits>& os, const error_code & ec ); 197 198 std::size_t hash_value( const error_code & ec ); 199 200 } // namespace system 201} // namespace boost 202``` 203 204The value of each `errc_t` constant is the same as the value of the `<cerrno>` 205macro shown in the above synopsis. 206 207Users may specialize `is_error_code_enum` and `is_error_condition_enum` 208templates to indicate that a type is eligible for class `error_code` and 209`error_condition` automatic conversions respectively. 210 211### Class error_category 212 213The class `error_category` defines the base class for types used 214to identify the source and encoding of a particular category of error code. 215 216Classes may be derived from `error_category` to support categories of 217errors in addition to those defined in Boost.System. 218 219``` 220namespace boost { 221 namespace system { 222 223 class error_category 224 { 225 public: // noncopyable 226 227 error_category( error_category const & ) = delete; 228 error_category& operator=( error_category const & ) = delete; 229 230 protected: 231 232 ~error_category() = default; 233 234 constexpr error_category() noexcept; 235 explicit constexpr error_category( unsigned long long id ) noexcept; 236 237 public: 238 239 virtual const char * name() const noexcept = 0; 240 241 virtual error_condition default_error_condition( int ev ) const noexcept; 242 243 virtual bool equivalent( int code, const error_condition & condition ) 244 const noexcept; 245 virtual bool equivalent( const error_code & code, int condition ) 246 const noexcept; 247 248 virtual std::string message( int ev ) const = 0; 249 virtual char const * message( int ev, char * buffer, std::size_t len ) 250 const noexcept; 251 252 virtual bool failed( int ev ) const noexcept; 253 254 constexpr bool operator==( const error_category & rhs ) const noexcept; 255 constexpr bool operator!=( const error_category & rhs ) const noexcept; 256 constexpr bool operator< ( const error_category & rhs ) const noexcept; 257 258 operator std::error_category const & () const; 259 260 private: 261 262 unsigned long long id_; // exposition only 263 264 }; 265 } 266} 267``` 268 269#### Constructors 270 271``` 272constexpr error_category() noexcept; 273``` 274[none] 275* {blank} 276+ 277Effects: :: Initializes `id_` to 0. 278Remarks: :: Since equivalence for categories that do not have an identifier is 279 based on comparing object addresses, a user-defined derived category of type 280 `C` that uses this constructor should ensure that only one object of type `C` 281 exists in the program. 282 283``` 284explicit constexpr error_category( unsigned long long id ) noexcept; 285``` 286[none] 287* {blank} 288+ 289Effects: :: Initializes `id_` to `id`. 290Remarks: :: User-defined derived categories that use this constructor are considered 291 equivalent when their identifiers match. Therefore, those categories may have more 292 than one instance existing in a program, but to minimize the possibility of 293 collision, their identifiers must be randomly chosen (at the time the category 294 is implemented, not at runtime). One way of generating a 64 bit random identifier 295 is https://www.random.org/cgi-bin/randbyte?nbytes=8&format=h. 296 297#### Virtuals 298 299``` 300virtual const char * name() const noexcept = 0; 301``` 302[none] 303* {blank} 304+ 305Returns: :: In derived classes, a character literal naming the error category. 306 307``` 308virtual error_condition default_error_condition( int ev ) const noexcept; 309``` 310[none] 311* {blank} 312+ 313Returns: :: 314- In derived classes, an error condition corresponding to `ev`. 315 The returned error condition will typically come from the generic category. 316- In the default implementation, `error_condition( ev, *this )`. 317 318``` 319virtual bool equivalent( int code, const error_condition & condition ) 320 const noexcept; 321``` 322[none] 323* {blank} 324+ 325Returns: :: 326- In derived classes, `true` when `error_code( code, *this )` is equivalent to `condition`. 327- In the default implementation, `default_error_condition( code ) == condition`. 328 329``` 330virtual bool equivalent( const error_code & code, int condition ) 331 const noexcept; 332``` 333[none] 334* {blank} 335+ 336Returns: :: 337- In derived classes, `true` when `code` is equivalent to `error_condition( condition, *this )`. 338- In the default implementation, `*this == code.category() && code.value() == condition`. 339 340``` 341virtual std::string message( int ev ) const = 0; 342``` 343[none] 344* {blank} 345+ 346Returns: :: In derived classes, a string that describes the error denoted by `ev`. 347 348``` 349virtual char const * message( int ev, char * buffer, std::size_t len ) 350 const noexcept; 351``` 352[none] 353* {blank} 354+ 355Effects: :: 356** Derived classes should either 357 *** return a pointer to a character literal describing the error denoted by `ev`, or 358 *** copy a string describing the error into `buffer`, truncating it to `len-1` 359 characters and storing a null terminator, and return `buffer`. If `len` is 0, 360 nothing is copied, but the function still returns `buffer`. Note that 361 when `len` is 0, `buffer` may be `nullptr`. 362** The default implementation calls `message(ev)` and copies the result into 363 `buffer`, truncating it to `len-1` characters and storing a null terminator. 364 If `len` is 0, copies nothing. Returns `buffer`. If `message(ev)` throws an 365 exception, the string `"Message text unavailable"` is used. 366Example: :: 367+ 368``` 369const char* my_category::message(int ev, char* buffer, size_t len) const noexcept 370{ 371 switch(ev) 372 { 373 case 0: return "no error"; 374 case 1: return "voltage out of range"; 375 case 2: return "impedance mismatch"; 376 case 31: 377 case 32: 378 case 33: 379 std::snprintf(buffer, len, "component %d failure", ev-30); 380 return buffer; 381 default: 382 std::snprintf(buffer, len, "unknown error %d", ev); 383 return buffer; 384 } 385} 386``` 387 388``` 389virtual bool failed( int ev ) const noexcept; 390``` 391[none] 392* {blank} 393+ 394Returns: :: 395- In derived classes, `true` when `ev` represents a failure. 396- In the default implementation, `ev != 0`. 397Remarks: :: 398 All calls to this function with the same `ev` must return the same value. 399 400#### Nonvirtuals 401 402``` 403constexpr bool operator==( const error_category & rhs ) const noexcept; 404``` 405[none] 406* {blank} 407+ 408Returns: :: `rhs.id_ == 0? this == &rhs: id_ == rhs.id_`. 409Remarks: :: Two category objects are considered equivalent when they have matching 410 nonzero identifiers, or are the same object. 411 412``` 413constexpr bool operator!=( const error_category & rhs ) const noexcept; 414``` 415[none] 416* {blank} 417+ 418Returns: :: `!( *this == rhs )`. 419 420``` 421constexpr bool operator< ( const error_category & rhs ) const noexcept; 422``` 423[none] 424* {blank} 425+ 426Returns: :: 427** If `id_ < rhs.id_`, `true`; 428** Otherwise, if `id_ > rhs.id_`, `false`; 429** Otherwise, if `rhs.id_ != 0`, `false`; 430** Otherwise, `std::less<error_category const *>()( this, &rhs )`. 431 432``` 433operator std::error_category const & () const; 434``` 435[none] 436* {blank} 437+ 438Returns: :: A reference to an `std::error_category` object corresponding 439 to `*this`. 440 441### Predefined Categories 442 443``` 444constexpr const error_category & system_category() noexcept; 445``` 446[none] 447* {blank} 448+ 449Returns: :: A reference to an `error_category` object identifying errors 450 originating from the operating system. 451 452``` 453constexpr const error_category & generic_category() noexcept; 454``` 455[none] 456* {blank} 457+ 458Returns: :: A reference to an `error_category` object identifying portable 459 error conditions. 460 461### Class error_code 462 463The class `error_code` describes an object used to hold error code 464values, such as those originating from the operating system or other 465low-level application program interfaces. It's an adjunct to error reporting 466by exception. 467 468``` 469namespace boost { 470 namespace system { 471 472 class error_code { 473 public: 474 475 // constructors: 476 477 constexpr error_code() noexcept; 478 constexpr error_code( int val, const error_category & cat ) noexcept; 479 480 template <class ErrorCodeEnum> 481 constexpr error_code( ErrorCodeEnum e ) noexcept; 482 483 // modifiers: 484 485 constexpr void assign( int val, const error_category & cat ) noexcept; 486 487 template<typename ErrorCodeEnum> 488 constexpr error_code & operator=( ErrorCodeEnum e ) noexcept; 489 490 constexpr void clear() noexcept; 491 492 // observers: 493 494 constexpr int value() const noexcept; 495 constexpr const error_category & category() const noexcept; 496 497 error_condition default_error_condition() const noexcept; 498 499 std::string message() const; 500 char const * message( char * buffer, std::size_t len ) const noexcept; 501 502 constexpr bool failed() const noexcept; 503 constexpr explicit operator bool() const noexcept; 504 505 operator std::error_code() const; 506 507 private: // exposition only 508 509 int val_; 510 const error_category * cat_; 511 512 }; 513 } 514} 515``` 516 517#### Constructors 518 519``` 520constexpr error_code() noexcept; 521``` 522[none] 523* {blank} 524+ 525Ensures: :: `val_ == 0`; `*cat_ == system_category()`. 526 527``` 528constexpr error_code( int val, const error_category & cat ) noexcept; 529``` 530[none] 531* {blank} 532+ 533Ensures: :: `val_ == val`; `cat_ == &cat`. 534 535``` 536template <class ErrorCodeEnum> 537 constexpr error_code( ErrorCodeEnum e ) noexcept; 538``` 539[none] 540* {blank} 541+ 542Ensures: :: `*this == make_error_code( e )`. 543Remarks: :: This constructor is only enabled when `is_error_code_enum<ErrorCodeEnum>::value` is `true`. 544 545#### Modifiers 546 547``` 548constexpr void assign( int val, const error_category & cat ) noexcept; 549``` 550[none] 551* {blank} 552+ 553Ensures: :: `val_ == val`; `cat_ == &cat`. 554 555``` 556template<typename ErrorCodeEnum> 557 constexpr error_code & operator=( ErrorCodeEnum e ) noexcept; 558``` 559[none] 560* {blank} 561+ 562Ensures: :: `*this == make_error_code( e )`. 563Remarks: :: This operator is only enabled when `is_error_code_enum<ErrorCodeEnum>::value` is `true`. 564 565``` 566constexpr void clear() noexcept; 567``` 568[none] 569* {blank} 570+ 571Ensures: :: 572 `val_ == 0`; `*cat_ == system_category()`. 573 574#### Observers 575 576``` 577constexpr int value() const noexcept; 578``` 579[none] 580* {blank} 581+ 582Returns: :: `val_`. 583 584``` 585constexpr const error_category & category() const noexcept; 586``` 587[none] 588* {blank} 589+ 590Returns: :: `*cat_`. 591 592``` 593error_condition default_error_condition() const noexcept; 594``` 595[none] 596* {blank} 597+ 598Returns: :: `cat_\->default_error_condition( val_ )`. 599 600``` 601std::string message() const; 602``` 603[none] 604* {blank} 605+ 606Returns: :: `cat_\->message( val_ )`. 607 608``` 609char const * message( char * buffer, std::size_t len ) const noexcept; 610``` 611[none] 612* {blank} 613+ 614Returns: :: `cat_\->message( val_, buffer, len )`. 615 616``` 617constexpr bool failed() const noexcept; 618``` 619[none] 620* {blank} 621+ 622Returns: :: `cat_\->failed( val_ )`. 623 624``` 625constexpr explicit operator bool() const noexcept; 626``` 627[none] 628* {blank} 629+ 630Returns: :: `failed()`. 631 632``` 633operator std::error_code() const; 634``` 635[none] 636* {blank} 637+ 638Returns: :: 639 `std::error_code( val_, *cat_ )`. 640 641### Class error_condition 642 643``` 644namespace boost { 645 namespace system { 646 647 class error_condition { 648 public: 649 650 // constructors: 651 652 constexpr error_condition() noexcept; 653 constexpr error_condition( int val, const error_category & cat ) noexcept; 654 655 template <class ErrorConditionEnum> 656 constexpr error_condition( ErrorConditionEnum e ) noexcept; 657 658 // modifiers: 659 660 constexpr void assign( int val, const error_category & cat ) noexcept; 661 662 template<typename ErrorConditionEnum> 663 constexpr error_condition & operator=( ErrorConditionEnum e ) noexcept; 664 665 constexpr void clear() noexcept; 666 667 // observers: 668 669 constexpr int value() const noexcept; 670 constexpr const error_category & category() const noexcept; 671 672 std::string message() const; 673 674 constexpr explicit operator bool() const noexcept; 675 676 operator std::error_condition() const; 677 678 // deprecated members; do not use 679 680 char const * message( char * buffer, std::size_t len ) const noexcept; 681 constexpr bool failed() const noexcept; 682 683 private: // exposition only 684 685 int val_; 686 const error_category * cat_; 687 688 }; 689 } 690} 691``` 692 693#### Constructors 694 695``` 696constexpr error_condition() noexcept; 697``` 698[none] 699* {blank} 700+ 701Ensures: :: `val_ == 0`; `*cat_ == generic_category()`. 702 703``` 704constexpr error_condition( int val, const error_category & cat ) noexcept; 705``` 706[none] 707* {blank} 708+ 709Ensures: :: `val_ == val`; `cat_ == &cat`. 710 711``` 712template <class ErrorConditionEnum> 713 constexpr error_condition( ErrorConditionEnum e ) noexcept; 714``` 715[none] 716* {blank} 717+ 718Ensures: :: `*this == make_error_condition( e )`. 719Remarks: :: 720 This constructor is only enabled when `is_error_condition_enum<ErrorConditionEnum>::value` is `true`. 721 722#### Modifiers 723 724``` 725constexpr void assign( int val, const error_category & cat ) noexcept; 726``` 727[none] 728* {blank} 729+ 730Ensures: :: `val_ == val`; `cat_ == &cat`. 731 732``` 733template <class ErrorConditionEnum> 734 constexpr error_condition & operator=( ErrorConditionEnum e ) noexcept; 735``` 736[none] 737* {blank} 738+ 739Ensures: :: `*this == make_error_condition( e )`. 740Remarks: :: This operator is only enabled when `is_error_condition_enum<ErrorConditionEnum>::value` is `true`. 741 742``` 743constexpr void clear() noexcept; 744``` 745[none] 746* {blank} 747+ 748Ensures: :: 749 `val_ == 0`; `*cat_ == generic_category()`. 750 751#### Observers 752 753``` 754constexpr int value() const noexcept; 755``` 756[none] 757* {blank} 758+ 759Returns: :: `val_`. 760 761``` 762constexpr const error_category & category() const noexcept; 763``` 764[none] 765* {blank} 766+ 767Returns: :: `*cat_`. 768 769``` 770std::string message() const; 771``` 772[none] 773* {blank} 774+ 775Returns: :: `cat_\->message( val_ )`. 776 777``` 778constexpr explicit operator bool() const noexcept; 779``` 780[none] 781* {blank} 782+ 783Returns: :: `value() != 0`. 784 785``` 786operator std::error_condition() const; 787``` 788[none] 789* {blank} 790+ 791Returns: :: 792 `std::error_condition( val_, *cat_ )`. 793 794#### Deprecated members 795 796``` 797char const * message( char * buffer, std::size_t len ) const noexcept; 798``` 799[none] 800* {blank} 801+ 802Returns: :: `cat_\->message( val_, buffer, len )`. 803 804WARNING: This member function is deprecated and will be removed. This is done 805 for compatibility with `std::error_condition` as the next release is 806 expected to improve interoperability with `<system_error>` even further. 807 _Note that this does not affect_ `error_code::message`. 808 809``` 810constexpr bool failed() const noexcept; 811``` 812[none] 813* {blank} 814+ 815Returns: :: `cat_\->failed( val_ )`. 816 817WARNING: This member function is deprecated and will be removed. This is done 818 for compatibility with `std::error_condition` as the next release is 819 expected to improve interoperability with `<system_error>` even further. 820 _Note that this does not affect_ `error_code::failed`. 821 822### Nonmember functions 823 824``` 825constexpr bool operator==( const error_code & lhs, 826 const error_code & rhs ) noexcept; 827constexpr bool operator==( const error_condition & lhs, 828 const error_condition & rhs ) noexcept; 829``` 830[none] 831* {blank} 832+ 833Returns: :: `lhs.value() == rhs.value() && lhs.category() == rhs.category()`. 834 835``` 836bool operator==( const error_code & code, 837 const error_condition & condition ) noexcept; 838bool operator==( const error_condition & condition, 839 const error_code & code ) noexcept; 840``` 841[none] 842* {blank} 843+ 844Returns: :: `code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() )`. 845 846``` 847constexpr bool operator!=( const error_code & lhs, 848 const error_code & rhs ) noexcept; 849constexpr bool operator!=( const error_condition & lhs, 850 const error_condition & rhs ) noexcept; 851bool operator!=( const error_code & code, 852 const error_condition & condition ) noexcept; 853bool operator!=( const error_condition & condition, 854 const error_code & code ) noexcept; 855``` 856[none] 857* {blank} 858+ 859Returns: :: `!( lhs == rhs )`. 860 861``` 862constexpr bool operator<( const error_code & lhs, 863 const error_code & rhs ) noexcept; 864constexpr bool operator<( const error_condition & lhs, 865 const error_condition & rhs ) noexcept; 866``` 867[none] 868* {blank} 869+ 870Returns: :: `lhs.category() < rhs.category() || ( lhs.category() == rhs.category() && lhs.value() < rhs.value() )`. 871 872``` 873constexpr error_code make_error_code( errc::errc_t e ) noexcept; 874``` 875[none] 876* {blank} 877+ 878Returns: :: `error_code( e, generic_category() )`. 879 880``` 881constexpr error_condition make_error_condition( errc::errc_t e ) noexcept; 882``` 883[none] 884* {blank} 885+ 886Returns: :: `error_condition( e, generic_category() )`. 887 888``` 889template <class charT, class traits> 890 std::basic_ostream<charT, traits>& 891 operator<<( basic_ostream<charT, traits>& os, const error_code & ec ); 892``` 893[none] 894* {blank} 895+ 896Effects: :: `os << ec.category().name() << ':' << ec.value()`. 897Returns: :: `os`. 898 899``` 900std::size_t hash_value( const error_code & ec ); 901``` 902[none] 903* {blank} 904+ 905Returns: :: 906 A hash value representing `ec`. 907 908## <boost/system/system_error.hpp> 909 910### Class system_error 911 912The class `system_error` describes an exception object used to 913report errors that have an associated `error_code`. Such errors 914typically originate from operating system or other low-level 915application program interfaces. 916 917``` 918namespace boost 919{ 920 namespace system 921 { 922 class system_error: public std::runtime_error 923 { 924 public: 925 926 explicit system_error( error_code ec ); 927 system_error( error_code ec, const char * what_arg ); 928 system_error( error_code ec, const std::string & what_arg ); 929 930 system_error( int ev, const error_category & ecat ); 931 system_error( int ev, const error_category & ecat, 932 const char * what_arg ); 933 system_error( int ev, const error_category & ecat, 934 const std::string & what_arg ); 935 936 error_code code() const noexcept; 937 const char * what() const noexcept; 938 }; 939 } 940} 941``` 942 943#### Constructors 944 945``` 946explicit system_error( error_code ec ); 947system_error( error_code ec, const char * what_arg ); 948system_error( error_code ec, const std::string & what_arg ); 949``` 950[none] 951* {blank} 952+ 953Ensures: :: `code() == ec`. 954 955``` 956system_error( int ev, const error_category & ecat, 957 const char * what_arg ); 958system_error( int ev, const error_category & ecat, 959 const std::string & what_arg ); 960system_error( int ev, const error_category & ecat ); 961``` 962[none] 963* {blank} 964+ 965Ensures: :: 966 `code() == error_code( ev, ecat )`. 967 968#### Observers 969 970``` 971error_code code() const noexcept; 972``` 973[none] 974* {blank} 975+ 976Returns: :: `ec` or `error_code( ev, ecat )`, from the constructor, as appropriate. 977 978``` 979const char * what() const noexcept; 980``` 981[none] 982* {blank} 983+ 984Returns: :: A null-terminated character string incorporating the arguments supplied 985 in the constructor, typically of the form `what_arg + ": " + code.message()`. 986