skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
hpp-tuple
This page is read only. You can view the source, but not change it.
# <tuple> **[<tuple>](https://en.cppreference.com/w/cpp/header/tuple)** provides `std::tuple<T1, T2, ...>`, a heterogeneous fixed-size container holding values of different types. Use `std::get<I>(t)` to access by index or `std::get<T>(t)` to access by type. C++17 structured bindings (`auto [x, y] = tuple`) make tuples convenient. Tuples are useful for returning multiple values from a function without defining a struct. This example returns multiple values of different types from a function via tuple, using structured bindings to unpack them. ```cpp // compile: g++ -std=c++17 -o tupleexample tupleexample.cpp // run: ./tupleexample // description: tuple creation and unpacking #include <tuple> #include <iostream> #include <string> std::tuple<int, double, std::string> fetch_data() { return {42, 3.14, "hello"}; } int main() { auto [i, d, s] = fetch_data(); std::cout << "int: " << i << ", double: " << d << ", string: " << s << "\n"; return 0; } ```
Page Tools
Show pagesource
Backlinks
Back to top