STD::PAIR(3)

πŸ’– std::pair< _T1, _T2 >(3) πŸ’– β€” Library Functions Manual

okay bestie, come closer, we're doing the std::pair< _T1, _T2 > page from the Library Functions Manual and honestly? it's giving "two little guys in a trench coat" and I am obsessed 🫢. it's long, it's got so many constructors, and we're doing all of it. no skimming, no skipping, periodt ✨


🌸 NAME 🌸

std::pair< _T1, _T2 > β€” a struct holding two objects (or references) of arbitrary type. that's the whole concept bestie. two things. one struct. iconic πŸ’…


✨ 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. yes queen, copy it πŸ’–

constexpr pair (pair &&)=default

Move constructor. scoot over, we're moving πŸ›Ό

template<typename... _Args1, typename... _Args2> constexpr pair
    (piecewise_construct_t, tuple< _Args1... >, tuple< _Args2... >)

the piecewise-construct one. it takes a piecewise_construct_t and two tuples and just... does its thing ✨

template<typename _U1, typename _U2> constexpr explicit
    (!_S_convertible< _U1 &, _U2 & >()) pair(pair< _U1

part one of the non-const lvalue converting-constructor saga 🫠

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. that's the one, bestie 🎯

template<typename _U1 = _T1, typename _U2 = _T2> constexpr explicit
    (!_S_convertible< _U1, _U2 >()) pair(_U1 &&

setting up the two-arg one... 🧚

template<typename _U1 = _T1, typename _U2 = _T2> constexpr explicit
    (!_S_convertible< _U1, _U2 >()) pair(_U1 &&__x

Constructor accepting two values of arbitrary types. pick two types, any two, they're valid πŸ’–

template<typename _U1, typename _U2> constexpr explicit
    (!_S_convertible< _U1, _U2 >()) pair(pair< _U1

and another converting pair, this time the non-const rvalue setup 🌈

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. slay πŸƒβ€β™€οΈπŸ’¨

constexpr explicit (!_S_convertible< const _T1 &, const _T2 & >())
    pair(const type_identity_t< _T1 > &__x

Constructor accepting lvalues of first_type and second_type. the classics πŸŽ€

template<typename _U1, typename _U2> constexpr explicit
    (!_S_convertible< const _U1 &, const _U2 & >()) pair(const pair< _U1

const-lvalue converting constructor, warming up 🌸

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

and now the rvalue version of the const one, because of course there's more πŸ¦‹

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

this one is =deleted, so bestie, do not try it. it is not for you πŸ™ˆ

template<__eligible_pair_like< pair > _UPair> constexpr _U2 &&constexpr
    explicit (!_S_convertible_from_pair_like< _UPair >()) pair(_UPair
    &&__p)

the pair-like one that is actually available πŸ’«

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. look at that noexcept clause, she's doing the most and we love her for it πŸ‘‘

constexpr _U2 &&constexpr _U2 &__p noexcept (_S_nothrow_constructible<
    _U1 &, _U2 & >())

one of the internal lvalue-ish construction forms πŸ’…

constexpr _U2 &constexpr _U2 &&__p noexcept (_S_nothrow_constructible<
    _U1, _U2 >())

and the value-ish sibling of it ✨

constexpr _U2 &&__y noexcept (_S_nothrow_constructible< _U1, _U2 >())

the __y variant, because of course it has a __y 🌸

constexpr const _T2 &__y noexcept (_S_nothrow_constructible< const _T1
    &, const _T2 & >())

const-flavoured, still __y, still vibing πŸ“

constexpr _U2 &&constexpr _U2 &__p noexcept (_S_nothrow_constructible<
    const _U1 &, const _U2 & >())

const lvalue refs this time, she said variety πŸ’–

constexpr _U2 &constexpr _U2 &&__p noexcept (_S_nothrow_constructible<
    const _U1, const _U2 >())

and the last of that little cluster, const by value πŸ¦‹

template<__eligible_pair_like< pair > _UPair> constexpr pair & operator=
    (_UPair &&__p)

pair-like assignment, non-const edition πŸŽ€

template<__eligible_pair_like< pair > _UPair> constexpr const pair &
    operator= (_UPair &&__p) const

same energy but const, obviously ✨

pair & operator= (const pair &)=delete

deleted. nope. not happening bestie πŸ’€

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. the main-character copy assign 🫢

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. (const version) ⭐

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. (non-const version) πŸ”₯

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. (const version) 🌈

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. (non-const version) 🌈πŸ”₯

constexpr void swap (const pair &__p) const noexcept(__and_v<
    __is_nothrow_swappable< const _T1 >, __is_nothrow_swappable< const
    _T2 > >)

swap, but the const one 🧚

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. order matters bestie, first then second, always πŸ’…

🌟 Public Attributes 🌟

  • _T1 first β€” the first member πŸ₯‡
  • _T2 second β€” the second member πŸ₯ˆ
(Note that these are not member symbols.) β€” they're the friends of the family, okay? not members. don't @ me πŸ™ˆ
template<typename _T1, typename _T2> pair (_T1, _T2) -> pair< _T1,
    _T2 >

Two pairs are equal iff their members are equal. (yes, that's literally what it says for the deduction guide, we're just reporting the news bestie πŸ“°)

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. say it with me one more time for the people in the back πŸ—£οΈ

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)

the spaceship operator πŸš€ three-way comparison, synthesized, gorgeous ✨

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

free-function swap, enable_if'd and noexcept-checked, doing the absolute most 🫢


πŸ¦‹ Detailed Description πŸ¦‹

template<typename _T1, typename _T2>
    struct std::pair< _T1, _T2 >

Struct holding two objects (or references) of arbitrary type. that's the thesis statement bestie, everything else is decoration πŸ’–

🌸 Template Parameters 🌸

  • _T1 β€” type of the first member πŸ₯‡
  • _T2 β€” type of the second member πŸ₯ˆ

https://gcc.gnu.org/onlinedocs/libstdc++/manual/utilities.html β€” go read it, it's the source of truth, iykyk πŸ“š


πŸŽ€ 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. also flagged [default], and it's referenced by pair(). cute little family tree 🌳

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

Move constructor. also [default], also iconic, also moving out of your old place πŸ›Ό


and that's where part one runs out of page, bestie β€” hold that thought, there's more coming πŸ‘€

βœ¨πŸ’… Member Function Documentation πŸ’…βœ¨

Okay bestie, this is the main event. The member functions are here, and they're all about constructing, assigning, and swapping. No cap. πŸŽ€

  • Converting constructor from a non-const pair<U1, U2> lvalue.
   template<typename _T1, typename _T2> template<typename _U1, typename _U2>
       _U2 &&constexpr 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 = _T1, typename
       _U2 = _T2> 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> template<typename _U1, typename _U2>
       _U2 &constexpr std::pair< _T1, _T2 >::explicit (!_S_convertible< _U1,
       _U2 > ()) [constexpr]
  • Constructor accepting lvalues of first_type and second_type.
   template<typename _T1, typename _T2> std::pair< _T1, _T2 >::explicit
       (!_S_convertible< const _T1 &, const _T2 & > ()) 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> template<typename _U1, typename _U2>
       _U2 &constexpr std::pair< _T1, _T2 >::explicit (!_S_convertible< const
       _U1, const _U2 > ()) const [constexpr]
  • Default constructor.
   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]
  • Copy assignment operator (const).
   template<typename _T1, typename _T2> const pair & std::pair< _T1, _T2
       >::operator= (const pair< _T1, _T2 > & __p) const [inline],  [constexpr]
  • Copy assignment operator.
   template<typename _T1, typename _T2> pair & std::pair< _T1, _T2 >::operator=
       (const pair< _T1, _T2 > & __p) [inline],  [constexpr],  [noexcept]
  • Converting assignment from a const pair<U1, U2> lvalue.
   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]"
  • Move assignment operator (const).
   template<typename _T1, typename _T2> const pair & std::pair< _T1, _T2
       >::operator= (pair< _T1, _T2 > && __p) const [inline],  [constexpr]
  • Move assignment operator.
   template<typename _T1, typename _T2> pair & std::pair< _T1, _T2 >::operator=
       (pair< _T1, _T2 > && __p) [inline],  [constexpr],  [noexcept]
  • Converting assignment from a non-const pair<U1, U2> rvalue.
   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]"
  • Swap the first members and then the second members.
   template<typename _T1, typename _T2> void std::pair< _T1, _T2 >::swap (pair<
       _T1, _T2 > & __p) [inline],  [constexpr],  [noexcept]

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 πŸŽ€

  • The first member.
   template<typename _T1, typename _T2> _T1 std::pair< _T1, _T2 >::first

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().

  • The second member.
   template<typename _T1, typename _T2> _T2 std::pair< _T1, _T2 >::second

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.


And that's the whole vibe, bestie. This page came from libstdc++ and it's the std::pair< _T1, _T2 >(3) manpage. The footer didn't have a date, but that's the source and section. Stay iconic. πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms