#include <iostream>
#include <tuple>
int main()
{
int a;
double b;
int c;
double d;
std::tuple<int, double, int, double> myTuple{1, 2.2, 3, 4.4};
std::tie(a, b, c, d) = myTuple;
std::cout << a << " "; // 1
std::cout << b << " "; // 2.0
std::cout << c << " "; // 3
std::cout << d << " "; // 4.0
std::cout << std::endl;
return 0;
}
// Output: 1 2.2 3 4.4
References: http://en.cppreference.com/w/cpp/utility/tuple
Monday, November 27, 2017
C++11: std::tie() – tuple unpacking
The function template std::tie() allows you to unpack a tuple. Here is an example:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment