C++20 sections · 1024 units
Open in Course

What is a Tuple?

Beyond two elements

Tuples hold three or more values of potentially different types. Use tuple<int, string, double> when pairs aren't enough. Each position has its own type. Where pairs limit you to two values, tuples scale to any count.

A function might return tuple<bool, int, string> for success flag, error code, and message. Tuples compare lexicographically and work with STL algorithms like pairs do. The standard library provides tools to unpack them with structured bindings.