From Jason Turner

[syserr]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpwmzlqgtw/{from.md → to.md} +106 -166
tmp/tmpwmzlqgtw/{from.md → to.md} RENAMED
@@ -1,18 +1,20 @@
1
  ## System error support <a id="syserr">[[syserr]]</a>
2
 
3
- This subclause describes components that the standard library and
4
- C++programs may use to report error conditions originating from the
5
  operating system or other low-level application program interfaces.
6
 
7
  Components described in this subclause shall not change the value of
8
- `errno` ([[errno]]). Implementations should leave the error states
9
  provided by other libraries unchanged.
10
 
11
- ### Header `<system_error>` synopsis <a id="system_error.syn">[[system_error.syn]]</a>
12
 
13
  ``` cpp
 
 
14
  namespace std {
15
  class error_category;
16
  const error_category& generic_category() noexcept;
17
  const error_category& system_category() noexcept;
18
 
@@ -118,53 +120,48 @@ namespace std {
118
 
119
  // [syserr.errcondition.nonmembers], non-member functions
120
  error_condition make_error_condition(errc e) noexcept;
121
 
122
  // [syserr.compare], comparison functions
123
- bool operator<(const error_code& lhs, const error_code& rhs) noexcept;
124
- bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
125
  bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
126
  bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
127
- bool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
128
  bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
129
- bool operator!=(const error_code& lhs, const error_code& rhs) noexcept;
130
- bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
131
- bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
132
- bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
133
 
134
  // [syserr.hash], hash support
135
  template<class T> struct hash;
136
  template<> struct hash<error_code>;
137
  template<> struct hash<error_condition>;
138
 
139
  // [syserr], system error support
140
- template <class T> inline constexpr bool is_error_code_enum_v
141
- = is_error_code_enum<T>::value;
142
- template <class T> inline constexpr bool is_error_condition_enum_v
143
- = is_error_condition_enum<T>::value;
144
  }
145
  ```
146
 
147
  The value of each `enum errc` constant shall be the same as the value of
148
  the `<cerrno>` macro shown in the above synopsis. Whether or not the
149
  `<system_error>` implementation exposes the `<cerrno>` macros is
150
  unspecified.
151
 
152
  The `is_error_code_enum` and `is_error_condition_enum` may be
153
- specialized for user-defined types to indicate that such types are
154
  eligible for `class error_code` and `class error_condition` automatic
155
  conversions, respectively.
156
 
157
  ### Class `error_category` <a id="syserr.errcat">[[syserr.errcat]]</a>
158
 
159
- #### Class `error_category` overview <a id="syserr.errcat.overview">[[syserr.errcat.overview]]</a>
160
 
161
  The class `error_category` serves as a base class for types used to
162
  identify the source and encoding of a particular category of error code.
163
  Classes may be derived from `error_category` to support categories of
164
- errors in addition to those defined in this International Standard. Such
165
- classes shall behave as specified in this subclause.
166
 
167
  [*Note 1*: `error_category` objects are passed by reference, and two
168
  such objects are equal if they have the same address. This means that
169
  applications using custom `error_category` types should create a single
170
  object of each such type. — *end note*]
@@ -182,26 +179,19 @@ namespace std {
182
  virtual bool equivalent(int code, const error_condition& condition) const noexcept;
183
  virtual bool equivalent(const error_code& code, int condition) const noexcept;
184
  virtual string message(int ev) const = 0;
185
 
186
  bool operator==(const error_category& rhs) const noexcept;
187
- bool operator!=(const error_category& rhs) const noexcept;
188
- bool operator<(const error_category& rhs) const noexcept;
189
  };
190
 
191
  const error_category& generic_category() noexcept;
192
  const error_category& system_category() noexcept;
193
  }
194
  ```
195
 
196
- #### Class `error_category` virtual members <a id="syserr.errcat.virtuals">[[syserr.errcat.virtuals]]</a>
197
-
198
- ``` cpp
199
- virtual ~error_category();
200
- ```
201
-
202
- *Effects:* Destroys an object of class `error_category`.
203
 
204
  ``` cpp
205
  virtual const char* name() const noexcept = 0;
206
  ```
207
 
@@ -229,40 +219,28 @@ virtual bool equivalent(const error_code& code, int condition) const noexcept;
229
  virtual string message(int ev) const = 0;
230
  ```
231
 
232
  *Returns:* A string that describes the error condition denoted by `ev`.
233
 
234
- #### Class `error_category` non-virtual members <a id="syserr.errcat.nonvirtuals">[[syserr.errcat.nonvirtuals]]</a>
235
-
236
- ``` cpp
237
- constexpr error_category() noexcept;
238
- ```
239
-
240
- *Effects:* Constructs an object of class `error_category`.
241
 
242
  ``` cpp
243
  bool operator==(const error_category& rhs) const noexcept;
244
  ```
245
 
246
  *Returns:* `this == &rhs`.
247
 
248
  ``` cpp
249
- bool operator!=(const error_category& rhs) const noexcept;
250
  ```
251
 
252
- *Returns:* `!(*this == rhs)`.
253
 
254
- ``` cpp
255
- bool operator<(const error_category& rhs) const noexcept;
256
- ```
257
-
258
- *Returns:* `less<const error_category*>()(this, &rhs)`.
259
-
260
- [*Note 1*: `less` ([[comparisons]]) provides a total ordering for
261
- pointers. — *end note*]
262
 
263
- #### Program defined classes derived from `error_category` <a id="syserr.errcat.derived">[[syserr.errcat.derived]]</a>
264
 
265
  ``` cpp
266
  virtual const char* name() const noexcept = 0;
267
  ```
268
 
@@ -327,11 +305,11 @@ unbounded, and some may not correspond to any POSIX `errno` value. Thus
327
  implementations are given latitude in determining
328
  correspondence. — *end note*]
329
 
330
  ### Class `error_code` <a id="syserr.errcode">[[syserr.errcode]]</a>
331
 
332
- #### Class `error_code` overview <a id="syserr.errcode.overview">[[syserr.errcode.overview]]</a>
333
 
334
  The class `error_code` describes an object used to hold error code
335
  values, such as those originating from the operating system or other
336
  low-level application program interfaces.
337
 
@@ -373,71 +351,59 @@ namespace std {
373
  basic_ostream<charT, traits>&
374
  operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
375
  }
376
  ```
377
 
378
- #### Class `error_code` constructors <a id="syserr.errcode.constructors">[[syserr.errcode.constructors]]</a>
379
 
380
  ``` cpp
381
  error_code() noexcept;
382
  ```
383
 
384
- *Effects:* Constructs an object of type `error_code`.
385
-
386
- *Postconditions:* `val_ == 0` and `cat_ == &system_category()`.
387
 
388
  ``` cpp
389
  error_code(int val, const error_category& cat) noexcept;
390
  ```
391
 
392
- *Effects:* Constructs an object of type `error_code`.
393
-
394
- *Postconditions:* `val_ == val` and `cat_ == &cat`.
395
 
396
  ``` cpp
397
  template<class ErrorCodeEnum>
398
  error_code(ErrorCodeEnum e) noexcept;
399
  ```
400
 
401
- *Effects:* Constructs an object of type `error_code`.
402
 
403
- *Postconditions:* `*this == make_error_code(e)`.
404
 
405
- *Remarks:*
406
-
407
- This constructor shall not participate in overload resolution unless
408
- `is_error_code_enum_v<ErrorCodeEnum>` is `true`.
409
-
410
- #### Class `error_code` modifiers <a id="syserr.errcode.modifiers">[[syserr.errcode.modifiers]]</a>
411
 
412
  ``` cpp
413
  void assign(int val, const error_category& cat) noexcept;
414
  ```
415
 
416
- *Postconditions:* `val_ == val` and `cat_ == &cat`.
417
 
418
  ``` cpp
419
  template<class ErrorCodeEnum>
420
  error_code& operator=(ErrorCodeEnum e) noexcept;
421
  ```
422
 
423
- *Postconditions:* `*this == make_error_code(e)`.
 
 
424
 
425
  *Returns:* `*this`.
426
 
427
- *Remarks:*
428
-
429
- This operator shall not participate in overload resolution unless
430
- `is_error_code_enum_v<ErrorCodeEnum>` is `true`.
431
-
432
  ``` cpp
433
  void clear() noexcept;
434
  ```
435
 
436
- *Postconditions:* `value() == 0` and `category() == system_category()`.
437
 
438
- #### Class `error_code` observers <a id="syserr.errcode.observers">[[syserr.errcode.observers]]</a>
439
 
440
  ``` cpp
441
  int value() const noexcept;
442
  ```
443
 
@@ -465,35 +431,35 @@ string message() const;
465
  explicit operator bool() const noexcept;
466
  ```
467
 
468
  *Returns:* `value() != 0`.
469
 
470
- #### Class `error_code` non-member functions <a id="syserr.errcode.nonmembers">[[syserr.errcode.nonmembers]]</a>
471
 
472
  ``` cpp
473
  error_code make_error_code(errc e) noexcept;
474
  ```
475
 
476
  *Returns:* `error_code(static_cast<int>(e), generic_category())`.
477
 
478
  ``` cpp
479
  template<class charT, class traits>
480
- basic_ostream<charT, traits>&
481
- operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
482
  ```
483
 
484
- *Effects:* As if by: `os << ec.category().name() << ’:’ << ec.value();`
 
485
 
486
  ### Class `error_condition` <a id="syserr.errcondition">[[syserr.errcondition]]</a>
487
 
488
- #### Class `error_condition` overview <a id="syserr.errcondition.overview">[[syserr.errcondition.overview]]</a>
489
 
490
  The class `error_condition` describes an object used to hold values
491
  identifying error conditions.
492
 
493
  [*Note 1*: `error_condition` values are portable abstractions, while
494
- `error_code` values ([[syserr.errcode]]) are implementation
495
  specific. — *end note*]
496
 
497
  ``` cpp
498
  namespace std {
499
  class error_condition {
@@ -521,71 +487,61 @@ namespace std {
521
  const error_category* cat_; // exposition only
522
  };
523
  }
524
  ```
525
 
526
- #### Class `error_condition` constructors <a id="syserr.errcondition.constructors">[[syserr.errcondition.constructors]]</a>
527
 
528
  ``` cpp
529
  error_condition() noexcept;
530
  ```
531
 
532
- *Effects:* Constructs an object of type `error_condition`.
533
-
534
- *Postconditions:* `val_ == 0` and `cat_ == &generic_category()`.
535
 
536
  ``` cpp
537
  error_condition(int val, const error_category& cat) noexcept;
538
  ```
539
 
540
- *Effects:* Constructs an object of type `error_condition`.
541
-
542
- *Postconditions:* `val_ == val` and `cat_ == &cat`.
543
 
544
  ``` cpp
545
  template<class ErrorConditionEnum>
546
  error_condition(ErrorConditionEnum e) noexcept;
547
  ```
548
 
549
- *Effects:* Constructs an object of type `error_condition`.
 
550
 
551
- *Postconditions:* `*this == make_error_condition(e)`.
552
 
553
- *Remarks:*
554
-
555
- This constructor shall not participate in overload resolution unless
556
- `is_error_condition_enum_v<ErrorConditionEnum>` is `true`.
557
-
558
- #### Class `error_condition` modifiers <a id="syserr.errcondition.modifiers">[[syserr.errcondition.modifiers]]</a>
559
 
560
  ``` cpp
561
  void assign(int val, const error_category& cat) noexcept;
562
  ```
563
 
564
- *Postconditions:* `val_ == val` and `cat_ == &cat`.
565
 
566
  ``` cpp
567
  template<class ErrorConditionEnum>
568
  error_condition& operator=(ErrorConditionEnum e) noexcept;
569
  ```
570
 
571
- *Postconditions:* `*this == make_error_condition(e)`.
 
 
 
572
 
573
  *Returns:* `*this`.
574
 
575
- *Remarks:*
576
-
577
- This operator shall not participate in overload resolution unless
578
- `is_error_condition_enum_v<ErrorConditionEnum>` is `true`.
579
-
580
  ``` cpp
581
  void clear() noexcept;
582
  ```
583
 
584
- *Postconditions:* `value() == 0` and `category() == generic_category()`.
585
 
586
- #### Class `error_condition` observers <a id="syserr.errcondition.observers">[[syserr.errcondition.observers]]</a>
587
 
588
  ``` cpp
589
  int value() const noexcept;
590
  ```
591
 
@@ -607,97 +563,93 @@ string message() const;
607
  explicit operator bool() const noexcept;
608
  ```
609
 
610
  *Returns:* `value() != 0`.
611
 
612
- #### Class `error_condition` non-member functions <a id="syserr.errcondition.nonmembers">[[syserr.errcondition.nonmembers]]</a>
613
 
614
  ``` cpp
615
  error_condition make_error_condition(errc e) noexcept;
616
  ```
617
 
618
  *Returns:* `error_condition(static_cast<int>(e), generic_category())`.
619
 
620
  ### Comparison functions <a id="syserr.compare">[[syserr.compare]]</a>
621
 
622
- ``` cpp
623
- bool operator<(const error_code& lhs, const error_code& rhs) noexcept;
624
- ```
625
-
626
- *Returns:*
627
-
628
- ``` cpp
629
- lhs.category() < rhs.category() ||
630
- (lhs.category() == rhs.category() && lhs.value() < rhs.value());
631
- ```
632
-
633
- ``` cpp
634
- bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
635
- ```
636
-
637
- *Returns:*
638
- `lhs.category() < rhs.category() || lhs.category() == rhs.category() &&`
639
- `lhs.value() < rhs.value()`.
640
-
641
  ``` cpp
642
  bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
643
  ```
644
 
645
  *Returns:*
646
- `lhs.category() == rhs.category() && lhs.value() == rhs.value()`.
 
 
 
647
 
648
  ``` cpp
649
  bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
650
  ```
651
 
652
  *Returns:*
653
- `lhs.category().equivalent(lhs.value(), rhs) || rhs.category().equivalent(lhs, rhs.value())`.
654
 
655
  ``` cpp
656
- bool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
657
  ```
658
 
659
- *Returns:*
660
- `rhs.category().equivalent(rhs.value(), lhs) || lhs.category().equivalent(rhs, lhs.value())`.
661
-
662
  ``` cpp
663
  bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
664
  ```
665
 
666
  *Returns:*
667
- `lhs.category() == rhs.category() && lhs.value() == rhs.value()`.
668
 
669
  ``` cpp
670
- bool operator!=(const error_code& lhs, const error_code& rhs) noexcept;
671
- bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
672
- bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
673
- bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
674
  ```
675
 
676
- *Returns:* `!(lhs == rhs)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
677
 
678
  ### System error hash support <a id="syserr.hash">[[syserr.hash]]</a>
679
 
680
  ``` cpp
681
  template<> struct hash<error_code>;
682
  template<> struct hash<error_condition>;
683
  ```
684
 
685
- The specializations are enabled ([[unord.hash]]).
686
 
687
  ### Class `system_error` <a id="syserr.syserr">[[syserr.syserr]]</a>
688
 
689
- #### Class `system_error` overview <a id="syserr.syserr.overview">[[syserr.syserr.overview]]</a>
690
 
691
  The class `system_error` describes an exception object used to report
692
  error conditions that have an associated error code. Such error
693
  conditions typically originate from the operating system or other
694
  low-level application program interfaces.
695
 
696
  [*Note 1*: If an error represents an out-of-memory condition,
697
  implementations are encouraged to throw an exception object of type
698
- `bad_alloc` ([[bad.alloc]]) rather than `system_error`. — *end note*]
699
 
700
  ``` cpp
701
  namespace std {
702
  class system_error : public runtime_error {
703
  public:
@@ -711,67 +663,55 @@ namespace std {
711
  const char* what() const noexcept override;
712
  };
713
  }
714
  ```
715
 
716
- #### Class `system_error` members <a id="syserr.syserr.members">[[syserr.syserr.members]]</a>
717
 
718
  ``` cpp
719
  system_error(error_code ec, const string& what_arg);
720
  ```
721
 
722
- *Effects:* Constructs an object of class `system_error`.
723
-
724
- *Postconditions:* `code() == ec`.
725
-
726
- `string(what()).find(what_arg) != string::npos`.
727
 
728
  ``` cpp
729
  system_error(error_code ec, const char* what_arg);
730
  ```
731
 
732
- *Effects:* Constructs an object of class `system_error`.
733
-
734
- *Postconditions:* `code() == ec`.
735
-
736
- `string(what()).find(what_arg) != string::npos`.
737
 
738
  ``` cpp
739
  system_error(error_code ec);
740
  ```
741
 
742
- *Effects:* Constructs an object of class `system_error`.
743
-
744
- *Postconditions:* `code() == ec`.
745
 
746
  ``` cpp
747
  system_error(int ev, const error_category& ecat, const string& what_arg);
748
  ```
749
 
750
- *Effects:* Constructs an object of class `system_error`.
751
 
752
- *Postconditions:* `code() == error_code(ev, ecat)`.
753
-
754
- `string(what()).find(what_arg) != string::npos`.
755
 
756
  ``` cpp
757
  system_error(int ev, const error_category& ecat, const char* what_arg);
758
  ```
759
 
760
- *Effects:* Constructs an object of class `system_error`.
761
 
762
- *Postconditions:* `code() == error_code(ev, ecat)`.
763
-
764
- `string(what()).find(what_arg) != string::npos`.
765
 
766
  ``` cpp
767
  system_error(int ev, const error_category& ecat);
768
  ```
769
 
770
- *Effects:* Constructs an object of class `system_error`.
771
-
772
- *Postconditions:* `code() == error_code(ev, ecat)`.
773
 
774
  ``` cpp
775
  const error_code& code() const noexcept;
776
  ```
777
 
@@ -789,18 +729,19 @@ constructor.
789
  `what_arg + ": " + code.message()`. — *end note*]
790
 
791
  <!-- Link reference definitions -->
792
  [assertions]: #assertions
793
  [assertions.assert]: #assertions.assert
794
- [bad.alloc]: language.md#bad.alloc
795
  [cassert.syn]: #cassert.syn
796
  [cerrno.syn]: #cerrno.syn
797
- [comparisons]: utilities.md#comparisons
798
- [conv]: conv.md#conv
799
  [defns.const.subexpr]: library.md#defns.const.subexpr
800
  [diagnostics]: #diagnostics
801
  [diagnostics.general]: #diagnostics.general
 
802
  [domain.error]: #domain.error
803
  [errno]: #errno
804
  [invalid.argument]: #invalid.argument
805
  [length.error]: #length.error
806
  [logic.error]: #logic.error
@@ -833,9 +774,8 @@ constructor.
833
  [syserr.errcondition.overview]: #syserr.errcondition.overview
834
  [syserr.hash]: #syserr.hash
835
  [syserr.syserr]: #syserr.syserr
836
  [syserr.syserr.members]: #syserr.syserr.members
837
  [syserr.syserr.overview]: #syserr.syserr.overview
838
- [system_error.syn]: #system_error.syn
839
- [tab:diagnostics.lib.summary]: #tab:diagnostics.lib.summary
840
  [underflow.error]: #underflow.error
841
  [unord.hash]: utilities.md#unord.hash
 
1
  ## System error support <a id="syserr">[[syserr]]</a>
2
 
3
+ This subclause describes components that the standard library and C++
4
+ programs may use to report error conditions originating from the
5
  operating system or other low-level application program interfaces.
6
 
7
  Components described in this subclause shall not change the value of
8
+ `errno` [[errno]]. Implementations should leave the error states
9
  provided by other libraries unchanged.
10
 
11
+ ### Header `<system_error>` synopsis <a id="system.error.syn">[[system.error.syn]]</a>
12
 
13
  ``` cpp
14
+ #include <compare> // see [compare.syn]
15
+
16
  namespace std {
17
  class error_category;
18
  const error_category& generic_category() noexcept;
19
  const error_category& system_category() noexcept;
20
 
 
120
 
121
  // [syserr.errcondition.nonmembers], non-member functions
122
  error_condition make_error_condition(errc e) noexcept;
123
 
124
  // [syserr.compare], comparison functions
 
 
125
  bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
126
  bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
 
127
  bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
128
+ strong_ordering operator<=>(const error_code& lhs, const error_code& rhs) noexcept;
129
+ strong_ordering operator<=>(const error_condition& lhs, const error_condition& rhs) noexcept;
 
 
130
 
131
  // [syserr.hash], hash support
132
  template<class T> struct hash;
133
  template<> struct hash<error_code>;
134
  template<> struct hash<error_condition>;
135
 
136
  // [syserr], system error support
137
+ template<class T>
138
+ inline constexpr bool is_error_code_enum_v = is_error_code_enum<T>::value;
139
+ template<class T>
140
+ inline constexpr bool is_error_condition_enum_v = is_error_condition_enum<T>::value;
141
  }
142
  ```
143
 
144
  The value of each `enum errc` constant shall be the same as the value of
145
  the `<cerrno>` macro shown in the above synopsis. Whether or not the
146
  `<system_error>` implementation exposes the `<cerrno>` macros is
147
  unspecified.
148
 
149
  The `is_error_code_enum` and `is_error_condition_enum` may be
150
+ specialized for program-defined types to indicate that such types are
151
  eligible for `class error_code` and `class error_condition` automatic
152
  conversions, respectively.
153
 
154
  ### Class `error_category` <a id="syserr.errcat">[[syserr.errcat]]</a>
155
 
156
+ #### Overview <a id="syserr.errcat.overview">[[syserr.errcat.overview]]</a>
157
 
158
  The class `error_category` serves as a base class for types used to
159
  identify the source and encoding of a particular category of error code.
160
  Classes may be derived from `error_category` to support categories of
161
+ errors in addition to those defined in this document. Such classes shall
162
+ behave as specified in subclause  [[syserr.errcat]].
163
 
164
  [*Note 1*: `error_category` objects are passed by reference, and two
165
  such objects are equal if they have the same address. This means that
166
  applications using custom `error_category` types should create a single
167
  object of each such type. — *end note*]
 
179
  virtual bool equivalent(int code, const error_condition& condition) const noexcept;
180
  virtual bool equivalent(const error_code& code, int condition) const noexcept;
181
  virtual string message(int ev) const = 0;
182
 
183
  bool operator==(const error_category& rhs) const noexcept;
184
+ strong_ordering operator<=>(const error_category& rhs) const noexcept;
 
185
  };
186
 
187
  const error_category& generic_category() noexcept;
188
  const error_category& system_category() noexcept;
189
  }
190
  ```
191
 
192
+ #### Virtual members <a id="syserr.errcat.virtuals">[[syserr.errcat.virtuals]]</a>
 
 
 
 
 
 
193
 
194
  ``` cpp
195
  virtual const char* name() const noexcept = 0;
196
  ```
197
 
 
219
  virtual string message(int ev) const = 0;
220
  ```
221
 
222
  *Returns:* A string that describes the error condition denoted by `ev`.
223
 
224
+ #### Non-virtual members <a id="syserr.errcat.nonvirtuals">[[syserr.errcat.nonvirtuals]]</a>
 
 
 
 
 
 
225
 
226
  ``` cpp
227
  bool operator==(const error_category& rhs) const noexcept;
228
  ```
229
 
230
  *Returns:* `this == &rhs`.
231
 
232
  ``` cpp
233
+ strong_ordering operator<=>(const error_category& rhs) const noexcept;
234
  ```
235
 
236
+ *Returns:* `compare_three_way()(this, &rhs)`.
237
 
238
+ [*Note 1*: `compare_three_way` [[comparisons.three.way]] provides a
239
+ total ordering for pointers. *end note*]
 
 
 
 
 
 
240
 
241
+ #### Program-defined classes derived from `error_category` <a id="syserr.errcat.derived">[[syserr.errcat.derived]]</a>
242
 
243
  ``` cpp
244
  virtual const char* name() const noexcept = 0;
245
  ```
246
 
 
305
  implementations are given latitude in determining
306
  correspondence. — *end note*]
307
 
308
  ### Class `error_code` <a id="syserr.errcode">[[syserr.errcode]]</a>
309
 
310
+ #### Overview <a id="syserr.errcode.overview">[[syserr.errcode.overview]]</a>
311
 
312
  The class `error_code` describes an object used to hold error code
313
  values, such as those originating from the operating system or other
314
  low-level application program interfaces.
315
 
 
351
  basic_ostream<charT, traits>&
352
  operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
353
  }
354
  ```
355
 
356
+ #### Constructors <a id="syserr.errcode.constructors">[[syserr.errcode.constructors]]</a>
357
 
358
  ``` cpp
359
  error_code() noexcept;
360
  ```
361
 
362
+ *Ensures:* `val_ == 0` and `cat_ == &system_category()`.
 
 
363
 
364
  ``` cpp
365
  error_code(int val, const error_category& cat) noexcept;
366
  ```
367
 
368
+ *Ensures:* `val_ == val` and `cat_ == &cat`.
 
 
369
 
370
  ``` cpp
371
  template<class ErrorCodeEnum>
372
  error_code(ErrorCodeEnum e) noexcept;
373
  ```
374
 
375
+ *Constraints:* `is_error_code_enum_v<ErrorCodeEnum>` is `true`.
376
 
377
+ *Ensures:* `*this == make_error_code(e)`.
378
 
379
+ #### Modifiers <a id="syserr.errcode.modifiers">[[syserr.errcode.modifiers]]</a>
 
 
 
 
 
380
 
381
  ``` cpp
382
  void assign(int val, const error_category& cat) noexcept;
383
  ```
384
 
385
+ *Ensures:* `val_ == val` and `cat_ == &cat`.
386
 
387
  ``` cpp
388
  template<class ErrorCodeEnum>
389
  error_code& operator=(ErrorCodeEnum e) noexcept;
390
  ```
391
 
392
+ *Constraints:* `is_error_code_enum_v<ErrorCodeEnum>` is `true`.
393
+
394
+ *Ensures:* `*this == make_error_code(e)`.
395
 
396
  *Returns:* `*this`.
397
 
 
 
 
 
 
398
  ``` cpp
399
  void clear() noexcept;
400
  ```
401
 
402
+ *Ensures:* `value() == 0` and `category() == system_category()`.
403
 
404
+ #### Observers <a id="syserr.errcode.observers">[[syserr.errcode.observers]]</a>
405
 
406
  ``` cpp
407
  int value() const noexcept;
408
  ```
409
 
 
431
  explicit operator bool() const noexcept;
432
  ```
433
 
434
  *Returns:* `value() != 0`.
435
 
436
+ #### Non-member functions <a id="syserr.errcode.nonmembers">[[syserr.errcode.nonmembers]]</a>
437
 
438
  ``` cpp
439
  error_code make_error_code(errc e) noexcept;
440
  ```
441
 
442
  *Returns:* `error_code(static_cast<int>(e), generic_category())`.
443
 
444
  ``` cpp
445
  template<class charT, class traits>
446
+ basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
 
447
  ```
448
 
449
+ *Effects:* Equivalent to:
450
+ `return os << ec.category().name() << ’:’ << ec.value();`
451
 
452
  ### Class `error_condition` <a id="syserr.errcondition">[[syserr.errcondition]]</a>
453
 
454
+ #### Overview <a id="syserr.errcondition.overview">[[syserr.errcondition.overview]]</a>
455
 
456
  The class `error_condition` describes an object used to hold values
457
  identifying error conditions.
458
 
459
  [*Note 1*: `error_condition` values are portable abstractions, while
460
+ `error_code` values [[syserr.errcode]] are implementation
461
  specific. — *end note*]
462
 
463
  ``` cpp
464
  namespace std {
465
  class error_condition {
 
487
  const error_category* cat_; // exposition only
488
  };
489
  }
490
  ```
491
 
492
+ #### Constructors <a id="syserr.errcondition.constructors">[[syserr.errcondition.constructors]]</a>
493
 
494
  ``` cpp
495
  error_condition() noexcept;
496
  ```
497
 
498
+ *Ensures:* `val_ == 0` and `cat_ == &generic_category()`.
 
 
499
 
500
  ``` cpp
501
  error_condition(int val, const error_category& cat) noexcept;
502
  ```
503
 
504
+ *Ensures:* `val_ == val` and `cat_ == &cat`.
 
 
505
 
506
  ``` cpp
507
  template<class ErrorConditionEnum>
508
  error_condition(ErrorConditionEnum e) noexcept;
509
  ```
510
 
511
+ *Constraints:* `is_error_condition_enum_v<ErrorConditionEnum>` is
512
+ `true`.
513
 
514
+ *Ensures:* `*this == make_error_condition(e)`.
515
 
516
+ #### Modifiers <a id="syserr.errcondition.modifiers">[[syserr.errcondition.modifiers]]</a>
 
 
 
 
 
517
 
518
  ``` cpp
519
  void assign(int val, const error_category& cat) noexcept;
520
  ```
521
 
522
+ *Ensures:* `val_ == val` and `cat_ == &cat`.
523
 
524
  ``` cpp
525
  template<class ErrorConditionEnum>
526
  error_condition& operator=(ErrorConditionEnum e) noexcept;
527
  ```
528
 
529
+ *Constraints:* `is_error_condition_enum_v<ErrorConditionEnum>` is
530
+ `true`.
531
+
532
+ *Ensures:* `*this == make_error_condition(e)`.
533
 
534
  *Returns:* `*this`.
535
 
 
 
 
 
 
536
  ``` cpp
537
  void clear() noexcept;
538
  ```
539
 
540
+ *Ensures:* `value() == 0` and `category() == generic_category()`.
541
 
542
+ #### Observers <a id="syserr.errcondition.observers">[[syserr.errcondition.observers]]</a>
543
 
544
  ``` cpp
545
  int value() const noexcept;
546
  ```
547
 
 
563
  explicit operator bool() const noexcept;
564
  ```
565
 
566
  *Returns:* `value() != 0`.
567
 
568
+ #### Non-member functions <a id="syserr.errcondition.nonmembers">[[syserr.errcondition.nonmembers]]</a>
569
 
570
  ``` cpp
571
  error_condition make_error_condition(errc e) noexcept;
572
  ```
573
 
574
  *Returns:* `error_condition(static_cast<int>(e), generic_category())`.
575
 
576
  ### Comparison functions <a id="syserr.compare">[[syserr.compare]]</a>
577
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
578
  ``` cpp
579
  bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
580
  ```
581
 
582
  *Returns:*
583
+
584
+ ``` cpp
585
+ lhs.category() == rhs.category() && lhs.value() == rhs.value()
586
+ ```
587
 
588
  ``` cpp
589
  bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
590
  ```
591
 
592
  *Returns:*
 
593
 
594
  ``` cpp
595
+ lhs.category().equivalent(lhs.value(), rhs) || rhs.category().equivalent(lhs, rhs.value())
596
  ```
597
 
 
 
 
598
  ``` cpp
599
  bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
600
  ```
601
 
602
  *Returns:*
 
603
 
604
  ``` cpp
605
+ lhs.category() == rhs.category() && lhs.value() == rhs.value()
 
 
 
606
  ```
607
 
608
+ ``` cpp
609
+ strong_ordering operator<=>(const error_code& lhs, const error_code& rhs) noexcept;
610
+ ```
611
+
612
+ *Effects:* Equivalent to:
613
+
614
+ ``` cpp
615
+ if (auto c = lhs.category() <=> rhs.category(); c != 0) return c;
616
+ return lhs.value() <=> rhs.value();
617
+ ```
618
+
619
+ ``` cpp
620
+ strong_ordering operator<=>(const error_condition& lhs, const error_condition& rhs) noexcept;
621
+ ```
622
+
623
+ *Returns:*
624
+
625
+ ``` cpp
626
+ if (auto c = lhs.category() <=> rhs.category(); c != 0) return c;
627
+ return lhs.value() <=> rhs.value();
628
+ ```
629
 
630
  ### System error hash support <a id="syserr.hash">[[syserr.hash]]</a>
631
 
632
  ``` cpp
633
  template<> struct hash<error_code>;
634
  template<> struct hash<error_condition>;
635
  ```
636
 
637
+ The specializations are enabled [[unord.hash]].
638
 
639
  ### Class `system_error` <a id="syserr.syserr">[[syserr.syserr]]</a>
640
 
641
+ #### Overview <a id="syserr.syserr.overview">[[syserr.syserr.overview]]</a>
642
 
643
  The class `system_error` describes an exception object used to report
644
  error conditions that have an associated error code. Such error
645
  conditions typically originate from the operating system or other
646
  low-level application program interfaces.
647
 
648
  [*Note 1*: If an error represents an out-of-memory condition,
649
  implementations are encouraged to throw an exception object of type
650
+ `bad_alloc` [[bad.alloc]] rather than `system_error`. — *end note*]
651
 
652
  ``` cpp
653
  namespace std {
654
  class system_error : public runtime_error {
655
  public:
 
663
  const char* what() const noexcept override;
664
  };
665
  }
666
  ```
667
 
668
+ #### Members <a id="syserr.syserr.members">[[syserr.syserr.members]]</a>
669
 
670
  ``` cpp
671
  system_error(error_code ec, const string& what_arg);
672
  ```
673
 
674
+ *Ensures:* `code() == ec` and
675
+ `string_view(what()).find(what_arg.c_str()) != string_view::npos`.
 
 
 
676
 
677
  ``` cpp
678
  system_error(error_code ec, const char* what_arg);
679
  ```
680
 
681
+ *Ensures:* `code() == ec` and
682
+ `string_view(what()).find(what_arg) != string_view::npos`.
 
 
 
683
 
684
  ``` cpp
685
  system_error(error_code ec);
686
  ```
687
 
688
+ *Ensures:* `code() == ec`.
 
 
689
 
690
  ``` cpp
691
  system_error(int ev, const error_category& ecat, const string& what_arg);
692
  ```
693
 
694
+ *Ensures:*
695
 
696
+ `code() == error_code(ev, ecat)` and
697
+ `string_view(what()).find(what_arg.c_str()) != string_view::npos`.
 
698
 
699
  ``` cpp
700
  system_error(int ev, const error_category& ecat, const char* what_arg);
701
  ```
702
 
703
+ *Ensures:*
704
 
705
+ `code() == error_code(ev, ecat)` and
706
+ `string_view(what()).find(what_arg) != string_view::npos`.
 
707
 
708
  ``` cpp
709
  system_error(int ev, const error_category& ecat);
710
  ```
711
 
712
+ *Ensures:* `code() == error_code(ev, ecat)`.
 
 
713
 
714
  ``` cpp
715
  const error_code& code() const noexcept;
716
  ```
717
 
 
729
  `what_arg + ": " + code.message()`. — *end note*]
730
 
731
  <!-- Link reference definitions -->
732
  [assertions]: #assertions
733
  [assertions.assert]: #assertions.assert
734
+ [bad.alloc]: support.md#bad.alloc
735
  [cassert.syn]: #cassert.syn
736
  [cerrno.syn]: #cerrno.syn
737
+ [comparisons.three.way]: utilities.md#comparisons.three.way
738
+ [conv]: expr.md#conv
739
  [defns.const.subexpr]: library.md#defns.const.subexpr
740
  [diagnostics]: #diagnostics
741
  [diagnostics.general]: #diagnostics.general
742
+ [diagnostics.summary]: #diagnostics.summary
743
  [domain.error]: #domain.error
744
  [errno]: #errno
745
  [invalid.argument]: #invalid.argument
746
  [length.error]: #length.error
747
  [logic.error]: #logic.error
 
774
  [syserr.errcondition.overview]: #syserr.errcondition.overview
775
  [syserr.hash]: #syserr.hash
776
  [syserr.syserr]: #syserr.syserr
777
  [syserr.syserr.members]: #syserr.syserr.members
778
  [syserr.syserr.overview]: #syserr.syserr.overview
779
+ [system.error.syn]: #system.error.syn
 
780
  [underflow.error]: #underflow.error
781
  [unord.hash]: utilities.md#unord.hash