Skip to content

Provide a simple GSL utility to replace static_cast<void> #2319

@GabrielDosReis

Description

@GabrielDosReis

The guidelines recommend avoiding all cast (including static_cast). However, static_cast<void>(expr) is used (and blessed by the C++ standards) as a way to silence function calls whose results shouldn't be ignored. That can be seen as a gnarly hack. Instead, the GSL could provide a facility like

namespace gsl {
   template<typename T>
   inline void drop(T&&) { }
}

to use to ignore the value of an expression. No cast, intent preserved.

Metadata

Metadata

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