std::tuple是一个固定大小的不同类型值的集合,是泛化的std::pair。和c#中的tuple类似,但是比c#中的tuple强大得多。我们也可以把他当做一个通用的结构体来用,不需要创建结构体又获取结构体的特征,在某些情况下可以取代结构体使程序更简洁,直观。
样例:
// std::tuple
class CTuple
{
public:
CTuple() {}
~CTuple() {}
void Run();
private:
};
// 元组使用
void CTuple::Run()
{
//创建tuple
//auto t1 = make_tuple(1, "a1", "b1", "c1");
std::tuple<int,string,string,string> t1 = std::make_tuple(1, "China", "中国", "北京");
cout << get<0>(t1) << " "; //取值
cout << get<1>(t1) << " ";
cout << get<2>(t1) << " ";
cout << get<3>(t1) << " ";
cout << endl;
std::vector<tuple<int, string, string, string> > tv;
tv.push_back(t1);
tv.push_back(std::make_t