template <class... Args> class tuple;
#include <tuple> using namespace std; tuple <class... Args> 変数名; tuple<int, string, double, string> t; // 全ての要素を初期化 tuple<int, string, double, string> t(1, "aaa", 3.14, "bbb"); tuple<int, string, double, string> t(t1); // t1 : tuple tuple<int, string, double, string> t({1, "aaa", 3.14, "bbb"}); tuple<int, string, double, string> t{1, "aaa", 3.14, "bbb"}; tuple<int, string, double, string> t = {1, "aaa", 3.14, "bbb"};
= == != < <= > >=
#include <iostream> #include <tuple> using namespace std; int main() { // タプルの生成 tuple<int, string, double> t = make_tuple(1, "aaa", 3.14); cout << "**タプルの生成**\n"; cout << " t " << get<int>(t) << " " << get<1>(t) << " " << get<2>(t) << endl; // tie と ignore cout << "**tie と ignore**\n"; int a = 2; string b = "bbb"; double c = 1.23; cout << " a " << a << " b " << b << " c " << c << endl; tuple<int, string, double> t1 = tie(a, b, c); cout << " t1 " << get<0>(t1) << " " << get<1>(t1) << " " << get<2>(t1) << endl; tie(a, ignore, c) = t; cout << " a " << a << " b " << b << " c " << c << endl; // タプルの連結 cout << "**タプルの連結**\n"; tuple<int> t2 = {1}; tuple<string, string> t3 = {"xxx", "yyy"}; tuple<int, string, string> t4 = tuple_cat(t2, t3); cout << " t2 " << get<0>(t2) << endl; cout << " t3 " << get<0>(t3) << " " << get<1>(t3) << endl; cout << " t4 " << get<0>(t4) << " " << get<1>(t4) << " " << get<2>(t4) << endl; return 0; }
**タプルの生成** t 1 aaa 3.14 **tie と ignore** a 2 b bbb c 1.23 t1 2 bbb 1.23 a 1 b bbb c 3.14 **タプルの連結** t2 1 t3 xxx yyy t4 1 xxx yyy
菅沼ホーム | 本文目次 | 演習問題解答例 | 付録目次 | 索引 |