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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.