##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::pair

From cppreference.com
< cpp‎ | utility

Defined in header `<utility>` |  |
template< class T1, class T2 > struct pair; |  |

`std::pair` is a struct template that provides a way to store two heterogeneous objects as a single unit. A pair is a specific case of a std::tuple with two elements.

If std::is_trivially_destructible_v<T1> && std::is_trivially_destructible_v<T2> is true, the destructor of `pair` is trivial. | (since C++17)

### [edit] Template parameters

T1, T2 | - | the types of the elements that the pair stores.

### [edit] Member types

Member type | Definition
`first_type` | `T1`
`second_type` | `T2`

### [edit] Member objects

Member name | Type
`first` | `T1`
`second` | `T2`

### [edit] Member functions

(constructor) | constructs new pair (public member function)
operator= | assigns the contents (public member function)
swap (C++11) | swaps the contents (public member function)

### [edit] Non-member functions

make_pair | creates a `pair` object of type, defined by the argument types (function template) [edit]
operator==operator!=operator<operator<=operator>operator>= | lexicographically compares the values in the pair (function template) [edit]
std::swap(std::pair) (C++11) | specializes the std::swap algorithm (function template) [edit]
std::get(std::pair) (C++11) | accesses an element of a `pair` (function template) [edit]

### [edit] Helper classes

std::tuple_size<std::pair> (C++11) | obtains the size of a `pair` (class template specialization) [edit]
std::tuple_element<std::pair> (C++11) | obtains the type of the elements of `pair` (class template specialization) [edit]

### [edit] See also

tuple (C++11) | implements fixed size container, which holds elements of possibly different types (class template) [edit]
tie | creates a `tuple` of lvalue references or unpacks a tuple into individual objects (function template) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/utility/pair&oldid=91974"