#include <iostream>
#include <tuple>
///////////////////////////////////////////////////////////////////////////////
std::tuple<int, double, int, double> returnTuple()
{
return {1, 2.2, 3, 4.4};
}
int main()
{
std::tuple<int, double, int, double> myTuple;
myTuple = returnTuple();
std::cout << std::get<0>(myTuple) << " "; // 1
std::cout << std::get<1>(myTuple) << " "; // 2.0
std::cout << std::get<2>(myTuple) << " "; // 3
std::cout << std::get<3>(myTuple) << " "; // 4.0
std::cout << std::endl;
return 0;
}
// Output: 1 2.2 3 4.4
Reference: http://en.cppreference.com/w/cpp/utility/tuple
Monday, November 27, 2017
C++17: Function returning tuple initialization-list
C++17 allows a function to return an initialization-list for a tuple. Here is an example:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment