---
name: "std::pair"
section: "3cxx"
platform: "linux"
package: "libstdc++-12-doc"
version: "12.4.0-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/std::pair/3cxx"
---

# std::pair(3cxx)

Struct holding two objects of arbitrary type.

## NAME

std::pair\< \_T1, \_T2 \> - Struct holding two objects of arbitrary type.

## SYNOPSIS

`#include <utility>`

Inherits \_\_pair\_base\< \_T1, \_T2 \>.

### Public Types

**typedef** \_T1 **first\_type**\
 The type of the `first` member.  **typedef** \_T2 **second\_type**\
 The type of the `second` member.

### Public Member Functions

template\<**typename** **\_U1**  = \_T1, **typename** **\_U2**  = \_T2, **typename** **enable\_if**\< \_\_and\_\< \_\_is\_implicitly\_default\_constructible\< **\_U1** \>, \_\_is\_implicitly\_default\_constructible\< **\_U2** \> \> ::value, bool \>::type  = true\> constexpr **pair** ()\
 template\<**typename** **\_U2** , **\_\_enable\_if\_t**\< \_\_and\_\< **is\_pointer**\< \_T1 \>, \_\_not\_\< **is\_reference**\< **\_U2** \> \>, **is\_constructible**\< \_T2, **\_U2** \>, \_\_not\_\< **is\_constructible**\< \_T2, const **\_U2** & \> \>, **is\_convertible**\< **\_U2**, \_T2 \> \>::value, bool \>  = true\> constexpr **pair** (**\_\_zero\_as\_null\_pointer\_constant**, **\_U2** &&\_\_y,...)\
 template\<**typename** **\_U2** , **\_\_enable\_if\_t**\< \_\_and\_\< **is\_pointer**\< \_T1 \>, \_\_not\_\< **is\_reference**\< **\_U2** \> \>, **is\_constructible**\< \_T2, **\_U2** \>, \_\_not\_\< **is\_constructible**\< \_T2, const **\_U2** & \> \>, \_\_not\_\< **is\_convertible**\< **\_U2**, \_T2 \> \> \>::value, bool \>  = false\> constexpr **pair** (**\_\_zero\_as\_null\_pointer\_constant**, **\_U2** &&\_\_y,...)\
 template\<**typename** **\_U1** , **\_\_enable\_if\_t**\< \_\_and\_\< \_\_not\_\< **is\_reference**\< **\_U1** \> \>, **is\_pointer**\< \_T2 \>, **is\_constructible**\< \_T1, **\_U1** \>, \_\_not\_\< **is\_constructible**\< \_T1, const **\_U1** & \> \>, **is\_convertible**\< **\_U1**, \_T1 \> \>::value, bool \>  = true\> constexpr **pair** (**\_U1** &&\_\_x, **\_\_zero\_as\_null\_pointer\_constant**,...)\
 template\<**typename** **\_U1** , **\_\_enable\_if\_t**\< \_\_and\_\< \_\_not\_\< **is\_reference**\< **\_U1** \> \>, **is\_pointer**\< \_T2 \>, **is\_constructible**\< \_T1, **\_U1** \>, \_\_not\_\< **is\_constructible**\< \_T1, const **\_U1** & \> \>, \_\_not\_\< **is\_convertible**\< **\_U1**, \_T1 \> \> \>::value, bool \>  = false\> constexpr **pair** (**\_U1** &&\_\_x, **\_\_zero\_as\_null\_pointer\_constant**,...)\
 template\<**typename** **\_U1** , **typename** **\_U2** , **typename** **enable\_if**\< \_PCCP::template **\_MoveConstructiblePair**\< **\_U1**, **\_U2** \>() &&\_PCCP::template **\_ImplicitlyMoveConvertiblePair**\< **\_U1**, **\_U2** \>(), bool \>::type  = true\> constexpr **pair** (**\_U1** &&\_\_x, **\_U2** &&\_\_y)\
 template\<**typename** **\_U1** , **typename** **\_U2** , **typename** **enable\_if**\< \_PCCP::template **\_MoveConstructiblePair**\< **\_U1**, **\_U2** \>() &&!\_PCCP::template **\_ImplicitlyMoveConvertiblePair**\< **\_U1**, **\_U2** \>(), bool \>::type  = false\> constexpr **pair** (**\_U1** &&\_\_x, **\_U2** &&\_\_y)\
 template\<**typename** **\_U1**  = \_T1, **typename** **\_U2**  = \_T2, **typename** **enable\_if**\< \_PCCP::template **\_ConstructiblePair**\< **\_U1**, **\_U2** \>() &&\_PCCP::template **\_ImplicitlyConvertiblePair**\< **\_U1**, **\_U2** \>(), bool \>::type  = true\> constexpr **pair** (const \_T1 &\_\_a, const \_T2 &\_\_b)\
 Construct from two const lvalues, allowing implicit conversions.  template\<**typename** **\_U1**  = \_T1, **typename** **\_U2**  = \_T2, **typename** **enable\_if**\< \_PCCP::template **\_ConstructiblePair**\< **\_U1**, **\_U2** \>() &&!\_PCCP::template **\_ImplicitlyConvertiblePair**\< **\_U1**, **\_U2** \>(), bool \>::type  = false\> constexpr **pair** (const \_T1 &\_\_a, const \_T2 &\_\_b)\
 Construct from two const lvalues, disallowing implicit conversions.  constexpr **pair** (const **pair** &)=**default**\
 Copy constructor.  template\<**typename** **\_U1** , **typename** **\_U2** , **typename** **enable\_if**\< **\_PCCFP**\< **\_U1**, **\_U2** \>::template **\_ConstructiblePair**\< **\_U1**, **\_U2** \>() &&**\_PCCFP**\< **\_U1**, **\_U2** \>::template **\_ImplicitlyConvertiblePair**\< **\_U1**, **\_U2** \>(), bool \>::type  = true\> constexpr **pair** (const **pair**\< **\_U1**, **\_U2** \> &\_\_p)\
 template\<**typename** **\_U1** , **typename** **\_U2** , **typename** **enable\_if**\< **\_PCCFP**\< **\_U1**, **\_U2** \>::template **\_ConstructiblePair**\< **\_U1**, **\_U2** \>() &&!**\_PCCFP**\< **\_U1**, **\_U2** \>::template **\_ImplicitlyConvertiblePair**\< **\_U1**, **\_U2** \>(), bool \>::type  = false\> constexpr **pair** (const **pair**\< **\_U1**, **\_U2** \> &\_\_p)\
 constexpr **pair** (**pair** &&)=**default**\
 Move constructor.  template\<**typename** **\_U1** , **typename** **\_U2** , **typename** **enable\_if**\< **\_PCCFP**\< **\_U1**, **\_U2** \>::template **\_MoveConstructiblePair**\< **\_U1**, **\_U2** \>() &&**\_PCCFP**\< **\_U1**, **\_U2** \>::template **\_ImplicitlyMoveConvertiblePair**\< **\_U1**, **\_U2** \>(), bool \>::type  = true\> constexpr **pair** (**pair**\< **\_U1**, **\_U2** \> &&\_\_p)\
 template\<**typename** **\_U1** , **typename** **\_U2** , **typename** **enable\_if**\< **\_PCCFP**\< **\_U1**, **\_U2** \>::template **\_MoveConstructiblePair**\< **\_U1**, **\_U2** \>() &&!**\_PCCFP**\< **\_U1**, **\_U2** \>::template **\_ImplicitlyMoveConvertiblePair**\< **\_U1**, **\_U2** \>(), bool \>::type  = false\> constexpr **pair** (**pair**\< **\_U1**, **\_U2** \> &&\_\_p)\
 template\<typename... \_Args1, typename... \_Args2\> constexpr **pair** (**piecewise\_construct\_t**, **tuple**\< \_Args1... \>, **tuple**\< \_Args2... \>)\
 **pair** & **operator=** (\_\_conditional\_t\< \_\_and\_\< **is\_copy\_assignable**\< \_T1 \>, **is\_copy\_assignable**\< \_T2 \> \>::value, const **pair** &, const **\_\_nonesuch** & \> \_\_p)\
 **pair** & **operator=** (\_\_conditional\_t\< \_\_and\_\< **is\_move\_assignable**\< \_T1 \>, **is\_move\_assignable**\< \_T2 \> \>::value, **pair** &&, **\_\_nonesuch** && \> \_\_p) noexcept(\_\_and\_\< **is\_nothrow\_move\_assignable**\< \_T1 \>, **is\_nothrow\_move\_assignable**\< \_T2 \> \>::value)\
 template\<**typename** **\_U1** , **typename** **\_U2** \> **enable\_if**\< \_\_and\_\< **is\_assignable**\< \_T1 &, **const\_U1** & \>, **is\_assignable**\< \_T2 &, **const\_U2** & \> \>::value, **pair** & \>::type **operator=** (const **pair**\< **\_U1**, **\_U2** \> &\_\_p)\
 template\<**typename** **\_U1** , **typename** **\_U2** \> **enable\_if**\< \_\_and\_\< **is\_assignable**\< \_T1 &, **\_U1** && \>, **is\_assignable**\< \_T2 &, **\_U2** && \> \>::value, **pair** & \>::type **operator=** (**pair**\< **\_U1**, **\_U2** \> &&\_\_p)\
 constexpr **void** **swap** (**pair** &\_\_p) noexcept(\_\_and\_\< **\_\_is\_nothrow\_swappable**\< \_T1 \>, **\_\_is\_nothrow\_swappable**\< \_T2 \> \>::value)\
 Swap the first members and then the second members.

### Public Attributes

\_T1 **first**\
 The first member.  \_T2 **second**\
 The second member.

### Related Symbols

(Note that these are not member symbols.)  template\<**typename** \_T1 , **typename** \_T2 \> constexpr **pair**\< **typename** **\_\_decay\_and\_strip**\< \_T1 \>::\_\_type, **typename** **\_\_decay\_and\_strip**\< \_T2 \>::\_\_type \> **make\_pair** (\_T1 &&\_\_x, \_T2 &&\_\_y)\
 A convenience wrapper for creating a pair from two objects.

template\<**typename** \_T1 , **typename** \_T2 \> **pair** (\_T1, \_T2) -\> **pair**\< \_T1, \_T2 \>\
 Two pairs of the same type are equal iff their members are equal.  template\<**typename** \_T1 , **typename** \_T2 \> constexpr bool **operator==** (const **pair**\< \_T1, \_T2 \> &\_\_x, const **pair**\< \_T1, \_T2 \> &\_\_y)\
 Two pairs of the same type are equal iff their members are equal.  template\<**typename** \_T1 , **typename** \_T2 \> constexpr bool **operator\<** (const **pair**\< \_T1, \_T2 \> &\_\_x, const **pair**\< \_T1, \_T2 \> &\_\_y)\
 template\<**typename** \_T1 , **typename** \_T2 \> constexpr bool **operator!=** (const **pair**\< \_T1, \_T2 \> &\_\_x, const **pair**\< \_T1, \_T2 \> &\_\_y)\
 Uses `operator==` to find the result.  template\<**typename** \_T1 , **typename** \_T2 \> constexpr bool **operator\>** (const **pair**\< \_T1, \_T2 \> &\_\_x, const **pair**\< \_T1, \_T2 \> &\_\_y)\
 Uses `operator<` to find the result.  template\<**typename** \_T1 , **typename** \_T2 \> constexpr bool **operator\<=** (const **pair**\< \_T1, \_T2 \> &\_\_x, const **pair**\< \_T1, \_T2 \> &\_\_y)\
 Uses `operator<` to find the result.  template\<**typename** \_T1 , **typename** \_T2 \> constexpr bool **operator\>=** (const **pair**\< \_T1, \_T2 \> &\_\_x, const **pair**\< \_T1, \_T2 \> &\_\_y)\
 Uses `operator<` to find the result.  template\<**typename** \_T1 , **typename** \_T2 \> constexpr **enable\_if**\< \_\_and\_\< **\_\_is\_swappable**\< \_T1 \>, **\_\_is\_swappable**\< \_T2 \> \>::value \>::type **swap** (**pair**\< \_T1, \_T2 \> &\_\_x, **pair**\< \_T1, \_T2 \> &\_\_y) noexcept(noexcept(\_\_x.swap(\_\_y)))\

## Detailed Description

### template\<typename \_T1, typename \_T2\>

struct std::pair\< \_T1, \_T2 \>"Struct holding two objects of arbitrary type.

**Template Parameters**

*\_T1* Type of first object. \
 *\_T2* Type of second object.

https://gcc.gnu.org/onlinedocs/libstdc++/manual/utilities.html

## Member Typedef Documentation

### template\<typename \_T1 , typename \_T2 \> typedef \_T1 std::pair\< \_T1, \_T2 \>::first\_type

The type of the `first` member.

### template\<typename \_T1 , typename \_T2 \> typedef \_T2 std::pair\< \_T1, \_T2 \>::second\_type

The type of the `second` member.

## Constructor & Destructor Documentation

### template\<typename \_T1 , typename \_T2 \> constexpr std::pair\< \_T1, \_T2 \>::pair (const pair\< \_T1, \_T2 \> &)` [constexpr]`, ` [default]`

Copy constructor.

### template\<typename \_T1 , typename \_T2 \> constexpr std::pair\< \_T1, \_T2 \>::pair (pair\< \_T1, \_T2 \> &&)` [constexpr]`, ` [default]`

Move constructor.

### template\<typename \_T1 , typename \_T2 \> template\<typename \_U1 = \_T1, typename \_U2 = \_T2, typename enable\_if\< \_\_and\_\< \_\_is\_implicitly\_default\_constructible\< \_U1 \>, \_\_is\_implicitly\_default\_constructible\< \_U2 \> \> ::value, bool \>::type = true\> constexpr std::pair\< \_T1, \_T2 \>::pair ()` [inline]`, ` [constexpr]`

The default constructor creates `first` and `second` using their respective default constructors. \

### template\<typename \_T1 , typename \_T2 \> template\<typename \_U1 = \_T1, typename \_U2 = \_T2, typename enable\_if\< \_PCCP::template \_ConstructiblePair\< \_U1, \_U2 \>() &&\_PCCP::template \_ImplicitlyConvertiblePair\< \_U1, \_U2 \>(), bool \>::type = true\> constexpr std::pair\< \_T1, \_T2 \>::pair (const \_T1 & \_\_a, const \_T2 & \_\_b)` [inline]`, ` [constexpr]`

Construct from two const lvalues, allowing implicit conversions.

### template\<typename \_T1 , typename \_T2 \> template\<typename \_U1 = \_T1, typename \_U2 = \_T2, typename enable\_if\< \_PCCP::template \_ConstructiblePair\< \_U1, \_U2 \>() &&!\_PCCP::template \_ImplicitlyConvertiblePair\< \_U1, \_U2 \>(), bool \>::type = false\> constexpr std::pair\< \_T1, \_T2 \>::pair (const \_T1 & \_\_a, const \_T2 & \_\_b)` [inline]`, ` [explicit]`, ` [constexpr]`

Construct from two const lvalues, disallowing implicit conversions.

## Member Function Documentation

### template\<typename \_T1 , typename \_T2 \> constexpr void std::pair\< \_T1, \_T2 \>::swap (pair\< \_T1, \_T2 \> & \_\_p)` [inline]`, ` [constexpr]`, ` [noexcept]`

Swap the first members and then the second members.

References **std::pair\< \_T1, \_T2 \>::first**, **std::pair\< \_T1, \_T2 \>::second**, **std::swap()**, and **std::pair\< \_T1, \_T2 \>::swap()**.

Referenced by **std::pair\< \_T1, \_T2 \>::swap()**, and **std::sub\_match\< \_BiIter \>::swap()**.

## Member Data Documentation

### template\<typename \_T1 , typename \_T2 \> \_T1 std::pair\< \_T1, \_T2 \>::first

The first member.

Referenced by **std::pair\< \_T1, \_T2 \>::swap()**.

### template\<typename \_T1 , typename \_T2 \> \_T2 std::pair\< \_T1, \_T2 \>::second

The second member.

Referenced by **std::pair\< \_T1, \_T2 \>::swap()**.

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
