einpoklum einpoklum -4 years ago 92
C++ Question

STL-pair-like triplet class - do I roll my own?

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?

Edit: About


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;

now can I? Won't I have to typedef individual-type-combination triples?

Answer Source

Take a look at std::tuple - it's a generalization of std::pair. So here's a value-initialized triple of ints:

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>;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download