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 π₯
π« Related Symbols π«
(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_typeandsecond_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