1-4) Extracts the Ith element from the tuple. I must be an integer value in [
â0â,
sizeof...(Types))
.
5-8) Extracts the element of the tuple t whose type is T
. Fails to compile unless the tuple has exactly one element of that type.
A reference to the selected element of t.
[edit] Notes [edit] Example#include <cassert> #include <iostream> #include <string> #include <tuple> int main() { auto x = std::make_tuple(1, "Foo", 3.14); // Index-based access std::cout << "( " << std::get<0>(x) << ", " << std::get<1>(x) << ", " << std::get<2>(x) << " )\n"; // Type-based access (since C++14) std::cout << "( " << std::get<int>(x) << ", " << std::get<const char*>(x) << ", " << std::get<double>(x) << " )\n"; const std::tuple<int, const int, double, double> y(1, 2, 6.9, 9.6); const int& i1 = std::get<int>(y); // OK: not ambiguous assert(i1 == 1); const int& i2 = std::get<const int>(y); // OK: not ambiguous assert(i2 == 2); // const double& d = std::get<double>(y); // Error: ill-formed (ambiguous) // Note: std::tie and structured binding can be // used to unpack a tuple into individual objects. }
Output:
( 1, Foo, 3.14 ) ( 1, Foo, 3.14 )[edit] Defect reports
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 (by index)RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4