59 #if __cplusplus >= 201103L 64 #if __cplusplus >= 202002L 66 # define __cpp_lib_constexpr_utility 201811L 69 namespace std _GLIBCXX_VISIBILITY(default)
71 _GLIBCXX_BEGIN_NAMESPACE_VERSION
78 #if __cplusplus >= 201103L 95 #if ! __cpp_lib_concepts 101 template <
bool,
typename _T1,
typename _T2>
104 template <
typename _U1,
typename _U2>
105 static constexpr
bool _ConstructiblePair()
107 return __and_<is_constructible<_T1, const _U1&>,
111 template <
typename _U1,
typename _U2>
112 static constexpr
bool _ImplicitlyConvertiblePair()
114 return __and_<is_convertible<const _U1&, _T1>,
118 template <
typename _U1,
typename _U2>
119 static constexpr
bool _MoveConstructiblePair()
121 return __and_<is_constructible<_T1, _U1&&>,
125 template <
typename _U1,
typename _U2>
126 static constexpr
bool _ImplicitlyMoveConvertiblePair()
128 return __and_<is_convertible<_U1&&, _T1>,
133 template <
typename _T1,
typename _T2>
134 struct _PCC<false, _T1, _T2>
136 template <
typename _U1,
typename _U2>
137 static constexpr
bool _ConstructiblePair()
142 template <
typename _U1,
typename _U2>
143 static constexpr
bool _ImplicitlyConvertiblePair()
148 template <
typename _U1,
typename _U2>
149 static constexpr
bool _MoveConstructiblePair()
154 template <
typename _U1,
typename _U2>
155 static constexpr
bool _ImplicitlyMoveConvertiblePair()
160 #endif // lib concepts 163 template<
typename _U1,
typename _U2>
class __pair_base
165 #if __cplusplus >= 201103L && ! __cpp_lib_concepts 166 template<
typename _T1,
typename _T2>
friend struct pair;
167 __pair_base() =
default;
168 ~__pair_base() =
default;
169 __pair_base(
const __pair_base&) =
default;
170 __pair_base& operator=(
const __pair_base&) =
delete;
186 template<
typename _T1,
typename _T2>
188 :
public __pair_base<_T1, _T2>
196 #if __cplusplus >= 201103L 197 constexpr
pair(
const pair&) =
default;
200 template<
typename... _Args1,
typename... _Args2>
205 _GLIBCXX20_CONSTEXPR
void 207 noexcept(__and_<__is_nothrow_swappable<_T1>,
208 __is_nothrow_swappable<_T2>>::value)
211 swap(first, __p.first);
212 swap(second, __p.second);
216 template<
typename... _Args1,
size_t... _Indexes1,
217 typename... _Args2,
size_t... _Indexes2>
220 _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>);
223 #if __cpp_lib_concepts 228 explicit(__not_<__and_<__is_implicitly_default_constructible<_T1>,
229 __is_implicitly_default_constructible<_T2>>>())
231 requires is_default_constructible_v<_T1>
232 && is_default_constructible_v<_T2>
239 template<
typename _U1,
typename _U2>
240 static constexpr
bool 243 if constexpr (is_constructible_v<_T1, _U1>)
244 return is_constructible_v<_T2, _U2>;
248 template<
typename _U1,
typename _U2>
249 static constexpr
bool 250 _S_nothrow_constructible()
252 if constexpr (is_nothrow_constructible_v<_T1, _U1>)
253 return is_nothrow_constructible_v<_T2, _U2>;
257 template<
typename _U1,
typename _U2>
258 static constexpr
bool 261 if constexpr (is_convertible_v<_U1, _T1>)
262 return is_convertible_v<_U2, _T2>;
270 constexpr
explicit(!_S_convertible<const _T1&, const _T2&>())
271 pair(
const _T1& __x,
const _T2& __y)
272 noexcept(_S_nothrow_constructible<const _T1&, const _T2&>())
273 requires (_S_constructible<const _T1&, const _T2&>())
274 : first(__x), second(__y)
278 template<
typename _U1,
typename _U2>
279 requires (_S_constructible<_U1, _U2>())
280 constexpr
explicit(!_S_convertible<_U1, _U2>())
281 pair(_U1&& __x, _U2&& __y)
282 noexcept(_S_nothrow_constructible<_U1, _U2>())
283 : first(std::forward<_U1>(__x)), second(std::forward<_U2>(__y))
287 template<
typename _U1,
typename _U2>
288 requires (_S_constructible<const _U1&, const _U2&>())
289 constexpr
explicit(!_S_convertible<const _U1&, const _U2&>())
291 noexcept(_S_nothrow_constructible<const _U1&, const _U2&>())
296 template<
typename _U1,
typename _U2>
297 requires (_S_constructible<_U1, _U2>())
298 constexpr
explicit(!_S_convertible<_U1, _U2>())
300 noexcept(_S_nothrow_constructible<_U1, _U2>())
301 : first(std::forward<_U1>(__p.
first)),
302 second(std::forward<_U2>(__p.
second))
307 template<
typename _U1,
typename _U2>
308 static constexpr
bool 311 if constexpr (is_assignable_v<_T1&, _U1>)
312 return is_assignable_v<_T2&, _U2>;
316 template<
typename _U1,
typename _U2>
317 static constexpr
bool 318 _S_nothrow_assignable()
320 if constexpr (is_nothrow_assignable_v<_T1&, _U1>)
321 return is_nothrow_assignable_v<_T2&, _U2>;
328 pair& operator=(
const pair&) =
delete;
332 operator=(
const pair& __p)
333 noexcept(_S_nothrow_assignable<const _T1&, const _T2&>())
334 requires (_S_assignable<const _T1&, const _T2&>())
343 operator=(pair&& __p)
344 noexcept(_S_nothrow_assignable<_T1, _T2>())
345 requires (_S_assignable<_T1, _T2>())
347 first = std::forward<first_type>(__p.
first);
348 second = std::forward<second_type>(__p.
second);
353 template<
typename _U1,
typename _U2>
356 noexcept(_S_nothrow_assignable<const _U1&, const _U2&>())
357 requires (_S_assignable<const _U1&, const _U2&>())
365 template<
typename _U1,
typename _U2>
368 noexcept(_S_nothrow_assignable<_U1, _U2>())
369 requires (_S_assignable<_U1, _U2>())
371 first = std::forward<_U1>(__p.
first);
372 second = std::forward<_U2>(__p.
second);
380 template <
typename _U1 = _T1,
383 __is_implicitly_default_constructible<_U1>,
384 __is_implicitly_default_constructible<_U2>>
385 ::value,
bool>::type =
true>
387 : first(), second() { }
389 template <
typename _U1 = _T1,
395 __and_<__is_implicitly_default_constructible<_U1>,
396 __is_implicitly_default_constructible<_U2>>>>
397 ::value,
bool>::type =
false>
398 explicit constexpr pair()
399 : first(), second() { }
403 using _PCCP = _PCC<true, _T1, _T2>;
407 template<
typename _U1 = _T1,
typename _U2=_T2,
typename 409 _ConstructiblePair<_U1, _U2>()
411 _ImplicitlyConvertiblePair<_U1, _U2>(),
413 constexpr
pair(
const _T1& __a,
const _T2& __b)
414 : first(__a), second(__b) { }
417 template<
typename _U1 = _T1,
typename _U2=_T2,
typename 419 _ConstructiblePair<_U1, _U2>()
421 _ImplicitlyConvertiblePair<_U1, _U2>(),
423 explicit constexpr
pair(
const _T1& __a,
const _T2& __b)
424 : first(__a), second(__b) { }
428 template <
typename _U1,
typename _U2>
429 using _PCCFP = _PCC<!is_same<_T1, _U1>::value
434 template<
typename _U1,
typename _U2,
typename 436 _ConstructiblePair<_U1, _U2>()
437 && _PCCFP<_U1, _U2>::template
438 _ImplicitlyConvertiblePair<_U1, _U2>(),
443 template<
typename _U1,
typename _U2,
typename 445 _ConstructiblePair<_U1, _U2>()
446 && !_PCCFP<_U1, _U2>::template
447 _ImplicitlyConvertiblePair<_U1, _U2>(),
452 #if _GLIBCXX_USE_DEPRECATED 453 #if defined(__DEPRECATED) 454 # define _GLIBCXX_DEPRECATED_PAIR_CTOR \ 455 __attribute__ ((__deprecated__ ("use 'nullptr' instead of '0' to " \ 456 "initialize std::pair of move-only " \ 457 "type and pointer"))) 459 # define _GLIBCXX_DEPRECATED_PAIR_CTOR 466 struct __zero_as_null_pointer_constant
468 __zero_as_null_pointer_constant(
int __zero_as_null_pointer_constant::*)
470 template<
typename _Tp,
471 typename = __enable_if_t<is_null_pointer<_Tp>::value>>
472 __zero_as_null_pointer_constant(_Tp) =
delete;
480 template<
typename _U1,
481 __enable_if_t<__and_<__not_<is_reference<_U1>>,
484 __not_<is_constructible<_T1, const _U1&>>,
487 _GLIBCXX_DEPRECATED_PAIR_CTOR
489 pair(_U1&& __x, __zero_as_null_pointer_constant, ...)
490 : first(std::forward<_U1>(__x)), second(
nullptr) { }
492 template<
typename _U1,
493 __enable_if_t<__and_<__not_<is_reference<_U1>>,
495 is_constructible<_T1, _U1>,
496 __not_<is_constructible<_T1, const _U1&>>,
497 __not_<is_convertible<_U1, _T1>>>::value,
499 _GLIBCXX_DEPRECATED_PAIR_CTOR
501 pair(_U1&& __x, __zero_as_null_pointer_constant, ...)
502 : first(std::forward<_U1>(__x)), second(
nullptr) { }
504 template<
typename _U2,
505 __enable_if_t<__and_<is_pointer<_T1>,
506 __not_<is_reference<_U2>>,
508 __not_<is_constructible<_T2, const _U2&>>,
511 _GLIBCXX_DEPRECATED_PAIR_CTOR
513 pair(__zero_as_null_pointer_constant, _U2&& __y, ...)
514 : first(
nullptr), second(std::forward<_U2>(__y)) { }
516 template<
typename _U2,
517 __enable_if_t<__and_<is_pointer<_T1>,
518 __not_<is_reference<_U2>>,
519 is_constructible<_T2, _U2>,
520 __not_<is_constructible<_T2, const _U2&>>,
521 __not_<is_convertible<_U2, _T2>>>::value,
523 _GLIBCXX_DEPRECATED_PAIR_CTOR
525 pair(__zero_as_null_pointer_constant, _U2&& __y, ...)
526 : first(
nullptr), second(std::forward<_U2>(__y)) { }
527 #undef _GLIBCXX_DEPRECATED_PAIR_CTOR 530 template<
typename _U1,
typename _U2,
typename 532 _MoveConstructiblePair<_U1, _U2>()
534 _ImplicitlyMoveConvertiblePair<_U1, _U2>(),
536 constexpr pair(_U1&& __x, _U2&& __y)
537 : first(std::forward<_U1>(__x)), second(std::forward<_U2>(__y)) { }
539 template<
typename _U1,
typename _U2,
typename 541 _MoveConstructiblePair<_U1, _U2>()
543 _ImplicitlyMoveConvertiblePair<_U1, _U2>(),
545 explicit constexpr pair(_U1&& __x, _U2&& __y)
546 : first(std::forward<_U1>(__x)), second(std::forward<_U2>(__y)) { }
549 template<
typename _U1,
typename _U2,
typename 551 _MoveConstructiblePair<_U1, _U2>()
552 && _PCCFP<_U1, _U2>::template
553 _ImplicitlyMoveConvertiblePair<_U1, _U2>(),
556 : first(std::forward<_U1>(__p.
first)),
557 second(std::forward<_U2>(__p.
second)) { }
559 template<
typename _U1,
typename _U2,
typename 561 _MoveConstructiblePair<_U1, _U2>()
562 && !_PCCFP<_U1, _U2>::template
563 _ImplicitlyMoveConvertiblePair<_U1, _U2>(),
566 : first(std::forward<_U1>(__p.
first)),
567 second(std::forward<_U2>(__p.
second)) { }
572 const pair&,
const __nonesuch&> __p)
582 pair&&, __nonesuch&&> __p)
586 first = std::forward<first_type>(__p.
first);
587 second = std::forward<second_type>(__p.
second);
591 template<
typename _U1,
typename _U2>
602 template<
typename _U1,
typename _U2>
608 first = std::forward<_U1>(__p.
first);
609 second = std::forward<_U2>(__p.
second);
612 #endif // lib concepts 620 pair() : first(), second() { }
623 pair(
const _T1& __a,
const _T2& __b)
624 : first(__a), second(__b) { }
627 template<
typename _U1,
typename _U2>
635 #if __cpp_deduction_guides >= 201606 640 template<
typename _T1,
typename _T2>
641 inline _GLIBCXX_CONSTEXPR
bool 645 #if __cpp_lib_three_way_comparison && __cpp_lib_concepts 646 template<
typename _T1,
typename _T2>
647 constexpr common_comparison_category_t<__detail::__synth3way_t<_T1>,
648 __detail::__synth3way_t<_T2>>
651 if (
auto __c = __detail::__synth3way(__x.
first, __y.
first); __c != 0)
663 template<
typename _T1,
typename _T2>
664 inline _GLIBCXX_CONSTEXPR
bool 667 || (!(__y.
first < __x.first) && __x.second < __y.
second); }
670 template<
typename _T1,
typename _T2>
671 inline _GLIBCXX_CONSTEXPR
bool 673 {
return !(__x == __y); }
676 template<
typename _T1,
typename _T2>
677 inline _GLIBCXX_CONSTEXPR
bool 679 {
return __y < __x; }
682 template<
typename _T1,
typename _T2>
683 inline _GLIBCXX_CONSTEXPR
bool 685 {
return !(__y < __x); }
688 template<
typename _T1,
typename _T2>
689 inline _GLIBCXX_CONSTEXPR
bool 691 {
return !(__x < __y); }
692 #endif // !(three_way_comparison && concepts) 694 #if __cplusplus >= 201103L 700 template<
typename _T1,
typename _T2>
701 _GLIBCXX20_CONSTEXPR
inline 702 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 705 __is_swappable<_T2>>::value>::type
710 noexcept(noexcept(__x.swap(__y)))
713 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 714 template<
typename _T1,
typename _T2>
716 __is_swappable<_T2>>::value>::type
719 #endif // __cplusplus >= 201103L 738 #if __cplusplus >= 201103L 740 template<
typename _T1,
typename _T2>
742 typename __decay_and_strip<_T2>::__type>
745 typedef typename __decay_and_strip<_T1>::__type __ds_type1;
746 typedef typename __decay_and_strip<_T2>::__type __ds_type2;
748 return __pair_type(std::forward<_T1>(__x), std::forward<_T2>(__y));
751 template<
typename _T1,
typename _T2>
753 make_pair(_T1 __x, _T2 __y)
759 #if __cplusplus >= 201103L 763 template<
typename _T1,
typename _T2>
764 struct __is_tuple_like_impl<pair<_T1, _T2>> :
true_type 769 template<
class _Tp1,
class _Tp2>
774 template<
class _Tp1,
class _Tp2>
776 {
typedef _Tp1 type; };
779 template<
class _Tp1,
class _Tp2>
781 {
typedef _Tp2 type; };
783 #if __cplusplus >= 201703L 784 template<
typename _Tp1,
typename _Tp2>
785 inline constexpr
size_t tuple_size_v<pair<_Tp1, _Tp2>> = 2;
787 template<
typename _Tp1,
typename _Tp2>
788 inline constexpr
size_t tuple_size_v<const pair<_Tp1, _Tp2>> = 2;
790 template<
typename _Tp>
791 inline constexpr
bool __is_pair =
false;
793 template<
typename _Tp,
typename _Up>
794 inline constexpr
bool __is_pair<pair<_Tp, _Up>> =
true;
796 template<
typename _Tp,
typename _Up>
797 inline constexpr
bool __is_pair<const pair<_Tp, _Up>> =
true;
801 template<
size_t _Int>
807 template<
typename _Tp1,
typename _Tp2>
808 static constexpr _Tp1&
810 {
return __pair.
first; }
812 template<
typename _Tp1,
typename _Tp2>
813 static constexpr _Tp1&&
815 {
return std::forward<_Tp1>(__pair.
first); }
817 template<
typename _Tp1,
typename _Tp2>
818 static constexpr
const _Tp1&
820 {
return __pair.
first; }
822 template<
typename _Tp1,
typename _Tp2>
823 static constexpr
const _Tp1&&
825 {
return std::forward<const _Tp1>(__pair.
first); }
831 template<
typename _Tp1,
typename _Tp2>
832 static constexpr _Tp2&
836 template<
typename _Tp1,
typename _Tp2>
837 static constexpr _Tp2&&
839 {
return std::forward<_Tp2>(__pair.
second); }
841 template<
typename _Tp1,
typename _Tp2>
842 static constexpr
const _Tp2&
846 template<
typename _Tp1,
typename _Tp2>
847 static constexpr
const _Tp2&&
849 {
return std::forward<const _Tp2>(__pair.
second); }
857 template<
size_t _Int,
class _Tp1,
class _Tp2>
860 {
return __pair_get<_Int>::__get(__in); }
862 template<
size_t _Int,
class _Tp1,
class _Tp2>
865 {
return __pair_get<_Int>::__move_get(
std::move(__in)); }
867 template<
size_t _Int,
class _Tp1,
class _Tp2>
870 {
return __pair_get<_Int>::__const_get(__in); }
872 template<
size_t _Int,
class _Tp1,
class _Tp2>
875 {
return __pair_get<_Int>::__const_move_get(
std::move(__in)); }
877 #if __cplusplus >= 201402L 879 #define __cpp_lib_tuples_by_type 201304L 881 template <
typename _Tp,
typename _Up>
884 {
return __p.first; }
886 template <
typename _Tp,
typename _Up>
889 {
return __p.first; }
891 template <
typename _Tp,
typename _Up>
896 template <
typename _Tp,
typename _Up>
897 constexpr
const _Tp&&
901 template <
typename _Tp,
typename _Up>
904 {
return __p.second; }
906 template <
typename _Tp,
typename _Up>
909 {
return __p.second; }
911 template <
typename _Tp,
typename _Up>
916 template <
typename _Tp,
typename _Up>
917 constexpr
const _Tp&&
925 _GLIBCXX_END_NAMESPACE_VERSION
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.
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)))
constexpr bool operator==(const pair< _T1, _T2 > &__x, const pair< _T1, _T2 > &__y)
Two pairs of the same type are equal iff their members are equal.
constexpr piecewise_construct_t piecewise_construct
Tag for piecewise construction of std::pair objects.
constexpr bool operator>(const pair< _T1, _T2 > &__x, const pair< _T1, _T2 > &__y)
Uses operator< to find the result.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
_T1 first
The first member.
Finds the size of a given tuple type.
ISO C++ entities toplevel namespace is std.
constexpr bool operator>=(const pair< _T1, _T2 > &__x, const pair< _T1, _T2 > &__y)
Uses operator< to find the result.
_T1 first_type
The type of the first member.
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.
is_nothrow_move_assignable
Struct holding two objects of arbitrary type.
Tag type for piecewise construction of std::pair objects.
constexpr bool operator!=(const pair< _T1, _T2 > &__x, const pair< _T1, _T2 > &__y)
Uses operator== to find the result.
constexpr pair(const _T1 &__a, const _T2 &__b)
Construct from two const lvalues, allowing implicit conversions.
Gives the type of the ith element of a given tuple type.
Define a member typedef type only if a boolean constant is true.
_T2 second_type
The type of the second member.
_T2 second
The second member.
Primary class template, tuple.