Skip to content

Commit a8045a4

Browse files
authored
Update c6031.md
Adding additional documentation on the use of std::ignore to silence the C6031 warning.
1 parent 5a464f9 commit a8045a4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/code-quality/c6031.md

+14
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ void test_f()
8383
}
8484
```
8585

86+
In cases where it is necessary to ignore the return value of a function, assign the returned value to `std::ignore`. Assigning to `std::ignore` clearly indicates developer intent and helps in future code maintenance.
87+
88+
```cpp
89+
#include <tuple>
90+
#include <ctime>
91+
#include <stdio.h>
92+
void f()
93+
{
94+
std::srand(static_cast(std::time(nullptr))); // set initial seed value to system clock
95+
std::ignore = std::rand(); // Discard the first result as the few random results are always small.
96+
// ...
97+
}
98+
```
99+
86100
## See also
87101

88102
[fopen_s, _wfopen_s](../c-runtime-library/reference/fopen-s-wfopen-s.md)\

0 commit comments

Comments
 (0)