#include <tuple>
std::tuple<char, int, bool> my_tuple = {'H', 56, false};
std::tuple<int, int> foo_tuple()
{
return {1, -1}; // Error until N4387
return std::tuple<int, int>{1, -1}; // Always works
return std::make_tuple(1, -1); // Always works
}
#include <tuple>
std::tuple<int, int> foo_tuple()
{
return {1, -1}; // Error until N4387
return std::tuple<int, int>{1, -1}; // Always works
return std::make_tuple(1, -1); // Always works
}
std::tuple<types...>
std::make_tuple(vals...)
#include <tuple>
....
std::tuple<int, int, int> tpl;
std::get<0>(tpl) = 1;
std::get<1>(tpl) = 2;
std::get<2>(tpl) = 3;
// C++ code to demonstrate tuple, get() and make_pair()
#include<iostream>
#include<tuple> // for tuple
using namespace std;
int main()
{
// Declaring tuple
tuple <char, int, float> geek;
// Assigning values to tuple using make_tuple()
geek = make_tuple('a', 10, 15.5);
// Printing initial tuple values using get()
cout << "The initial values of tuple are : ";
cout << get<0>(geek) << " " << get<1>(geek);
cout << " " << get<2>(geek) << endl;
// Use of get() to change values of tuple
get<0>(geek) = 'b';
get<2>(geek) = 20.5;
// Printing modified tuple values
cout << "The modified values of tuple are : ";
cout << get<0>(geek) << " " << get<1>(geek);
cout << " " << get<2>(geek) << endl;
return 0;
}