1*38fd1498Szrj // Pair implementation -*- C++ -*- 2*38fd1498Szrj 3*38fd1498Szrj // Copyright (C) 2001-2018 Free Software Foundation, Inc. 4*38fd1498Szrj // 5*38fd1498Szrj // This file is part of the GNU ISO C++ Library. This library is free 6*38fd1498Szrj // software; you can redistribute it and/or modify it under the 7*38fd1498Szrj // terms of the GNU General Public License as published by the 8*38fd1498Szrj // Free Software Foundation; either version 3, or (at your option) 9*38fd1498Szrj // any later version. 10*38fd1498Szrj 11*38fd1498Szrj // This library is distributed in the hope that it will be useful, 12*38fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of 13*38fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*38fd1498Szrj // GNU General Public License for more details. 15*38fd1498Szrj 16*38fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional 17*38fd1498Szrj // permissions described in the GCC Runtime Library Exception, version 18*38fd1498Szrj // 3.1, as published by the Free Software Foundation. 19*38fd1498Szrj 20*38fd1498Szrj // You should have received a copy of the GNU General Public License and 21*38fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program; 22*38fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23*38fd1498Szrj // <http://www.gnu.org/licenses/>. 24*38fd1498Szrj 25*38fd1498Szrj /* 26*38fd1498Szrj * 27*38fd1498Szrj * Copyright (c) 1994 28*38fd1498Szrj * Hewlett-Packard Company 29*38fd1498Szrj * 30*38fd1498Szrj * Permission to use, copy, modify, distribute and sell this software 31*38fd1498Szrj * and its documentation for any purpose is hereby granted without fee, 32*38fd1498Szrj * provided that the above copyright notice appear in all copies and 33*38fd1498Szrj * that both that copyright notice and this permission notice appear 34*38fd1498Szrj * in supporting documentation. Hewlett-Packard Company makes no 35*38fd1498Szrj * representations about the suitability of this software for any 36*38fd1498Szrj * purpose. It is provided "as is" without express or implied warranty. 37*38fd1498Szrj * 38*38fd1498Szrj * 39*38fd1498Szrj * Copyright (c) 1996,1997 40*38fd1498Szrj * Silicon Graphics Computer Systems, Inc. 41*38fd1498Szrj * 42*38fd1498Szrj * Permission to use, copy, modify, distribute and sell this software 43*38fd1498Szrj * and its documentation for any purpose is hereby granted without fee, 44*38fd1498Szrj * provided that the above copyright notice appear in all copies and 45*38fd1498Szrj * that both that copyright notice and this permission notice appear 46*38fd1498Szrj * in supporting documentation. Silicon Graphics makes no 47*38fd1498Szrj * representations about the suitability of this software for any 48*38fd1498Szrj * purpose. It is provided "as is" without express or implied warranty. 49*38fd1498Szrj */ 50*38fd1498Szrj 51*38fd1498Szrj /** @file bits/stl_pair.h 52*38fd1498Szrj * This is an internal header file, included by other library headers. 53*38fd1498Szrj * Do not attempt to use it directly. @headername{utility} 54*38fd1498Szrj */ 55*38fd1498Szrj 56*38fd1498Szrj #ifndef _STL_PAIR_H 57*38fd1498Szrj #define _STL_PAIR_H 1 58*38fd1498Szrj 59*38fd1498Szrj #include <bits/move.h> // for std::move / std::forward, and std::swap 60*38fd1498Szrj 61*38fd1498Szrj #if __cplusplus >= 201103L 62*38fd1498Szrj #include <type_traits> // for std::__decay_and_strip too 63*38fd1498Szrj #endif 64*38fd1498Szrj 65*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default) 66*38fd1498Szrj { 67*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION 68*38fd1498Szrj 69*38fd1498Szrj /** 70*38fd1498Szrj * @addtogroup utilities 71*38fd1498Szrj * @{ 72*38fd1498Szrj */ 73*38fd1498Szrj 74*38fd1498Szrj #if __cplusplus >= 201103L 75*38fd1498Szrj /// piecewise_construct_t 76*38fd1498Szrj struct piecewise_construct_t { explicit piecewise_construct_t() = default; }; 77*38fd1498Szrj 78*38fd1498Szrj /// piecewise_construct 79*38fd1498Szrj _GLIBCXX17_INLINE constexpr piecewise_construct_t piecewise_construct = 80*38fd1498Szrj piecewise_construct_t(); 81*38fd1498Szrj 82*38fd1498Szrj // Forward declarations. 83*38fd1498Szrj template<typename...> 84*38fd1498Szrj class tuple; 85*38fd1498Szrj 86*38fd1498Szrj template<std::size_t...> 87*38fd1498Szrj struct _Index_tuple; 88*38fd1498Szrj 89*38fd1498Szrj // Concept utility functions, reused in conditionally-explicit 90*38fd1498Szrj // constructors. 91*38fd1498Szrj // See PR 70437, don't look at is_constructible or 92*38fd1498Szrj // is_convertible if the types are the same to 93*38fd1498Szrj // avoid querying those properties for incomplete types. 94*38fd1498Szrj template <bool, typename _T1, typename _T2> 95*38fd1498Szrj struct _PCC 96*38fd1498Szrj { 97*38fd1498Szrj template <typename _U1, typename _U2> 98*38fd1498Szrj static constexpr bool _ConstructiblePair() 99*38fd1498Szrj { 100*38fd1498Szrj return __and_<is_constructible<_T1, const _U1&>, 101*38fd1498Szrj is_constructible<_T2, const _U2&>>::value; 102*38fd1498Szrj } 103*38fd1498Szrj 104*38fd1498Szrj template <typename _U1, typename _U2> 105*38fd1498Szrj static constexpr bool _ImplicitlyConvertiblePair() 106*38fd1498Szrj { 107*38fd1498Szrj return __and_<is_convertible<const _U1&, _T1>, 108*38fd1498Szrj is_convertible<const _U2&, _T2>>::value; 109*38fd1498Szrj } 110*38fd1498Szrj 111*38fd1498Szrj template <typename _U1, typename _U2> 112*38fd1498Szrj static constexpr bool _MoveConstructiblePair() 113*38fd1498Szrj { 114*38fd1498Szrj return __and_<is_constructible<_T1, _U1&&>, 115*38fd1498Szrj is_constructible<_T2, _U2&&>>::value; 116*38fd1498Szrj } 117*38fd1498Szrj 118*38fd1498Szrj template <typename _U1, typename _U2> 119*38fd1498Szrj static constexpr bool _ImplicitlyMoveConvertiblePair() 120*38fd1498Szrj { 121*38fd1498Szrj return __and_<is_convertible<_U1&&, _T1>, 122*38fd1498Szrj is_convertible<_U2&&, _T2>>::value; 123*38fd1498Szrj } 124*38fd1498Szrj 125*38fd1498Szrj template <bool __implicit, typename _U1, typename _U2> 126*38fd1498Szrj static constexpr bool _CopyMovePair() 127*38fd1498Szrj { 128*38fd1498Szrj using __do_converts = __and_<is_convertible<const _U1&, _T1>, 129*38fd1498Szrj is_convertible<_U2&&, _T2>>; 130*38fd1498Szrj using __converts = typename conditional<__implicit, 131*38fd1498Szrj __do_converts, 132*38fd1498Szrj __not_<__do_converts>>::type; 133*38fd1498Szrj return __and_<is_constructible<_T1, const _U1&>, 134*38fd1498Szrj is_constructible<_T2, _U2&&>, 135*38fd1498Szrj __converts 136*38fd1498Szrj >::value; 137*38fd1498Szrj } 138*38fd1498Szrj 139*38fd1498Szrj template <bool __implicit, typename _U1, typename _U2> 140*38fd1498Szrj static constexpr bool _MoveCopyPair() 141*38fd1498Szrj { 142*38fd1498Szrj using __do_converts = __and_<is_convertible<_U1&&, _T1>, 143*38fd1498Szrj is_convertible<const _U2&, _T2>>; 144*38fd1498Szrj using __converts = typename conditional<__implicit, 145*38fd1498Szrj __do_converts, 146*38fd1498Szrj __not_<__do_converts>>::type; 147*38fd1498Szrj return __and_<is_constructible<_T1, _U1&&>, 148*38fd1498Szrj is_constructible<_T2, const _U2&&>, 149*38fd1498Szrj __converts 150*38fd1498Szrj >::value; 151*38fd1498Szrj } 152*38fd1498Szrj }; 153*38fd1498Szrj 154*38fd1498Szrj template <typename _T1, typename _T2> 155*38fd1498Szrj struct _PCC<false, _T1, _T2> 156*38fd1498Szrj { 157*38fd1498Szrj template <typename _U1, typename _U2> 158*38fd1498Szrj static constexpr bool _ConstructiblePair() 159*38fd1498Szrj { 160*38fd1498Szrj return false; 161*38fd1498Szrj } 162*38fd1498Szrj 163*38fd1498Szrj template <typename _U1, typename _U2> 164*38fd1498Szrj static constexpr bool _ImplicitlyConvertiblePair() 165*38fd1498Szrj { 166*38fd1498Szrj return false; 167*38fd1498Szrj } 168*38fd1498Szrj 169*38fd1498Szrj template <typename _U1, typename _U2> 170*38fd1498Szrj static constexpr bool _MoveConstructiblePair() 171*38fd1498Szrj { 172*38fd1498Szrj return false; 173*38fd1498Szrj } 174*38fd1498Szrj 175*38fd1498Szrj template <typename _U1, typename _U2> 176*38fd1498Szrj static constexpr bool _ImplicitlyMoveConvertiblePair() 177*38fd1498Szrj { 178*38fd1498Szrj return false; 179*38fd1498Szrj } 180*38fd1498Szrj }; 181*38fd1498Szrj 182*38fd1498Szrj // PR libstdc++/79141, a utility type for preventing 183*38fd1498Szrj // initialization of an argument of a disabled assignment 184*38fd1498Szrj // operator from a pair of empty braces. 185*38fd1498Szrj struct __nonesuch_no_braces : std::__nonesuch { 186*38fd1498Szrj explicit __nonesuch_no_braces(const __nonesuch&) = delete; 187*38fd1498Szrj }; 188*38fd1498Szrj 189*38fd1498Szrj #endif 190*38fd1498Szrj 191*38fd1498Szrj /** 192*38fd1498Szrj * @brief Struct holding two objects of arbitrary type. 193*38fd1498Szrj * 194*38fd1498Szrj * @tparam _T1 Type of first object. 195*38fd1498Szrj * @tparam _T2 Type of second object. 196*38fd1498Szrj */ 197*38fd1498Szrj template<typename _T1, typename _T2> 198*38fd1498Szrj struct pair 199*38fd1498Szrj { 200*38fd1498Szrj typedef _T1 first_type; /// @c first_type is the first bound type 201*38fd1498Szrj typedef _T2 second_type; /// @c second_type is the second bound type 202*38fd1498Szrj 203*38fd1498Szrj _T1 first; /// @c first is a copy of the first object 204*38fd1498Szrj _T2 second; /// @c second is a copy of the second object 205*38fd1498Szrj 206*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 207*38fd1498Szrj // 265. std::pair::pair() effects overly restrictive 208*38fd1498Szrj /** The default constructor creates @c first and @c second using their 209*38fd1498Szrj * respective default constructors. */ 210*38fd1498Szrj #if __cplusplus >= 201103L 211*38fd1498Szrj template <typename _U1 = _T1, 212*38fd1498Szrj typename _U2 = _T2, 213*38fd1498Szrj typename enable_if<__and_< 214*38fd1498Szrj __is_implicitly_default_constructible<_U1>, 215*38fd1498Szrj __is_implicitly_default_constructible<_U2>> 216*38fd1498Szrj ::value, bool>::type = true> 217*38fd1498Szrj #endif 218*38fd1498Szrj _GLIBCXX_CONSTEXPR pair() 219*38fd1498Szrj : first(), second() { } 220*38fd1498Szrj 221*38fd1498Szrj #if __cplusplus >= 201103L 222*38fd1498Szrj template <typename _U1 = _T1, 223*38fd1498Szrj typename _U2 = _T2, 224*38fd1498Szrj typename enable_if<__and_< 225*38fd1498Szrj is_default_constructible<_U1>, 226*38fd1498Szrj is_default_constructible<_U2>, 227*38fd1498Szrj __not_< 228*38fd1498Szrj __and_<__is_implicitly_default_constructible<_U1>, 229*38fd1498Szrj __is_implicitly_default_constructible<_U2>>>> 230*38fd1498Szrj ::value, bool>::type = false> 231*38fd1498Szrj explicit constexpr pair() 232*38fd1498Szrj : first(), second() { } 233*38fd1498Szrj #endif 234*38fd1498Szrj 235*38fd1498Szrj /** Two objects may be passed to a @c pair constructor to be copied. */ 236*38fd1498Szrj #if __cplusplus < 201103L 237*38fd1498Szrj pair(const _T1& __a, const _T2& __b) 238*38fd1498Szrj : first(__a), second(__b) { } 239*38fd1498Szrj #else 240*38fd1498Szrj // Shortcut for constraining the templates that don't take pairs. 241*38fd1498Szrj using _PCCP = _PCC<true, _T1, _T2>; 242*38fd1498Szrj 243*38fd1498Szrj template<typename _U1 = _T1, typename _U2=_T2, typename 244*38fd1498Szrj enable_if<_PCCP::template 245*38fd1498Szrj _ConstructiblePair<_U1, _U2>() 246*38fd1498Szrj && _PCCP::template 247*38fd1498Szrj _ImplicitlyConvertiblePair<_U1, _U2>(), 248*38fd1498Szrj bool>::type=true> 249*38fd1498Szrj constexpr pair(const _T1& __a, const _T2& __b) 250*38fd1498Szrj : first(__a), second(__b) { } 251*38fd1498Szrj 252*38fd1498Szrj template<typename _U1 = _T1, typename _U2=_T2, typename 253*38fd1498Szrj enable_if<_PCCP::template 254*38fd1498Szrj _ConstructiblePair<_U1, _U2>() 255*38fd1498Szrj && !_PCCP::template 256*38fd1498Szrj _ImplicitlyConvertiblePair<_U1, _U2>(), 257*38fd1498Szrj bool>::type=false> 258*38fd1498Szrj explicit constexpr pair(const _T1& __a, const _T2& __b) 259*38fd1498Szrj : first(__a), second(__b) { } 260*38fd1498Szrj #endif 261*38fd1498Szrj 262*38fd1498Szrj /** There is also a templated copy ctor for the @c pair class itself. */ 263*38fd1498Szrj #if __cplusplus < 201103L 264*38fd1498Szrj template<typename _U1, typename _U2> 265*38fd1498Szrj pair(const pair<_U1, _U2>& __p) 266*38fd1498Szrj : first(__p.first), second(__p.second) { } 267*38fd1498Szrj #else 268*38fd1498Szrj // Shortcut for constraining the templates that take pairs. 269*38fd1498Szrj template <typename _U1, typename _U2> 270*38fd1498Szrj using _PCCFP = _PCC<!is_same<_T1, _U1>::value 271*38fd1498Szrj || !is_same<_T2, _U2>::value, 272*38fd1498Szrj _T1, _T2>; 273*38fd1498Szrj 274*38fd1498Szrj template<typename _U1, typename _U2, typename 275*38fd1498Szrj enable_if<_PCCFP<_U1, _U2>::template 276*38fd1498Szrj _ConstructiblePair<_U1, _U2>() 277*38fd1498Szrj && _PCCFP<_U1, _U2>::template 278*38fd1498Szrj _ImplicitlyConvertiblePair<_U1, _U2>(), 279*38fd1498Szrj bool>::type=true> 280*38fd1498Szrj constexpr pair(const pair<_U1, _U2>& __p) 281*38fd1498Szrj : first(__p.first), second(__p.second) { } 282*38fd1498Szrj 283*38fd1498Szrj template<typename _U1, typename _U2, typename 284*38fd1498Szrj enable_if<_PCCFP<_U1, _U2>::template 285*38fd1498Szrj _ConstructiblePair<_U1, _U2>() 286*38fd1498Szrj && !_PCCFP<_U1, _U2>::template 287*38fd1498Szrj _ImplicitlyConvertiblePair<_U1, _U2>(), 288*38fd1498Szrj bool>::type=false> 289*38fd1498Szrj explicit constexpr pair(const pair<_U1, _U2>& __p) 290*38fd1498Szrj : first(__p.first), second(__p.second) { } 291*38fd1498Szrj 292*38fd1498Szrj constexpr pair(const pair&) = default; 293*38fd1498Szrj constexpr pair(pair&&) = default; 294*38fd1498Szrj 295*38fd1498Szrj // DR 811. 296*38fd1498Szrj template<typename _U1, typename 297*38fd1498Szrj enable_if<_PCCP::template 298*38fd1498Szrj _MoveCopyPair<true, _U1, _T2>(), 299*38fd1498Szrj bool>::type=true> 300*38fd1498Szrj constexpr pair(_U1&& __x, const _T2& __y) 301*38fd1498Szrj : first(std::forward<_U1>(__x)), second(__y) { } 302*38fd1498Szrj 303*38fd1498Szrj template<typename _U1, typename 304*38fd1498Szrj enable_if<_PCCP::template 305*38fd1498Szrj _MoveCopyPair<false, _U1, _T2>(), 306*38fd1498Szrj bool>::type=false> 307*38fd1498Szrj explicit constexpr pair(_U1&& __x, const _T2& __y) 308*38fd1498Szrj : first(std::forward<_U1>(__x)), second(__y) { } 309*38fd1498Szrj 310*38fd1498Szrj template<typename _U2, typename 311*38fd1498Szrj enable_if<_PCCP::template 312*38fd1498Szrj _CopyMovePair<true, _T1, _U2>(), 313*38fd1498Szrj bool>::type=true> 314*38fd1498Szrj constexpr pair(const _T1& __x, _U2&& __y) 315*38fd1498Szrj : first(__x), second(std::forward<_U2>(__y)) { } 316*38fd1498Szrj 317*38fd1498Szrj template<typename _U2, typename 318*38fd1498Szrj enable_if<_PCCP::template 319*38fd1498Szrj _CopyMovePair<false, _T1, _U2>(), 320*38fd1498Szrj bool>::type=false> 321*38fd1498Szrj explicit pair(const _T1& __x, _U2&& __y) 322*38fd1498Szrj : first(__x), second(std::forward<_U2>(__y)) { } 323*38fd1498Szrj 324*38fd1498Szrj template<typename _U1, typename _U2, typename 325*38fd1498Szrj enable_if<_PCCP::template 326*38fd1498Szrj _MoveConstructiblePair<_U1, _U2>() 327*38fd1498Szrj && _PCCP::template 328*38fd1498Szrj _ImplicitlyMoveConvertiblePair<_U1, _U2>(), 329*38fd1498Szrj bool>::type=true> 330*38fd1498Szrj constexpr pair(_U1&& __x, _U2&& __y) 331*38fd1498Szrj : first(std::forward<_U1>(__x)), second(std::forward<_U2>(__y)) { } 332*38fd1498Szrj 333*38fd1498Szrj template<typename _U1, typename _U2, typename 334*38fd1498Szrj enable_if<_PCCP::template 335*38fd1498Szrj _MoveConstructiblePair<_U1, _U2>() 336*38fd1498Szrj && !_PCCP::template 337*38fd1498Szrj _ImplicitlyMoveConvertiblePair<_U1, _U2>(), 338*38fd1498Szrj bool>::type=false> 339*38fd1498Szrj explicit constexpr pair(_U1&& __x, _U2&& __y) 340*38fd1498Szrj : first(std::forward<_U1>(__x)), second(std::forward<_U2>(__y)) { } 341*38fd1498Szrj 342*38fd1498Szrj 343*38fd1498Szrj template<typename _U1, typename _U2, typename 344*38fd1498Szrj enable_if<_PCCFP<_U1, _U2>::template 345*38fd1498Szrj _MoveConstructiblePair<_U1, _U2>() 346*38fd1498Szrj && _PCCFP<_U1, _U2>::template 347*38fd1498Szrj _ImplicitlyMoveConvertiblePair<_U1, _U2>(), 348*38fd1498Szrj bool>::type=true> 349*38fd1498Szrj constexpr pair(pair<_U1, _U2>&& __p) 350*38fd1498Szrj : first(std::forward<_U1>(__p.first)), 351*38fd1498Szrj second(std::forward<_U2>(__p.second)) { } 352*38fd1498Szrj 353*38fd1498Szrj template<typename _U1, typename _U2, typename 354*38fd1498Szrj enable_if<_PCCFP<_U1, _U2>::template 355*38fd1498Szrj _MoveConstructiblePair<_U1, _U2>() 356*38fd1498Szrj && !_PCCFP<_U1, _U2>::template 357*38fd1498Szrj _ImplicitlyMoveConvertiblePair<_U1, _U2>(), 358*38fd1498Szrj bool>::type=false> 359*38fd1498Szrj explicit constexpr pair(pair<_U1, _U2>&& __p) 360*38fd1498Szrj : first(std::forward<_U1>(__p.first)), 361*38fd1498Szrj second(std::forward<_U2>(__p.second)) { } 362*38fd1498Szrj 363*38fd1498Szrj template<typename... _Args1, typename... _Args2> 364*38fd1498Szrj pair(piecewise_construct_t, tuple<_Args1...>, tuple<_Args2...>); 365*38fd1498Szrj 366*38fd1498Szrj pair& 367*38fd1498Szrj operator=(typename conditional< 368*38fd1498Szrj __and_<is_copy_assignable<_T1>, 369*38fd1498Szrj is_copy_assignable<_T2>>::value, 370*38fd1498Szrj const pair&, const __nonesuch_no_braces&>::type __p) 371*38fd1498Szrj { 372*38fd1498Szrj first = __p.first; 373*38fd1498Szrj second = __p.second; 374*38fd1498Szrj return *this; 375*38fd1498Szrj } 376*38fd1498Szrj 377*38fd1498Szrj pair& 378*38fd1498Szrj operator=(typename conditional< 379*38fd1498Szrj __not_<__and_<is_copy_assignable<_T1>, 380*38fd1498Szrj is_copy_assignable<_T2>>>::value, 381*38fd1498Szrj const pair&, const __nonesuch_no_braces&>::type __p) = delete; 382*38fd1498Szrj 383*38fd1498Szrj pair& 384*38fd1498Szrj operator=(typename conditional< 385*38fd1498Szrj __and_<is_move_assignable<_T1>, 386*38fd1498Szrj is_move_assignable<_T2>>::value, 387*38fd1498Szrj pair&&, __nonesuch_no_braces&&>::type __p) 388*38fd1498Szrj noexcept(__and_<is_nothrow_move_assignable<_T1>, 389*38fd1498Szrj is_nothrow_move_assignable<_T2>>::value) 390*38fd1498Szrj { 391*38fd1498Szrj first = std::forward<first_type>(__p.first); 392*38fd1498Szrj second = std::forward<second_type>(__p.second); 393*38fd1498Szrj return *this; 394*38fd1498Szrj } 395*38fd1498Szrj 396*38fd1498Szrj template<typename _U1, typename _U2> 397*38fd1498Szrj typename enable_if<__and_<is_assignable<_T1&, const _U1&>, 398*38fd1498Szrj is_assignable<_T2&, const _U2&>>::value, 399*38fd1498Szrj pair&>::type 400*38fd1498Szrj operator=(const pair<_U1, _U2>& __p) 401*38fd1498Szrj { 402*38fd1498Szrj first = __p.first; 403*38fd1498Szrj second = __p.second; 404*38fd1498Szrj return *this; 405*38fd1498Szrj } 406*38fd1498Szrj 407*38fd1498Szrj template<typename _U1, typename _U2> 408*38fd1498Szrj typename enable_if<__and_<is_assignable<_T1&, _U1&&>, 409*38fd1498Szrj is_assignable<_T2&, _U2&&>>::value, 410*38fd1498Szrj pair&>::type 411*38fd1498Szrj operator=(pair<_U1, _U2>&& __p) 412*38fd1498Szrj { 413*38fd1498Szrj first = std::forward<_U1>(__p.first); 414*38fd1498Szrj second = std::forward<_U2>(__p.second); 415*38fd1498Szrj return *this; 416*38fd1498Szrj } 417*38fd1498Szrj 418*38fd1498Szrj void 419*38fd1498Szrj swap(pair& __p) 420*38fd1498Szrj noexcept(__and_<__is_nothrow_swappable<_T1>, 421*38fd1498Szrj __is_nothrow_swappable<_T2>>::value) 422*38fd1498Szrj { 423*38fd1498Szrj using std::swap; 424*38fd1498Szrj swap(first, __p.first); 425*38fd1498Szrj swap(second, __p.second); 426*38fd1498Szrj } 427*38fd1498Szrj 428*38fd1498Szrj private: 429*38fd1498Szrj template<typename... _Args1, std::size_t... _Indexes1, 430*38fd1498Szrj typename... _Args2, std::size_t... _Indexes2> 431*38fd1498Szrj pair(tuple<_Args1...>&, tuple<_Args2...>&, 432*38fd1498Szrj _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>); 433*38fd1498Szrj #endif 434*38fd1498Szrj }; 435*38fd1498Szrj 436*38fd1498Szrj #if __cpp_deduction_guides >= 201606 437*38fd1498Szrj template<typename _T1, typename _T2> pair(_T1, _T2) -> pair<_T1, _T2>; 438*38fd1498Szrj #endif 439*38fd1498Szrj 440*38fd1498Szrj /// Two pairs of the same type are equal iff their members are equal. 441*38fd1498Szrj template<typename _T1, typename _T2> 442*38fd1498Szrj inline _GLIBCXX_CONSTEXPR bool 443*38fd1498Szrj operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) 444*38fd1498Szrj { return __x.first == __y.first && __x.second == __y.second; } 445*38fd1498Szrj 446*38fd1498Szrj /// <http://gcc.gnu.org/onlinedocs/libstdc++/manual/utilities.html> 447*38fd1498Szrj template<typename _T1, typename _T2> 448*38fd1498Szrj inline _GLIBCXX_CONSTEXPR bool 449*38fd1498Szrj operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) 450*38fd1498Szrj { return __x.first < __y.first 451*38fd1498Szrj || (!(__y.first < __x.first) && __x.second < __y.second); } 452*38fd1498Szrj 453*38fd1498Szrj /// Uses @c operator== to find the result. 454*38fd1498Szrj template<typename _T1, typename _T2> 455*38fd1498Szrj inline _GLIBCXX_CONSTEXPR bool 456*38fd1498Szrj operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) 457*38fd1498Szrj { return !(__x == __y); } 458*38fd1498Szrj 459*38fd1498Szrj /// Uses @c operator< to find the result. 460*38fd1498Szrj template<typename _T1, typename _T2> 461*38fd1498Szrj inline _GLIBCXX_CONSTEXPR bool 462*38fd1498Szrj operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) 463*38fd1498Szrj { return __y < __x; } 464*38fd1498Szrj 465*38fd1498Szrj /// Uses @c operator< to find the result. 466*38fd1498Szrj template<typename _T1, typename _T2> 467*38fd1498Szrj inline _GLIBCXX_CONSTEXPR bool 468*38fd1498Szrj operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) 469*38fd1498Szrj { return !(__y < __x); } 470*38fd1498Szrj 471*38fd1498Szrj /// Uses @c operator< to find the result. 472*38fd1498Szrj template<typename _T1, typename _T2> 473*38fd1498Szrj inline _GLIBCXX_CONSTEXPR bool 474*38fd1498Szrj operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) 475*38fd1498Szrj { return !(__x < __y); } 476*38fd1498Szrj 477*38fd1498Szrj #if __cplusplus >= 201103L 478*38fd1498Szrj /// See std::pair::swap(). 479*38fd1498Szrj // Note: no std::swap overloads in C++03 mode, this has performance 480*38fd1498Szrj // implications, see, eg, libstdc++/38466. 481*38fd1498Szrj template<typename _T1, typename _T2> 482*38fd1498Szrj inline 483*38fd1498Szrj #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 484*38fd1498Szrj // Constrained free swap overload, see p0185r1 485*38fd1498Szrj typename enable_if<__and_<__is_swappable<_T1>, 486*38fd1498Szrj __is_swappable<_T2>>::value>::type 487*38fd1498Szrj #else 488*38fd1498Szrj void 489*38fd1498Szrj #endif 490*38fd1498Szrj swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) 491*38fd1498Szrj noexcept(noexcept(__x.swap(__y))) 492*38fd1498Szrj { __x.swap(__y); } 493*38fd1498Szrj 494*38fd1498Szrj #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 495*38fd1498Szrj template<typename _T1, typename _T2> 496*38fd1498Szrj typename enable_if<!__and_<__is_swappable<_T1>, 497*38fd1498Szrj __is_swappable<_T2>>::value>::type 498*38fd1498Szrj swap(pair<_T1, _T2>&, pair<_T1, _T2>&) = delete; 499*38fd1498Szrj #endif 500*38fd1498Szrj #endif // __cplusplus >= 201103L 501*38fd1498Szrj 502*38fd1498Szrj /** 503*38fd1498Szrj * @brief A convenience wrapper for creating a pair from two objects. 504*38fd1498Szrj * @param __x The first object. 505*38fd1498Szrj * @param __y The second object. 506*38fd1498Szrj * @return A newly-constructed pair<> object of the appropriate type. 507*38fd1498Szrj * 508*38fd1498Szrj * The standard requires that the objects be passed by reference-to-const, 509*38fd1498Szrj * but LWG issue #181 says they should be passed by const value. We follow 510*38fd1498Szrj * the LWG by default. 511*38fd1498Szrj */ 512*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 513*38fd1498Szrj // 181. make_pair() unintended behavior 514*38fd1498Szrj #if __cplusplus >= 201103L 515*38fd1498Szrj // NB: DR 706. 516*38fd1498Szrj template<typename _T1, typename _T2> 517*38fd1498Szrj constexpr pair<typename __decay_and_strip<_T1>::__type, 518*38fd1498Szrj typename __decay_and_strip<_T2>::__type> 519*38fd1498Szrj make_pair(_T1&& __x, _T2&& __y) 520*38fd1498Szrj { 521*38fd1498Szrj typedef typename __decay_and_strip<_T1>::__type __ds_type1; 522*38fd1498Szrj typedef typename __decay_and_strip<_T2>::__type __ds_type2; 523*38fd1498Szrj typedef pair<__ds_type1, __ds_type2> __pair_type; 524*38fd1498Szrj return __pair_type(std::forward<_T1>(__x), std::forward<_T2>(__y)); 525*38fd1498Szrj } 526*38fd1498Szrj #else 527*38fd1498Szrj template<typename _T1, typename _T2> 528*38fd1498Szrj inline pair<_T1, _T2> 529*38fd1498Szrj make_pair(_T1 __x, _T2 __y) 530*38fd1498Szrj { return pair<_T1, _T2>(__x, __y); } 531*38fd1498Szrj #endif 532*38fd1498Szrj 533*38fd1498Szrj /// @} 534*38fd1498Szrj 535*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION 536*38fd1498Szrj } // namespace std 537*38fd1498Szrj 538*38fd1498Szrj #endif /* _STL_PAIR_H */ 539