C++ で std::ignore を使用して std::tie() で一部の値を受け取らないようにする
std::tie()
を利用すると std::tuple
の値を複数の変数で一度に受け取る事ができます。
auto calc(int a, int b){ return std::make_tuple(a + b, a - b, a * b, a / b); } int a, b, c, d; std::tie(a, b, c, d) = calc(6, 2);
[一部の値のみ受け取る]
std::ignore
を使用すると一部の値のみを受け取る事ができます。
auto calc(int a, int b){ return std::make_tuple(a + b, a - b, a * b, a / b); } int a, b; // 受け取る必要がない値に std::ignore を渡す std::tie(a, std::ignore, b, std::ignore) = calc(6, 2);
C++11 から追加された変数みたいですが、こんなのがあったのかー。