STD::PAIR(3cxx)

πŸ’– std::pair< _T1, _T2 >(3cxx) β€” NAME πŸŽ€

okay so bestie, welcome to the 3cxx manual page for std::pair< _T1, _T2 > β€” literally the struct holding two objects of arbitrary type. That's the whole serve: two little slots, any types you want, main character energy for your tuples-but-smaller era. ✨


🌸 SYNOPSIS 🌸

#include <utility>

It 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 πŸ’…

  • Default constructor β€” the constexpr pair () situation. Full signature, copied exactly because we do not play with template text:
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 ()
  • Zero-as-null-pointer-constant constructor, first variant β€” takes __zero_as_null_pointer_constant plus _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 & > >, is_convertible< _U2, _T2 >
           >::value, bool >  = true> constexpr pair
           (__zero_as_null_pointer_constant, _U2 &&__y,...)
  • Zero-as-null-pointer-constant constructor, second variant β€” same shape, bool > = false, and the convertibility check is negated:
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,...)
  • Zero-as-null-pointer-constant constructor, third variant β€” now the first parameter is the one taking __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 & > >, is_convertible< _U1, _T1 >
           >::value, bool >  = true> constexpr pair (_U1 &&__x,
           __zero_as_null_pointer_constant,...)
  • Zero-as-null-pointer-constant constructor, fourth variant β€” same but bool > = false and the convertibility check is negated:
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,...)
  • Move-constructible pair constructor, implicit version β€” _PCCP says _MoveConstructiblePair and _ImplicitlyMoveConvertiblePair are both true:
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)
  • Move-constructible pair constructor, non-implicit version β€” _PCCP says _MoveConstructiblePair is true and _ImplicitlyMoveConvertiblePair is not:
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)
  • Construct from two const lvalues, allowing implicit conversions β€” the description says exactly that: 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  = true>
           constexpr pair (const _T1 &__a, const _T2 &__b)
  • Construct from two const lvalues, disallowing implicit conversions β€” same base description, but the implicit-conversion bit is turned off:
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)
  • Copy constructor β€” literally the copy constructor:
constexpr pair (const pair &)=default
  • Converting copy constructor, implicit version β€” _PCCFP pair-constructible and implicitly convertible:
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)
  • Converting copy constructor, non-implicit version β€” _PCCFP pair-constructible and not implicitly convertible:
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)
  • Move constructor β€” literally the move constructor:
constexpr pair (pair &&)=default
  • Converting move constructor, implicit version β€” _PCCFP move-constructible and implicitly move-convertible:
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)
  • Converting move constructor, non-implicit version β€” _PCCFP move-constructible and not implicitly move-convertible:
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)
  • Piecewise constructor β€” takes piecewise_construct_t and two tuples:
template<typename... _Args1, typename... _Args2> constexpr pair
           (piecewise_construct_t, tuple< _Args1... >, tuple< _Args2... >)
  • Copy assignment operator β€” the __conditional_t situation:
pair & operator= (__conditional_t< __and_< is_copy_assignable< _T1 >,
           is_copy_assignable< _T2 > >::value, const pair &, const __nonesuch &
           > __p)
  • Move assignment operator β€” also has a noexcept clause:
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)
  • Converting copy assignment operator β€” enable_if on assignability with const_U1 and const_U2 exactly as printed:
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)
  • Converting move assignment operator β€” enable_if on assignability with _U1 && and _U2 &&:
template<typename _U1 , typename _U2 > enable_if< __and_< is_assignable<
           _T1 &, _U1 && >, is_assignable< _T2 &, _U2 && > >::value, pair &
           >::type operator= (pair< _U1, _U2 > &&__p)
  • swap β€” swaps the first members and then the second members. That's the whole bit:
constexpr void swap (pair &__p) noexcept(__and_< __is_nothrow_swappable<
           _T1 >, __is_nothrow_swappable< _T2 > >::value)

πŸ“ Public Attributes πŸ“

  • _T1 first β€” the first member.
  • _T2 second β€” the second member.

Note that these are not member symbols. They're related, bestie, not members. Keep the distinction cute and clear.
  • make_pair β€” a convenience wrapper for creating a pair from two objects:
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)
  • Deduction guide for pair β€” description in the page says: two pairs of the same type are equal iff their members are equal:
template<typename _T1 , typename _T2 > pair (_T1, _T2) -> pair< _T1,
               _T2 >
  • operator== β€” 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)
  • operator< β€” here's the signature:
template<typename _T1 , typename _T2 > constexpr bool operator<
               (const pair< _T1, _T2 > &__x, const pair< _T1, _T2 > &__y)
  • operator!= β€” uses operator== to find the result:
template<typename _T1 , typename _T2 > constexpr bool operator!=
               (const pair< _T1, _T2 > &__x, const pair< _T1, _T2 > &__y)
  • operator> β€” uses operator< to find the result:
template<typename _T1 , typename _T2 > constexpr bool operator>
               (const pair< _T1, _T2 > &__x, const pair< _T1, _T2 > &__y)
  • operator<= β€” uses operator< to find the result:
template<typename _T1 , typename _T2 > constexpr bool operator<=
               (const pair< _T1, _T2 > &__x, const pair< _T1, _T2 > &__y)
  • operator>= β€” uses operator< to find the result:
template<typename _T1 , typename _T2 > constexpr bool operator>=
               (const pair< _T1, _T2 > &__x, const pair< _T1, _T2 > &__y)
  • Free swap β€” enable_if on __is_swappable< _T1 > and __is_swappable< _T2 >, with a noexcept that checks __x.swap(__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 🌈

The declaration in the manpage is printed like this β€” stray quote and all, so I'm keeping it exactly:

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.

The reference link, copied exactly:

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

✨ AUTHOR ✨

okay so nobody actually sat down and hand-wrote this one, bestie 😭 it was Generated automatically by Doxygen for libstdc++ from the source code. so like, the robot did the typing, and the source code did the ~vibes~ πŸ’… no cap, the code is the real main character here and Doxygen is just the icon doing the transcription πŸŽ€


and that's a wrap on std::pair< _T1, _T2 >, section 3cxx of the libstdc++ manual πŸ¦‹ the whole thing lives under the libstdc++ banner, and it got stamped with its little date-and-version footer at the bottom of the page β€” you know the one, the tiny line that goes libstdc++ … std::pair< _T1, _T2 >(3cxx). absolute serve, no notes ✨

go forth and pair your _T1 with your _T2, bestie πŸ’– you ate 🫢 πŸ‘‘

πŸ“¦ where this page comes from