__GNU_CXX::PAIR(3)

πŸ“¦
version 16.2.1+r23+gd564253eb6c8 Β· 5 versions
, in arch rolling, fedora 44

πŸ’– NAME πŸ’–

__gnu_cxx::pair< _T1, _T2 > β€” it's a struct that holds two objects (or references, bestie, references) of literally any type you want. And yes, this is the Library Functions Manual, so you know it's official. 🫢


✨ SYNOPSIS ✨

#include <utility>

πŸŽ€ Public Types πŸŽ€

  • typedef _T1 first_type β€” the type of the first member. it's giving first-born energy πŸ’…
  • typedef _T2 second_type β€” the type of the second member. the sequel, the encore, the remix ✨

πŸ’– Public Member Functions πŸ’–

okay bestie, hydrate, sit down, put your phone on do-not-disturb, because this list is long and we are doing every single one of them. no skipping. 🌸

  • constexpr pair (const pair &)=default β€” the copy constructor. defaulted, iconic, no notes. πŸ‘‘
  • constexpr pair (pair &&)=default β€” the move constructor. defaulted too. slay. πŸ’…
  • template<typename... _Args1, typename... _Args2> constexpr pair (piecewise_construct_t, tuple< _Args1... >, tuple< _Args2... >) β€” the piecewise-construct one, no description given, just vibes ✨
  • 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 β€” the 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 β€” the 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 β€” the 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 β€” the 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 β€” deleted, bestie. not today. πŸ’€
  • 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 >) β€” the default constructor. the main character. 🌟
  • 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 β€” deleted. absolutely not. πŸ™ˆ
  • 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) β€” swaps the first members and then the second members. in that order. first, then second. respect the sequence. πŸ’…

πŸ¦‹ Public Attributes πŸ¦‹

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

(Note that these are not member symbols.) like, they're friends of the family, not family family, yk?
  • template<typename _T1, typename _T2> pair (_T1, _T2) -> pair< _T1, _T2 > β€” the deduction guide, doing its lil thing ✨
  • 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))) β€” the free-function swap 🫢
  • 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. periodt. πŸ’…
  • 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, iconic 🌈

πŸ‘‘ Detailed Description πŸ‘‘

template<typename _T1, typename _T2>
    struct __gnu_cxx::pair< _T1, _T2 >"Struct holding two objects (or references) of arbitrary type.

so yeah bestie, it's a struct holding two objects (or references) of arbitrary type. that's the whole pitch. it's simple, it's elegant, it's the blueprint. πŸ’–

🌈 Template Parameters 🌈

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

https://gcc.gnu.org/onlinedocs/libstdc++/manual/utilities.html β€” the reading material, if you want the lore 🧚


πŸ’œ 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] β€” the copy constructor. constexpr, defaulted, flawless. πŸ‘‘
  • template<typename _T1, typename _T2> std::pair< _T1, _T2 >::pair (pair< _T1, _T2 > && ) [constexpr], [default] β€” the move constructor. constexpr, defaulted, also flawless. 🫢

πŸ’… Member Function Documentation πŸ’…

okay bestie, this is the part where pair shows off literally everything it can do. sixteen whole functions. grab a snack. πŸ“


1. 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]

Converting constructor from a non-const pair<U1, U2> lvalue β€” you hand it a non-const pair<U1, U2> lvalue and it converts it into a shiny new pair. it's constexpr, so yes, this can happen at compile time. ✨

2. 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]

Constructor accepting two values of arbitrary types β€” and note the cute default template args, _U1 = _T1 and _U2 = _T2, so you can just not say them. the && at the end is right there in the signature. 🫢

3. 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]

Converting constructor from a non-const pair<U1, U2> rvalue β€” same energy as #1 but for rvalues. the way this family of constructors just keeps going… iconic. πŸ’–

4. 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]

Constructor accepting lvalues of first_type and second_type β€” it's const & qualified and it takes lvalues of the two types. slay. 🌸

5. 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> lvalue β€” now with const in the mix, and the whole thing is const qualified too. respect the const. πŸ‘‘

6. 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]

Converting constructor from a const pair<U1, U2> rvalue β€” const and rvalue. the final boss of the converting constructors. πŸ”₯

7. 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]

Default constructor β€” no args, no thoughts, just vibes. it's [inline], [constexpr] and [noexcept], and that gnarly constraint is literally telling you it's explicit unless both _T1 and _T2 are implicitly default constructible. main character behaviour, no cap. πŸ’…

8. 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 (const) β€” it hands you back a const pair & and it's const qualified. it's [inline] and [constexpr] too. note: no [noexcept] here, bestie, don't @ me.

9. Copy assignment operator

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

Copy assignment operator β€” the regular one. returns pair &, and this one is [noexcept] along with [inline] and [constexpr]. ✨

10. 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 β€” guarded by a requires clause on _S_const_assignable<const _U1&, const _U2&>(), and it's the const pair & / const flavour. 🌈

11. 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 β€” yes, same description as #10, no I'm not tripping. this one's requires is _S_assignable<const _U1&, const _U2&>() (not the const-assignable one), it returns pair & instead of const pair &, and it brings [noexcept] to the party. two sisters, different outfits. πŸŽ€

12. 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 (const) β€” the const-qualified move assign, returning const pair &. [inline] and [constexpr]. πŸ¦‹

13. Move assignment operator

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

Move assignment operator β€” the normal move assign. returns pair &, and it's [inline], [constexpr], [noexcept]. yup yup. ⭐

14. 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 β€” requires (_S_const_assignable<_U1, _U2>()), takes a non-const pair<U1, U2> rvalue, gives back const pair &. πŸ’œ

15. 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 β€” again, same description as #14, but requires (_S_assignable<_U1, _U2>()), returns plain pair &, and adds [noexcept]. matching set, one's just louder. πŸ’€

16. swap

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 β€” first then second, in that exact order, okay? it returns void, and it's [inline], [constexpr], [noexcept]. 🧚


🌸 Member Data Documentation 🌸

these are the two little guys living inside every pair. the whole point, honestly.

  • template<typename _T1, typename _T2> _T1 std::pair< _T1, _T2 >::first β€” The first member. it's literally the _T1. πŸ₯‡
template<typename _T1, typename _T2> _T1 std::pair< _T1, _T2 >::first
  • template<typename _T1, typename _T2> _T2 std::pair< _T1, _T2 >::second β€” The second member. and this one is the _T2. the duo. the pair, if you will. πŸ₯ˆ
template<typename _T1, typename _T2> _T2 std::pair< _T1, _T2 >::second

✨ Author ✨

Generated automatically by Doxygen for libstdc++ from the source code. β€” so like, nobody hand-wrote this, Doxygen just did its little thing straight off the libstdc++ source. we stan an automated queen. πŸ€–πŸ‘‘


okay that's the whole page bestie!! πŸ’– this was the libstdc++ manual, page __gnu_cxx:... _T1, _T2 >(3), and the date/version stamp lives down there in the footer like always. go forth and std::pair responsibly. πŸ«ΆπŸŽ€

πŸ“¦ 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