Defined in header <utility> | ||||
---|---|---|---|---|
(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) | ||
| (9) | (since C++14) | ||
| (10) | (since C++14) | ||
| (11) | (since C++14) | ||
| (12) | (since C++17) |
Extracts an element from the pair using tuple-like interface.
The index-based overloads (1-4) fail to compile if the index N
is neither 0 nor 1.
The type-based overloads (5-12) fail to compile if the types T
and U
are the same.
Parameters
p | - | pair whose contents to extract |
Return value
1-4) Returns a reference to
p.first
if N==0
and a reference to p.second
if N==1
. 5-8) Returns a reference to
p.first
. 9-12) Returns a reference to
p.second
.Exceptions
noexcept
specification: noexcept
Example
1 2 3 4 5 6 7 8 9 | #include <iostream> #include <utility> int main() { auto p = std::make_pair(1, 3.14); std::cout << '(' << std::get<0>(p) << ", " << std::get<1>(p) << ")\n" ; std::cout << '(' << std::get< int >(p) << ", " << std::get< double >(p) << ")\n" ; } |
Output:
1 2 | (1, 3.14) (1, 3.14) |
See also
tuple accesses specified element (function template) | |
accesses an element of an array (function template) |
Please login to continue.