Skip to content

Commit a5882df

Browse files
authored
Merge pull request #5243 from Rageking8/improve-system-error-operators-reference
Improve `<system_error>` operators reference
2 parents d385365 + 469ab7c commit a5882df

File tree

1 file changed

+54
-20
lines changed

1 file changed

+54
-20
lines changed

docs/standard-library/system-error-operators.md

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
---
2-
description: "Learn more about: <system_error> operators"
32
title: "<system_error> operators"
4-
ms.date: "11/04/2016"
3+
description: "Learn more about: <system_error> operators"
4+
ms.date: "3/17/2025"
55
f1_keywords: ["system_error/std::operator!=", "system_error/std::operator=="]
6-
ms.assetid: c14edefb-bd8a-4e90-88d3-c59c98e6f73c
76
---
87
# `<system_error>` operators
98

10-
## <a name="op_eq_eq"></a> operator==
9+
## <a name="op_eq_eq"></a> `operator==`
1110

1211
Tests if the object on the left side of the operator is equal to the object on the right side.
1312

@@ -24,11 +23,11 @@ bool operator==(const error_condition& left,
2423

2524
### Parameters
2625

27-
*left*\
28-
The object to be tested for equality.
26+
*`left`*\
27+
The object to test for equality.
2928

30-
*right*\
31-
The object to be tested for equality.
29+
*`right`*\
30+
The object to test for equality.
3231

3332
### Return Value
3433

@@ -38,7 +37,7 @@ The object to be tested for equality.
3837

3938
This function returns `left.category() == right.category() && left.value() == right.value()`.
4039

41-
## <a name="op_neq"></a> operator!=
40+
## <a name="op_neq"></a> `operator!=`
4241

4342
Tests if the object on the left side of the operator is not equal to the object on the right side.
4443

@@ -51,15 +50,15 @@ bool operator!=(const error_condition& left, const error_condition& right);
5150

5251
### Parameters
5352

54-
*left*\
55-
The object to be tested for inequality.
53+
*`left`*\
54+
The object to test for inequality.
5655

57-
*right*\
58-
The object to be tested for inequality.
56+
*`right`*\
57+
The object to test for inequality.
5958

6059
### Return Value
6160

62-
**`true`** if the object passed in *left* is not equal to the object passed in *right*; otherwise **`false`**.
61+
**`true`** if the object passed in *left* is not equal to the object passed in *`right`*; otherwise **`false`**.
6362

6463
### Remarks
6564

@@ -95,23 +94,58 @@ inline bool operator<(
9594

9695
### Parameters
9796

98-
*left*\
99-
The object to be compared.
97+
*`left`*\
98+
The object to compare.
10099

101-
*right*\
102-
The object to be compared.
100+
*`right`*\
101+
The object to compare.
103102

104103
### Return Value
105104

106-
**`true`** if the object passed in *left* is less than the object passed in *right*; Otherwise, **`false`**.
105+
**`true`** if the object passed in *`left`* is less than the object passed in *`right`*; Otherwise, **`false`**.
107106

108107
### Remarks
109108

110109
This function tests the error order.
111110

112111
## <a name="op_ostream"></a> `operator<<`
113112

113+
Inserts an [`error_code`](error-code-class.md) object into the output stream.
114+
114115
```cpp
115116
template <class charT, class traits>
116-
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
117+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
118+
```
119+
120+
### Parameters
121+
122+
*`os`*\
123+
The target output stream.
124+
125+
*`ec`*\
126+
The `error_code` object to output.
127+
128+
### Return Value
129+
130+
A reference to the modified output stream.
131+
132+
### Remarks
133+
134+
This operator does the equivalent of `os << ec.category().name() << ':' << ec.value()`.
135+
136+
### Example
137+
138+
```cpp
139+
#include <iostream>
140+
#include <system_error>
141+
142+
int main()
143+
{
144+
std::error_code ec(1234, std::generic_category());
145+
std::cout << ec;
146+
}
147+
```
148+
149+
```Output
150+
generic:1234
117151
```

0 commit comments

Comments
 (0)