Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22047

Is it ok to use std::ignore in order to discard a return value of a function to avoid any related compiler warnings?

$
0
0

I know that you can use static_cast<void>, but it just seems too verbose for me, and not reflecting the original intent that I want to discard a return value, not to cast it to anything.

Recently I stumbled upon std::ignore, which can accept a value of any type, the name is clear and readable, and to me it seems fitting.

I know that the initial intent was to use std::ignore alongside with std::tie to discard any unwanted values, but I guess the original intent of static_cast was to actually cast values for some better reasons than discarding values so the compiler won't complain.

So, is it OK to use std::ignore for the purpose I described in the question?

For example:

std::ignore = std::transform(...);

Viewing all articles
Browse latest Browse all 22047

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>