Skip to content

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

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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