问题描述
我想使用一个三元组类,尽可能类似于std :: pair。 STL似乎没有一个。我不想使用太重的东西,像Boost。有没有一些有用的FOSS非限制性许可三元组类,我可以从某地提起?我应该自己滚吗?
I want to use a triplet class, as similar as possible to std::pair. STL doesn't seem to have one. I don't want to use something too heavy, like Boost. Is there some useful FOSS non-restrictive-license triplet class I could lift from somewhere? Should I roll my own? Should I do something else entirely?
编辑:关于 std :: tuple
。 ..
对一个三元组特定类没有什么好处吗?我的意思是,用tuple,我不能做
Is there really no benefit to a triplet-specific class? I mean, with tuple, I can't do
template<typename T1, typename T2, typename T3> std::tuple<T1, T2, T3> triple;
现在可以吗?
推荐答案
看看 - 它是 std的概括:: pair
。所以这里是一个价值初始化的三元组 int
s:
Take a look at std::tuple
- it's a generalization of std::pair
. So here's a value-initialized triple of int
s:
std::tuple<int, int, int> triple;
如果需要,您可以有三元组的类型别名:
If you want, you can have a type alias for triples only:
template<typename T1, typename T2, typename T3>
using triple = std::tuple<T1, T2, T3>;
这篇关于STL对样的三元组类 - 我自己滚吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!