The Standard Library provides a special case of tuple, a 2-tuple, called std::pair. This construct is used by Standard Library containers, which you have probably noted when operating on elements of std::map. You can store pairs in container classes, too. Of course, std::pair is not just a tool for container classes, it's useful on its own, and it comes with the convenience function std::make_pair, which automates type deduction, plus a set of operators for comparing pairs. A general solution for tuples, not just 2-tuples, is definitely even more useful. The offering from the Tuple library is not fully general, but it allows tuples up to 10 elements. (If more are needed, which seems unlikely but certainly not impossible, this limit can be extended.) What's more, these tuples are as efficient as a handcrafted solution using structs! |