#include <iostream>
#include <string>
#include <tuple>
int main()
{
std::tuple
myTuple(1, 2, 3, 4.4f, 5.5, "six");
std::cout << std::get<int >(myTuple) << " ";
std::cout << std::get<long >(myTuple) << " ";
std::cout << std::get<short >(myTuple) << " ";
std::cout << std::get<float >(myTuple) << " ";
std::cout << std::get<double >(myTuple) << " ";
std::cout << std::get<std::string>(myTuple) << " ";
std::cout << std::endl;
return 0;
}
// Output: 1 2 3 4.4 5.5 six
Reference: http://developeradventure.blogspot.com/2013/12/c14-tuple-addressing-via-type.html
Tuesday, October 3, 2017
C++14: Tuple addressing via type
C++14 added addressing a tuple component by type. Here is an example:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment