(1) | ||||
| (since C++11) (until C++14) | |||
| (since C++14) | |||
(2) | ||||
| (since C++11) (until C++14) | |||
| (since C++14) | |||
(3) | ||||
| (since C++11) (until C++14) | |||
| (since C++14) | |||
| (4) | (since C++17) | ||
| (5) | (since C++14) | ||
| (6) | (since C++14) | ||
| (7) | (since C++14) | ||
| (8) | (since C++17) |
1-4) Extracts the
Ith
element from the tuple. I
is an integer value in [0, sizeof...(Types))
. 5-8) Extracts the element of the tuple
t
whose type is T
. Fails to compile if the tuple has more than one element of that type.Parameters
t | - | tuple whose contents to extract |
Return value
A reference to the selected element of t
.
Exceptions
noexcept
specification: noexcept
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #include <iostream> #include <string> #include <tuple> int main() { auto t = std::make_tuple(1, "Foo" , 3.14); // index-based access std::cout << "(" << std::get<0>(t) << ", " << std::get<1>(t) << ", " << std::get<2>(t) << ")\n" ; // type-based access std::cout << "(" << std::get< int >(t) << ", " << std::get< const char *>(t) << ", " << std::get< double >(t) << ")\n" ; } |
Output:
1 2 | (1, Foo, 3.14) (1, Foo, 3.14) |
See also
accesses an element of an array (function template) | |
(C++11) | accesses an element of a pair (function template) |
Please login to continue.