blog, c++,

std::tie in c++

Jing Chi Jing Chi Follow Aug 16, 2019 · 1 min read
std::tie in c++
Share this

std::tie(a, b, c) constructs a tuple object whose elements are references to the arguments. This allows a set of objects to act as a tuple, which is especially useful to unpack tuple objects. The special constant ignore can be used to specify elements of a tuple to be ignored instead of tied to a specific object.

#include <iostream>
#include <tuple>

int main ()
{
    int i = 0;
    char c = '\0';

    std::tuple<int, float, char> t = std::make_tuple(100, 1.0, 'a');
    std::tie(i, std::ignore, c) = t;   // unpacking tuple into variables
    std::cout << "i = " << i << ", c = '" << c << "'" << endl;

    return 0;
}