<tuple>

tuple

class template
<tuple>

std::tuple

template <class... Types> class tuple;
Tuple
A tuple is an object capable to hold a collection of elements. Each element can be of a different type.

Template parameters

Types...
A list of types used for the elements, in the same order as they are going to be ordered in the tuple.

Member types

none.

Member functions


Non-member function overloads


Non-member class specializations


Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// tuple example #include <iostream> // std::cout #include <tuple> // std::tuple, std::get, std::tie, std::ignore int main () { std::tuple<int,char> foo (10,'x'); auto bar = std::make_tuple ("test", 3.1, 14, 'y'); std::get<2>(bar) = 100; // access element int myint; char mychar; std::tie (myint, mychar) = foo; // unpack elements std::tie (std::ignore, std::ignore, myint, mychar) = bar; // unpack (with ignore) mychar = std::get<3>(bar); std::get<0>(foo) = std::get<2>(bar); std::get<1>(foo) = mychar; std::cout << "foo contains: "; std::cout << std::get<0>(foo) << ' '; std::cout << std::get<1>(foo) << '\n'; return 0; }
Output:
foo contains: 100 y