std::tie ?

I am learning about tuples and have came across std::tie, and I just can not figure out the reason for it. Could someone explain the point in it? Is it just so i dont need to use get<> on the actual tuple itself, and instead i can use the variable that is a reference to that variable of the tuple?

I have read the info on it here http://www.cplusplus.com/reference/tuple/tie/ but still not understanding it

I understand that it says it creates a new tuple, but unsure about the whole unpacking thing
Last edited on
std::tie creates a tuple containing lvalue references.
Because the resultant tuple contains lvalue referencesm it can be used for unpacking.

In the example:
std::tie (myint, std::ignore, mychar) creates a tuple containing references to myint and mychar

std::tie (myint, std::ignore, mychar) = mytuple assigns one tuple to another;
since the tuple on the left hand side holds references, it assigns to myint and mychar

Unpacking a tuple with std::tie is superseded by structured bindings in C++17
https://www.geeksforgeeks.org/structured-binding-c/
Topic archived. No new replies allowed.