Unpacking tuples values

Another useful member that functions in the tuples classes is tie(), which is used to unpack a tuple into individual objects or create a tuple of lvalue references. Also, we have the ignore helper class in tuples, a placeholder to skip an element when unpacking a tuple is using tie(). Let's see the use of tie() and ignore in the following block of code:

    /* tuples_2.cpp */    #include <tuple>    #include <iostream>    using namespace std;    auto main() -> int   {      cout << "[tuples_2.cpp]" << endl;      // Initializing two Tuples      tuple<int, string, bool> t1(1, "Robert", true);      auto t2 = make_tuple(2, "Anna", false);      int i;      string s;      bool b;      // Unpacking t1 Tuples      tie(i, s, b) = t1;      cout << "tie(i, s, b) = t1" << endl; cout << "i = " << ...

Get Learning C++ Functional Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.