Does C++ provide a "triple" template, comparable to pair<T1, T2>?

user3432317 picture user3432317 · May 13, 2014 · Viewed 39.2k times · Source

Does C++ have anything like std::pair but with 3 elements?

For example:

#include <triple.h>
triple<int, int, int> array[10];

array[1].first = 1;
array[1].second = 2;
array[1].third = 3;

Answer

juanchopanza picture juanchopanza · May 13, 2014

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;