C++ 是否提供了“三重"?模板,与对<T1,T2>相比较? [英] Does C++ provide a "triple" template, comparable to pair<T1, T2>?
本文介绍了C++ 是否提供了“三重"?模板,与对<T1,T2>相比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
C++ 有没有类似 std::pair 但有 3元素?
Does C++ have anything like std::pair but with 3 elements?
例如:
#include <triple.h>
triple<int, int, int> array[10];
array[1].first = 1;
array[1].second = 2;
array[1].third = 3;
推荐答案
您可能正在寻找 std::tuple
:
You might be looking for std::tuple
:
#include <tuple>
....
std::tuple<int, int, int> tpl;
std::get<0>(tpl) = 1;
std::get<1>(tpl) = 2;
std::get<2>(tpl) = 3;
这篇关于C++ 是否提供了“三重"?模板,与对<T1,T2>相比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文