std::pair
a way to store two heterogeneous objects as a single unit. A pair is a specific case of a std::tuple with two elements. - cppreference.com
see also
- Deduction guide
- Difference between std::pair and std::tuple with only two members?
- Why is std::pair faster than std::tuple - in the end, performance results are equivalent/the same.
- It is fully expected that std::tuple will be slower than std::pair when not optimized, because it is more complicated object.
#include <utility>
std::pair p(2, 4.5); // deduces to std::pair<int, double> p(2, 4.5); - since C++17
or
int a[2], b[3];
std::pair p{a, b}; // explicit deduction guide is used in this case
auto p = std::make_pair(1, 3.14);
std::cout << '(' << std::get<0>(p) << ", " << std::get<1>(p) << ")\n";
std::cout << '(' << std::get<int>(p) << ", " << std::get<double>(p) << ")\n";
Written on June 7, 2023, Last update on June 7, 2023
c++
tuple