AlgoMaster Logo

std::pair & std::tuple

Last Updated: May 22, 2026

High Priority
10 min read

std::pair<T1, T2> glues two values of possibly different types into one object with fields first and second. std::tuple<Ts...> generalises the idea to any number of fields, accessed by index or by type. Both show up across the standard library (especially in map iteration and algorithms that need to return more than one value), and both are useful when you want a quick ad-hoc record without writing a full struct. This chapter covers what they are, how to construct and unpack them, when one is the right answer, and when a named struct beats both.

Premium Content

Subscribe to unlock full access to this content and more premium articles.