#include <iostream> #include <tuple> #include <string> #include <typeinfo> int main(int argc, char *argv[]) { //initialization std::tuple<std::string, int> planet("Earth", 4); auto address = std::make_tuple("US", "VA", "Yorktown", 1); //access std::cout<<std::get<0>(planet)<<" "<<std::get<1>(planet)<<std::endl; std::cout<<std::get<0>(address)<<" "<<std::get<1>(address)<<" "<<std::get<2>(address)<<" "<<std::get<3>(address)<<std::endl; //tie std::string city; int index; std::tie(std::ignore, std::ignore, city, index) = address; std::cout<<city<<" "<<index<<std::endl; //tuple_size std::cout<<std::tuple_size<decltype(address)>::value<<std::endl; //tuple_element std::cout<<typeid(decltype(address)).name()<<std::endl; std::cout<<typeid(std::tuple_element<3, decltype(address)>::type).name()<<std::endl; //forward_as_tuple, constructs a tuple object with rvalue references std::string greeting = "Hello"; std::tuple<std::string, int> person = std::forward_as_tuple(greeting+" World!", 20); std::cout<<std::get<0>(person)<<" "<<std::get<1>(person)<<std::endl; //tuple_cat, construct a tuple by concatenate tuples auto merge = std::tuple_cat(planet, address); std::cout<<std::get<0>(merge)<<" "<<std::get<1>(merge)<<" "<<std::get<2>(merge)<<" "<<std::get<3>(merge)<<" "<<std::get<4>(merge)<<" "<<std::get<5>(merge)<<std::endl; return 0; }