---
name: "std::pair"
section: "3"
platform: "linux"
package: "gcc"
version: "16.2.1+r23+gd564253eb6c8-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/std::pair"
---

# std::pair(3)

Struct holding two objects (or references) of arbitrary type.

## NAME

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

## SYNOPSIS

\#include \<utility\>

### 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

constexpr **pair** (const pair &)=default\
 Copy constructor.  constexpr **pair** (pair &&)=default\
 Move constructor.  template\<typename... \_Args1, typename... \_Args2\> constexpr **pair** (**piecewise\_construct\_t**, **tuple**\< \_Args1... \>, **tuple**\< \_Args2... \>)\
 template\<typename \_U1, typename \_U2\> constexpr **explicit** (!\_S\_convertible\< \_U1 &, \_U2 & \>()) **pair**(**pair**\< \_U1\
 template\<typename \_U1, typename \_U2\> constexpr \_U2 &&constexpr **explicit** (!\_S\_convertible\< \_U1 &, \_U2 & \>()) **pair**(**pair**\< \_U1\
 Converting constructor from a non-const pair\<U1, U2\> lvalue.  template\<typename \_U1 = \_T1, typename \_U2 = \_T2\> constexpr **explicit** (!\_S\_convertible\< \_U1, \_U2 \>()) **pair**(\_U1 &&\
 template\<typename \_U1 = \_T1, typename \_U2 = \_T2\> constexpr **explicit** (!\_S\_convertible\< \_U1, \_U2 \>()) **pair**(\_U1 &&\_\_x\
 Constructor accepting two values of arbitrary types.  template\<typename \_U1, typename \_U2\> constexpr **explicit** (!\_S\_convertible\< \_U1, \_U2 \>()) **pair**(**pair**\< \_U1\
 template\<typename \_U1, typename \_U2\> constexpr \_U2 &constexpr **explicit** (!\_S\_convertible\< \_U1, \_U2 \>()) **pair**(**pair**\< \_U1\
 Converting constructor from a non-const pair\<U1, U2\> rvalue.  constexpr **explicit** (!\_S\_convertible\< const \_T1 &, const \_T2 & \>()) **pair**(const type\_identity\_t\< \_T1 \> &\_\_x\
 Constructor accepting lvalues of first\_type and second\_type.  template\<typename \_U1, typename \_U2\> constexpr **explicit** (!\_S\_convertible\< const \_U1 &, const \_U2 & \>()) **pair**(const **pair**\< \_U1\
 template\<typename \_U1, typename \_U2\> constexpr \_U2 &&constexpr **explicit** (!\_S\_convertible\< const \_U1 &, const \_U2 & \>()) **pair**(const **pair**\< \_U1\
 Converting constructor from a const pair\<U1, U2\> lvalue.  template\<typename \_U1, typename \_U2\> constexpr **explicit** (!\_S\_convertible\< const \_U1, const \_U2 \>()) **pair**(const **pair**\< \_U1\
 template\<typename \_U1, typename \_U2\> constexpr \_U2 &constexpr **explicit** (!\_S\_convertible\< const \_U1, const \_U2 \>()) **pair**(const **pair**\< \_U1\
 Converting constructor from a const pair\<U1, U2\> rvalue.  template\<\_\_eligible\_pair\_like\< **pair** \> \_UPair\> constexpr **explicit** (!\_S\_convertible\_from\_pair\_like\< \_UPair \>()) **pair**(\_UPair &&)=delete\
 template\<\_\_eligible\_pair\_like\< **pair** \> \_UPair\> constexpr \_U2 &&constexpr **explicit** (!\_S\_convertible\_from\_pair\_like\< \_UPair \>()) **pair**(\_UPair &&\_\_p)\
 constexpr **explicit** (\_\_not\_\< \_\_and\_\< \_\_is\_implicitly\_default\_constructible\< \_T1 \>, \_\_is\_implicitly\_default\_constructible\< \_T2 \> \> \>()) **pair**() noexcept(is\_nothrow\_default\_constructible\_v\< \_T1 \> &&is\_nothrow\_default\_constructible\_v\< \_T2 \>)\
 Default constructor.  constexpr \_U2 &&constexpr \_U2 &\_\_p **noexcept** (\_S\_nothrow\_constructible\< \_U1 &, \_U2 & \>())\
 constexpr \_U2 &constexpr \_U2 &&\_\_p **noexcept** (\_S\_nothrow\_constructible\< \_U1, \_U2 \>())\
 constexpr \_U2 &&\_\_y **noexcept** (\_S\_nothrow\_constructible\< \_U1, \_U2 \>())\
 constexpr const \_T2 &\_\_y **noexcept** (\_S\_nothrow\_constructible\< const \_T1 &, const \_T2 & \>())\
 constexpr \_U2 &&constexpr \_U2 &\_\_p **noexcept** (\_S\_nothrow\_constructible\< const \_U1 &, const \_U2 & \>())\
 constexpr \_U2 &constexpr \_U2 &&\_\_p **noexcept** (\_S\_nothrow\_constructible\< const \_U1, const \_U2 \>())\
 template\<\_\_eligible\_pair\_like\< **pair** \> \_UPair\> constexpr **pair** & **operator=** (\_UPair &&\_\_p)\
 template\<\_\_eligible\_pair\_like\< **pair** \> \_UPair\> constexpr const **pair** & **operator=** (\_UPair &&\_\_p) const\
 **pair** & **operator=** (const **pair** &)=delete\
 constexpr const **pair** & **operator=** (const **pair** &\_\_p) const\
 Copy assignment operator (const).  constexpr **pair** & **operator=** (const **pair** &\_\_p) noexcept(\_S\_nothrow\_assignable\< const \_T1 &, const \_T2 & \>())\
 Copy assignment operator.  template\<typename \_U1, typename \_U2\> \
 requires (\_S\_const\_assignable\<const \_U1&, const \_U2&\>())constexpr const **pair** & **operator=** (const **pair**\< \_U1, \_U2 \> &\_\_p) const"\
 Converting assignment from a const pair\<U1, U2\> lvalue.  template\<typename \_U1, typename \_U2\> \
 requires (\_S\_assignable\<const \_U1&, const \_U2&\>())constexpr **pair** & **operator=** (const **pair**\< \_U1, \_U2 \> &\_\_p) noexcept(\_S\_nothrow\_assignable\< const \_U1 &, const \_U2 & \>())"\
 Converting assignment from a const pair\<U1, U2\> lvalue.  constexpr const **pair** & **operator=** (**pair** &&\_\_p) const\
 Move assignment operator (const).  constexpr **pair** & **operator=** (**pair** &&\_\_p) noexcept(\_S\_nothrow\_assignable\< \_T1, \_T2 \>())\
 Move assignment operator.  template\<typename \_U1, typename \_U2\> \
 requires (\_S\_const\_assignable\<\_U1, \_U2\>())constexpr const **pair** & **operator=** (**pair**\< \_U1, \_U2 \> &&\_\_p) const"\
 Converting assignment from a non-const pair\<U1, U2\> rvalue.  template\<typename \_U1, typename \_U2\> \
 requires (\_S\_assignable\<\_U1, \_U2\>())constexpr **pair** & **operator=** (**pair**\< \_U1, \_U2 \> &&\_\_p) noexcept(\_S\_nothrow\_assignable\< \_U1, \_U2 \>())"\
 Converting assignment from a non-const pair\<U1, U2\> rvalue.  constexpr void **swap** (const **pair** &\_\_p) const noexcept(\_\_and\_v\< \_\_is\_nothrow\_swappable\< const \_T1 \>, \_\_is\_nothrow\_swappable\< const \_T2 \> \>)\
 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\> **pair** (\_T1, \_T2) -\> pair\< \_T1, \_T2 \>\
 Two pairs are equal iff their members are equal.  template\<typename \_T1, typename \_T2, typename \_U1, typename \_U2\> constexpr bool **operator==** (const **pair**\< \_T1, \_T2 \> &\_\_x, const **pair**\< \_U1, \_U2 \> &\_\_y)\
 Two pairs are equal iff their members are equal.  template\<typename \_T1, typename \_T2, typename \_U1, typename \_U2\> constexpr common\_comparison\_category\_t\< \_\_detail::\_\_synth3way\_t\< \_T1, \_U1 \>, \_\_detail::\_\_synth3way\_t\< \_T2, \_U2 \> \> **operator\<=\>** (const **pair**\< \_T1, \_T2 \> &\_\_x, const **pair**\< \_U1, \_U2 \> &\_\_y)\
 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 (or references) of arbitrary type.

**Template Parameters**

*\_T1* Type of the first member. \
 *\_T2* Type of the second member.

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\> std::pair\< \_T1, \_T2 \>::pair (const pair\< \_T1, \_T2 \> & ) \[constexpr\], \[default\]

Copy constructor.

Referenced by **pair()**.

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

Move constructor.

## Member Function Documentation

### template\<typename \_T1, typename \_T2\> template\<typename \_U1, typename \_U2\> \_U2 &&constexpr std::pair\< \_T1, \_T2 \>::explicit (!\_S\_convertible\< \_U1 &, \_U2 & \> ()) \[constexpr\]

Converting constructor from a non-const pair\<U1, U2\> lvalue.

### template\<typename \_T1, typename \_T2\> template\<typename \_U1 = \_T1, typename \_U2 = \_T2\> std::pair\< \_T1, \_T2 \>::explicit (!\_S\_convertible\< \_U1, \_U2 \> ()) && \[constexpr\]

Constructor accepting two values of arbitrary types.

### template\<typename \_T1, typename \_T2\> template\<typename \_U1, typename \_U2\> \_U2 &constexpr std::pair\< \_T1, \_T2 \>::explicit (!\_S\_convertible\< \_U1, \_U2 \> ()) \[constexpr\]

Converting constructor from a non-const pair\<U1, U2\> rvalue.

### template\<typename \_T1, typename \_T2\> std::pair\< \_T1, \_T2 \>::explicit (!\_S\_convertible\< const \_T1 &, const \_T2 & \> ()) const & \[constexpr\]

Constructor accepting lvalues of first\_type and second\_type.

### template\<typename \_T1, typename \_T2\> template\<typename \_U1, typename \_U2\> \_U2 &&constexpr std::pair\< \_T1, \_T2 \>::explicit (!\_S\_convertible\< const \_U1 &, const \_U2 & \> ()) const \[constexpr\]

Converting constructor from a const pair\<U1, U2\> lvalue.

### template\<typename \_T1, typename \_T2\> template\<typename \_U1, typename \_U2\> \_U2 &constexpr std::pair\< \_T1, \_T2 \>::explicit (!\_S\_convertible\< const \_U1, const \_U2 \> ()) const \[constexpr\]

Converting constructor from a const pair\<U1, U2\> rvalue.

### template\<typename \_T1, typename \_T2\> std::pair\< \_T1, \_T2 \>::explicit (\_\_not\_\< \_\_and\_\< \_\_is\_implicitly\_default\_constructible\< \_T1 \>, \_\_is\_implicitly\_default\_constructible\< \_T2 \> \> \> ()) \[inline\], \[constexpr\], \[noexcept\]

Default constructor.

### template\<typename \_T1, typename \_T2\> const pair & std::pair\< \_T1, \_T2 \>::operator= (const pair\< \_T1, \_T2 \> & \_\_p) const \[inline\], \[constexpr\]

Copy assignment operator (const).

### template\<typename \_T1, typename \_T2\> pair & std::pair\< \_T1, \_T2 \>::operator= (const pair\< \_T1, \_T2 \> & \_\_p) \[inline\], \[constexpr\], \[noexcept\]

Copy assignment operator.

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

requires (\_S\_const\_assignable\<const \_U1&, const \_U2&\>())const **pair** & **std::pair**\< \_T1, \_T2 \>::operator= (const **pair**\< \_U1, \_U2 \> & \_\_p) const \[inline\],  \[constexpr\]"

Converting assignment from a const pair\<U1, U2\> lvalue.

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

requires (\_S\_assignable\<const \_U1&, const \_U2&\>())**pair** & **std::pair**\< \_T1, \_T2 \>::operator= (const **pair**\< \_U1, \_U2 \> & \_\_p) \[inline\],  \[constexpr\],  \[noexcept\]"

Converting assignment from a const pair\<U1, U2\> lvalue.

### template\<typename \_T1, typename \_T2\> const pair & std::pair\< \_T1, \_T2 \>::operator= (pair\< \_T1, \_T2 \> && \_\_p) const \[inline\], \[constexpr\]

Move assignment operator (const).

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

Move assignment operator.

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

requires (\_S\_const\_assignable\<\_U1, \_U2\>())const **pair** & **std::pair**\< \_T1, \_T2 \>::operator= (**pair**\< \_U1, \_U2 \> && \_\_p) const \[inline\],  \[constexpr\]"

Converting assignment from a non-const pair\<U1, U2\> rvalue.

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

requires (\_S\_assignable\<\_U1, \_U2\>())**pair** & **std::pair**\< \_T1, \_T2 \>::operator= (**pair**\< \_U1, \_U2 \> && \_\_p) \[inline\],  \[constexpr\],  \[noexcept\]"

Converting assignment from a non-const pair\<U1, U2\> rvalue.

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

Swap the first members and then the second members.

Referenced by **std::pair\< const \_\_iter\_key\_t\< \_InputIterator \>, \_\_iter\_val\_t\< \_InputIterator \> \>::swap()**, **std::sub\_match\< const char \* \>::swap()**, and **std::swap()**.

## Member Data Documentation

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

The first member.

Referenced by **\_\_gnu\_parallel::\_\_find\_template()**, **\_\_gnu\_parallel::\_\_find\_template()**, **std::\_\_sample()**, **std::set\< \_Key, \_Cmp, polymorphic\_allocator\< \_Key \> \>::insert()**, **std::pair\< const \_\_iter\_key\_t\< \_InputIterator \>, \_\_iter\_val\_t\< \_InputIterator \> \>::operator\<=\>()**, **std::pair\< const \_\_iter\_key\_t\< \_InputIterator \>, \_\_iter\_val\_t\< \_InputIterator \> \>::operator==()**, and **std::shuffle()**.

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

The second member.

Referenced by **std::\_\_sample()**, **std::set\< \_Key, \_Cmp, polymorphic\_allocator\< \_Key \> \>::insert()**, **std::pair\< const \_\_iter\_key\_t\< \_InputIterator \>, \_\_iter\_val\_t\< \_InputIterator \> \>::operator\<=\>()**, **std::pair\< const \_\_iter\_key\_t\< \_InputIterator \>, \_\_iter\_val\_t\< \_InputIterator \> \>::operator==()**, and **std::shuffle()**.

## Author

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