目录
- 1 基础知识
- 2 模板
- 3 工程化
1 基础知识
tuple是元组,一旦定义则不可修改,它可以存储一组不同类型的数据。它定义在头文件#include <tuple>
中。
(一)
tuple变量的定义。
tuple<int, float, string> a = {1, 2.0, "three"};
tuple<int, float, string> b(1, 2.0, "three");
tuple<int, float, string> c = make_tuple(1, 2.0, "three");
(二)
tuple变量的访问。
int a1 = get<0>(a);
float a2 = get<1>(a);
string a3 = get<2>(a);int b1;
float b2;
string b3;
tie(b1, b2, b3) = b;
2 模板
#include <iostream>
#include <tuple>
#include <string>using namespace std;int main() {tuple<int, float, string> a = {1, 2.0, "three"};tuple<int, float, string> b(1, 2.0, "three");tuple<int, float, string> c = make_tuple(1, 2.0, "three");int a1 = get<0>(a);float a2 = get<1>(a);string a3 = get<2>(a); cout << "a1 = " << a1 << ", a2 = " << a2 << ", a3 = " << a3 << endl;int b1;float b2;string b3;tie(b1, b2, b3) = b; cout << "b1 = " << b1 << ", b2 = " << b2 << ", b3 = " << b3 << endl;return 0;
}
上述代码输出,
a1 = 1, a2 = 2, a3 = three
b1 = 1, b2 = 2, b3 = three
3 工程化
暂无。。。