|
|
Member functions | ||||
(C++11) | ||||
Non-member functions | ||||
(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20) | ||||
(C++11) | ||||
(C++11) | ||||
Helper classes | ||||
(C++11) | ||||
(C++11) | ||||
(C++23) | ||||
(C++23) | ||||
(C++11) | ||||
Deduction guides(C++17) |
Defined in header <utility> | ||
template< class T1, | ||
std::pair
is a class template that provides a way to store two heterogeneous objects as a single unit. A pair is a specific case of astd::tuple with two elements.
If neitherT1
norT2
is a possibly cv-qualified class type with non-trivial destructor, or array thereof, the destructor ofpair
is trivial.
Contents |
T1, T2 | - | the types of the elements that the pair stores. |
Member type | Definition |
first_type | T1 |
second_type | T2 |
Member name | Type |
first | T1 |
second | T2 |
constructs newpair (public member function)[edit] | |
assigns the contents (public member function)[edit] | |
(C++11) | swaps the contents (public member function)[edit] |
creates apair object of type, determined by the argument types(function template)[edit] | |
(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20) | lexicographically compares the values in thepair (function template)[edit] |
(C++11) | specializes thestd::swap algorithm (function template)[edit] |
(C++11) | accesses an element of apair (function template)[edit] |
(C++11) | obtains the size of apair (class template specialization)[edit] |
obtains the type of the elements ofpair (class template specialization)[edit] | |
determines the common reference type of twopair s(class template specialization)[edit] | |
(C++23) | determines the common type of twopair s(class template specialization)[edit] |
(C++23) | formatting support forpair (class template specialization)[edit] |
template<class T,class U> constexprbool enable_nonlocking_formatter_optimization<std::pair<T, U>>= | (since C++23) | |
This specialization ofstd::enable_nonlocking_formatter_optimization enables efficient implementation ofstd::print andstd::println for printing apair
object when bothT
andU
enable it.
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 2796 | C++98 | triviality of the destructor ofpair was unspecified | specified |
(C++11) | implements fixed size container, which holds elements of possibly different types (class template)[edit] |
(C++11) | creates atuple of lvalue references or unpacks a tuple into individual objects (function template)[edit] |