CKTIS / C++
std::ignore — skipping elements during tuple assignment
std::ignore is a standard-library object used with std::tie to skip selected elements during tuple assignment. It lets you store the values you need in existing variables without creating a dummy variable for the skipped element.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
#include <tuple>
std::tie(first, std::ignore, last) = values;std::ignore, available through <tuple>, is an object, not a function or keyword. In an assignment using std::tie, it occupies the position of an element whose value you do not want to keep. You do not need to know or name its concrete type.
std::tie(first, std::ignore, last) creates a tuple of references. Assignment from values stores the first and third elements in first and last, while the second goes to std::ignore and is not retained. The skipped position still counts: both tuples in this example must have three elements.
Ignoring a value does not skip its computation. Expressions forming the right-hand side are still evaluated, so std::ignore does not remove their side effects or exceptions. It is not a wildcard in a structured binding declaration either.
The example uses C++23 compilation mode and should print 7 12 followed by a newline. The sources show the current working draft, not a frozen C++23 text; the example does not require newer extensions.
Examples
#include <iostream>
#include <tuple>
int main() {
int first = 0;
int last = 0;
const auto values = std::make_tuple(7, 99, 12);
std::tie(first, std::ignore, last) = values;
std::cout << first << ' ' << last << '\n';
}
Result
7 12
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.