Ith
element from the tuple. I
must be an integer value in [0, sizeof...(Types))
.t
whose type is T
. Fails to compile unless the tuple has exactly one element of that type.t | - | tuple whose contents to extract |
A reference to the selected element of t
.
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 2485 | C++11 | there are no overloads for const tuple&& | the overloads are added |
#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"; // Note: std::tie and structured binding may also be used to decompose a tuple }
Output:
accesses an element of an array (function template) |
|
(C++11) | accesses an element of a pair (function template) |
(C++17) | reads the value of the variant given the index or the type (if the type is unique), throws on error (function template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/utility/tuple/get