Namespaces
Variants
Views
Actions

std::pair

From cppreference.com
< cpp‎ | utility
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
pair
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

Elementary string conversions
(C++17)
(C++17)
 
std::pair
Member functions
Non-member functions
(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20)
(C++11)
Deduction guides(C++17)
Helper classes
(C++11)
 
Defined in header <utility>
template<

    class T1,
    class T2

> struct pair;

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 a std::tuple with two elements.

If neither T1 nor T2 is a possibly cv-qualified class type with non-trivial destructor, or array thereof, the destructor of pair is trivial.

Contents

[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

constructs new pair
(public member function)
assigns the contents
(public member function)
(C++11)
swaps the contents
(public member function)

[edit] Non-member functions

creates a pair object of type, defined 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 the pair
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]
accesses an element of a pair
(function template) [edit]

[edit] Helper classes

obtains the size of a pair
(class template specialization) [edit]
obtains the type of the elements of pair
(class template specialization) [edit]

[edit] Deduction guides(since C++17)

[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 2796 C++98 triviality of the destructor of pair was unspecified specified

[edit] See also

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