On this page
std::ignore
Defined in header <tuple> |
||
|---|---|---|
|
(since C++11) (until C++17) |
|
|
(since C++17) |
An object of unspecified type such that any value can be assigned to it with no effect. Intended for use with std::tie when unpacking a std::tuple, as a placeholder for the arguments that are not used.
While the behavior of std::ignore outside of std::tie is not formally specified, some code guides recommend using std::ignore to avoid warnings from unused return values of [[nodiscard]] functions.
Possible implementation
|
Example
- Demonstrates the use of
std::ignoretogether with a[[nodiscard]]function. - Unpacks a
std::pair<iterator, bool>returned bystd::set::insert(), but only saves the boolean.
#include <iostream>
#include <set>
#include <string>
#include <tuple>
[[nodiscard]] int dontIgnoreMe()
{
return 42;
}
int main()
{
std::ignore = dontIgnoreMe();
std::set<std::string> set_of_str;
bool inserted = false;
std::tie(std::ignore, inserted) = set_of_str.insert("Test");
if (inserted)
std::cout << "Value was inserted successfully\n";
}
Output:
Value was inserted successfully
See also
|
(C++11)
|
creates a tuple of lvalue references or unpacks a tuple into individual objects (function template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/utility/tuple/ignore