Skip to content

ES.48: alternative to (void) cast #1580

@wolfseifert

Description

@wolfseifert

As an alternative to (void) cast or static_cast<void>() I suggest using a (empty) function "discard" to intentionally discard a [[nodiscard]] value:

`template
void discard(const T&) {}

[[nodiscard]] int foo () {return 0;}

int main () {
(void) foo();
static_cast<void>(foo());
discard(foo());
}`

This avoids a cast and is more readable.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions