1// -*- C++ -*- 2//===-------------------------- utility -----------------------------------===// 3// 4// The LLVM Compiler Infrastructure 5// 6// This file is dual licensed under the MIT and the University of Illinois Open 7// Source Licenses. See LICENSE.TXT for details. 8// 9//===----------------------------------------------------------------------===// 10 11#ifndef _LIBCPP_UTILITY 12#define _LIBCPP_UTILITY 13 14/* 15 utility synopsis 16 17namespace std 18{ 19 20template <class T> 21 void 22 swap(T& a, T& b); 23 24namespace rel_ops 25{ 26 template<class T> bool operator!=(const T&, const T&); 27 template<class T> bool operator> (const T&, const T&); 28 template<class T> bool operator<=(const T&, const T&); 29 template<class T> bool operator>=(const T&, const T&); 30} 31 32template<class T> 33void 34swap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value && 35 is_nothrow_move_assignable<T>::value); 36 37template <class T, size_t N> 38void 39swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b))); 40 41template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; // constexpr in C++14 42template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++14 43 44template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14 45 46template <class T> 47 typename conditional 48 < 49 !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value, 50 const T&, 51 T&& 52 >::type 53 move_if_noexcept(T& x) noexcept; // constexpr in C++14 54 55template <class T> typename add_rvalue_reference<T>::type declval() noexcept; 56 57template <class T1, class T2> 58struct pair 59{ 60 typedef T1 first_type; 61 typedef T2 second_type; 62 63 T1 first; 64 T2 second; 65 66 pair(const pair&) = default; 67 pair(pair&&) = default; 68 constexpr pair(); 69 pair(const T1& x, const T2& y); // constexpr in C++14 70 template <class U, class V> pair(U&& x, V&& y); // constexpr in C++14 71 template <class U, class V> pair(const pair<U, V>& p); // constexpr in C++14 72 template <class U, class V> pair(pair<U, V>&& p); // constexpr in C++14 73 template <class... Args1, class... Args2> 74 pair(piecewise_construct_t, tuple<Args1...> first_args, 75 tuple<Args2...> second_args); 76 77 template <class U, class V> pair& operator=(const pair<U, V>& p); 78 pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value && 79 is_nothrow_move_assignable<T2>::value); 80 template <class U, class V> pair& operator=(pair<U, V>&& p); 81 82 void swap(pair& p) noexcept(noexcept(swap(first, p.first)) && 83 noexcept(swap(second, p.second))); 84}; 85 86template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 87template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 88template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 89template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 90template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 91template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 92 93template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14 94template <class T1, class T2> 95void 96swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); 97 98struct piecewise_construct_t { }; 99constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); 100 101template <class T> class tuple_size; 102template <size_t I, class T> class tuple_element; 103 104template <class T1, class T2> struct tuple_size<pair<T1, T2> >; 105template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >; 106template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >; 107 108template<size_t I, class T1, class T2> 109 typename tuple_element<I, pair<T1, T2> >::type& 110 get(pair<T1, T2>&) noexcept; // constexpr in C++14 111 112template<size_t I, class T1, class T2> 113 const typename const tuple_element<I, pair<T1, T2> >::type& 114 get(const pair<T1, T2>&) noexcept; // constexpr in C++14 115 116template<size_t I, class T1, class T2> 117 typename tuple_element<I, pair<T1, T2> >::type&& 118 get(pair<T1, T2>&&) noexcept; // constexpr in C++14 119 120template<class T1, class T2> 121 constexpr T1& get(pair<T1, T2>&) noexcept; // C++14 122 123template<size_t I, class T1, class T2> 124 constexpr T1 const& get(pair<T1, T2> const &) noexcept; // C++14 125 126template<size_t I, class T1, class T2> 127 constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14 128 129// C++14 130 131template<class T, T... I> 132struct integer_sequence 133{ 134 typedef T value_type; 135 136 static constexpr size_t size() noexcept; 137}; 138 139template<size_t... I> 140 using index_sequence = integer_sequence<size_t, I...>; 141 142template<class T, T N> 143 using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>; 144template<size_t N> 145 using make_index_sequence = make_integer_sequence<size_t, N>; 146 147template<class... T> 148 using index_sequence_for = make_index_sequence<sizeof...(T)>; 149 150template<class T, class U=T> 151 T exchange(T& obj, U&& new_value); 152} // std 153 154*/ 155 156#include <__config> 157#include <__tuple> 158#include <type_traits> 159 160#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 161#pragma GCC system_header 162#endif 163 164_LIBCPP_BEGIN_NAMESPACE_STD 165 166namespace rel_ops 167{ 168 169template<class _Tp> 170inline _LIBCPP_INLINE_VISIBILITY 171bool 172operator!=(const _Tp& __x, const _Tp& __y) 173{ 174 return !(__x == __y); 175} 176 177template<class _Tp> 178inline _LIBCPP_INLINE_VISIBILITY 179bool 180operator> (const _Tp& __x, const _Tp& __y) 181{ 182 return __y < __x; 183} 184 185template<class _Tp> 186inline _LIBCPP_INLINE_VISIBILITY 187bool 188operator<=(const _Tp& __x, const _Tp& __y) 189{ 190 return !(__y < __x); 191} 192 193template<class _Tp> 194inline _LIBCPP_INLINE_VISIBILITY 195bool 196operator>=(const _Tp& __x, const _Tp& __y) 197{ 198 return !(__x < __y); 199} 200 201} // rel_ops 202 203// swap_ranges 204 205// forward 206template<class _Tp, size_t _Np> 207void swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value); 208 209template <class _ForwardIterator1, class _ForwardIterator2> 210inline _LIBCPP_INLINE_VISIBILITY 211_ForwardIterator2 212swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) 213{ 214 for(; __first1 != __last1; ++__first1, (void) ++__first2) 215 swap(*__first1, *__first2); 216 return __first2; 217} 218 219template<class _Tp, size_t _Np> 220inline _LIBCPP_INLINE_VISIBILITY 221void 222swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) 223{ 224 _VSTD::swap_ranges(__a, __a + _Np, __b); 225} 226 227template <class _Tp> 228inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 229#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 230typename conditional 231< 232 !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, 233 const _Tp&, 234 _Tp&& 235>::type 236#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 237const _Tp& 238#endif 239move_if_noexcept(_Tp& __x) _NOEXCEPT 240{ 241 return _VSTD::move(__x); 242} 243 244struct _LIBCPP_TYPE_VIS_ONLY piecewise_construct_t { }; 245#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_UTILITY) 246extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t(); 247#else 248constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); 249#endif 250 251template <class _T1, class _T2> 252struct _LIBCPP_TYPE_VIS_ONLY pair 253{ 254 typedef _T1 first_type; 255 typedef _T2 second_type; 256 257 _T1 first; 258 _T2 second; 259 260 // pair(const pair&) = default; 261 // pair(pair&&) = default; 262 263 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {} 264 265 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 266 pair(const _T1& __x, const _T2& __y) 267 : first(__x), second(__y) {} 268 269 template<class _U1, class _U2> 270 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 271 pair(const pair<_U1, _U2>& __p 272#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE 273 ,typename enable_if<is_convertible<const _U1&, _T1>::value && 274 is_convertible<const _U2&, _T2>::value>::type* = 0 275#endif 276 ) 277 : first(__p.first), second(__p.second) {} 278 279#if !defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && _LIBCPP_TRIVIAL_PAIR_COPY_CTOR 280 _LIBCPP_INLINE_VISIBILITY 281 pair(const pair& __p) = default; 282#elif !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) || !_LIBCPP_TRIVIAL_PAIR_COPY_CTOR 283 _LIBCPP_INLINE_VISIBILITY 284 pair(const pair& __p) 285 _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value && 286 is_nothrow_copy_constructible<second_type>::value) 287 : first(__p.first), 288 second(__p.second) 289 { 290 } 291#endif 292 293 _LIBCPP_INLINE_VISIBILITY 294 pair& operator=(const pair& __p) 295 _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value && 296 is_nothrow_copy_assignable<second_type>::value) 297 { 298 first = __p.first; 299 second = __p.second; 300 return *this; 301 } 302 303#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 304 305 template <class _U1, class _U2, 306 class = typename enable_if<is_convertible<_U1, first_type>::value && 307 is_convertible<_U2, second_type>::value>::type> 308 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 309 pair(_U1&& __u1, _U2&& __u2) 310 : first(_VSTD::forward<_U1>(__u1)), 311 second(_VSTD::forward<_U2>(__u2)) 312 {} 313 314 template<class _U1, class _U2> 315 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 316 pair(pair<_U1, _U2>&& __p, 317 typename enable_if<is_convertible<_U1, _T1>::value && 318 is_convertible<_U2, _T2>::value>::type* = 0) 319 : first(_VSTD::forward<_U1>(__p.first)), 320 second(_VSTD::forward<_U2>(__p.second)) {} 321 322#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 323 _LIBCPP_INLINE_VISIBILITY 324 pair(pair&& __p) = default; 325#else 326 _LIBCPP_INLINE_VISIBILITY 327 pair(pair&& __p) _NOEXCEPT_(is_nothrow_move_constructible<first_type>::value && 328 is_nothrow_move_constructible<second_type>::value) 329 : first(_VSTD::forward<first_type>(__p.first)), 330 second(_VSTD::forward<second_type>(__p.second)) 331 { 332 } 333#endif 334 335 _LIBCPP_INLINE_VISIBILITY 336 pair& 337 operator=(pair&& __p) _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value && 338 is_nothrow_move_assignable<second_type>::value) 339 { 340 first = _VSTD::forward<first_type>(__p.first); 341 second = _VSTD::forward<second_type>(__p.second); 342 return *this; 343 } 344 345#ifndef _LIBCPP_HAS_NO_VARIADICS 346 347 template<class _Tuple, 348 class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type> 349 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 350 pair(_Tuple&& __p) 351 : first(_VSTD::forward<typename tuple_element<0, 352 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<0>(__p))), 353 second(_VSTD::forward<typename tuple_element<1, 354 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<1>(__p))) 355 {} 356 357 358 359 template <class... _Args1, class... _Args2> 360 _LIBCPP_INLINE_VISIBILITY 361 pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, 362 tuple<_Args2...> __second_args) 363 : pair(__pc, __first_args, __second_args, 364 typename __make_tuple_indices<sizeof...(_Args1)>::type(), 365 typename __make_tuple_indices<sizeof...(_Args2) >::type()) 366 {} 367 368 template <class _Tuple, 369 class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type> 370 _LIBCPP_INLINE_VISIBILITY 371 pair& 372 operator=(_Tuple&& __p) 373 { 374 typedef typename __make_tuple_types<_Tuple>::type _TupleRef; 375 typedef typename tuple_element<0, _TupleRef>::type _U0; 376 typedef typename tuple_element<1, _TupleRef>::type _U1; 377 first = _VSTD::forward<_U0>(_VSTD::get<0>(__p)); 378 second = _VSTD::forward<_U1>(_VSTD::get<1>(__p)); 379 return *this; 380 } 381 382#endif // _LIBCPP_HAS_NO_VARIADICS 383 384#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 385 _LIBCPP_INLINE_VISIBILITY 386 void 387 swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value && 388 __is_nothrow_swappable<second_type>::value) 389 { 390 _VSTD::iter_swap(&first, &__p.first); 391 _VSTD::iter_swap(&second, &__p.second); 392 } 393private: 394 395#ifndef _LIBCPP_HAS_NO_VARIADICS 396 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> 397 _LIBCPP_INLINE_VISIBILITY 398 pair(piecewise_construct_t, 399 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, 400 __tuple_indices<_I1...>, __tuple_indices<_I2...>); 401#endif // _LIBCPP_HAS_NO_VARIADICS 402}; 403 404template <class _T1, class _T2> 405inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 406bool 407operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 408{ 409 return __x.first == __y.first && __x.second == __y.second; 410} 411 412template <class _T1, class _T2> 413inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 414bool 415operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 416{ 417 return !(__x == __y); 418} 419 420template <class _T1, class _T2> 421inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 422bool 423operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 424{ 425 return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second); 426} 427 428template <class _T1, class _T2> 429inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 430bool 431operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 432{ 433 return __y < __x; 434} 435 436template <class _T1, class _T2> 437inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 438bool 439operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 440{ 441 return !(__x < __y); 442} 443 444template <class _T1, class _T2> 445inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 446bool 447operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 448{ 449 return !(__y < __x); 450} 451 452template <class _T1, class _T2> 453inline _LIBCPP_INLINE_VISIBILITY 454typename enable_if 455< 456 __is_swappable<_T1>::value && 457 __is_swappable<_T2>::value, 458 void 459>::type 460swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) 461 _NOEXCEPT_((__is_nothrow_swappable<_T1>::value && 462 __is_nothrow_swappable<_T2>::value)) 463{ 464 __x.swap(__y); 465} 466 467#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 468 469template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY reference_wrapper; 470 471template <class _Tp> 472struct __make_pair_return_impl 473{ 474 typedef _Tp type; 475}; 476 477template <class _Tp> 478struct __make_pair_return_impl<reference_wrapper<_Tp>> 479{ 480 typedef _Tp& type; 481}; 482 483template <class _Tp> 484struct __make_pair_return 485{ 486 typedef typename __make_pair_return_impl<typename decay<_Tp>::type>::type type; 487}; 488 489template <class _T1, class _T2> 490inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 491pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type> 492make_pair(_T1&& __t1, _T2&& __t2) 493{ 494 return pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type> 495 (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2)); 496} 497 498#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 499 500template <class _T1, class _T2> 501inline _LIBCPP_INLINE_VISIBILITY 502pair<_T1,_T2> 503make_pair(_T1 __x, _T2 __y) 504{ 505 return pair<_T1, _T2>(__x, __y); 506} 507 508#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 509 510template <class _T1, class _T2> 511 class _LIBCPP_TYPE_VIS_ONLY tuple_size<pair<_T1, _T2> > 512 : public integral_constant<size_t, 2> {}; 513 514template <class _T1, class _T2> 515 class _LIBCPP_TYPE_VIS_ONLY tuple_size<const pair<_T1, _T2> > 516 : public integral_constant<size_t, 2> {}; 517 518template <class _T1, class _T2> 519class _LIBCPP_TYPE_VIS_ONLY tuple_element<0, pair<_T1, _T2> > 520{ 521public: 522 typedef _T1 type; 523}; 524 525template <class _T1, class _T2> 526class _LIBCPP_TYPE_VIS_ONLY tuple_element<1, pair<_T1, _T2> > 527{ 528public: 529 typedef _T2 type; 530}; 531 532template <class _T1, class _T2> 533class _LIBCPP_TYPE_VIS_ONLY tuple_element<0, const pair<_T1, _T2> > 534{ 535public: 536 typedef const _T1 type; 537}; 538 539template <class _T1, class _T2> 540class _LIBCPP_TYPE_VIS_ONLY tuple_element<1, const pair<_T1, _T2> > 541{ 542public: 543 typedef const _T2 type; 544}; 545 546template <size_t _Ip> struct __get_pair; 547 548template <> 549struct __get_pair<0> 550{ 551 template <class _T1, class _T2> 552 static 553 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 554 _T1& 555 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} 556 557 template <class _T1, class _T2> 558 static 559 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 560 const _T1& 561 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} 562 563#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 564 565 template <class _T1, class _T2> 566 static 567 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 568 _T1&& 569 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);} 570 571#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 572}; 573 574template <> 575struct __get_pair<1> 576{ 577 template <class _T1, class _T2> 578 static 579 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 580 _T2& 581 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} 582 583 template <class _T1, class _T2> 584 static 585 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 586 const _T2& 587 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} 588 589#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 590 591 template <class _T1, class _T2> 592 static 593 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 594 _T2&& 595 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);} 596 597#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 598}; 599 600template <size_t _Ip, class _T1, class _T2> 601inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 602typename tuple_element<_Ip, pair<_T1, _T2> >::type& 603get(pair<_T1, _T2>& __p) _NOEXCEPT 604{ 605 return __get_pair<_Ip>::get(__p); 606} 607 608template <size_t _Ip, class _T1, class _T2> 609inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 610const typename tuple_element<_Ip, pair<_T1, _T2> >::type& 611get(const pair<_T1, _T2>& __p) _NOEXCEPT 612{ 613 return __get_pair<_Ip>::get(__p); 614} 615 616#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 617 618template <size_t _Ip, class _T1, class _T2> 619inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 620typename tuple_element<_Ip, pair<_T1, _T2> >::type&& 621get(pair<_T1, _T2>&& __p) _NOEXCEPT 622{ 623 return __get_pair<_Ip>::get(_VSTD::move(__p)); 624} 625 626#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 627 628#if _LIBCPP_STD_VER > 11 629template <class _T1, class _T2> 630inline _LIBCPP_INLINE_VISIBILITY 631constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT 632{ 633 return __get_pair<0>::get(__p); 634} 635 636template <class _T1, class _T2> 637inline _LIBCPP_INLINE_VISIBILITY 638constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT 639{ 640 return __get_pair<0>::get(__p); 641} 642 643template <class _T1, class _T2> 644inline _LIBCPP_INLINE_VISIBILITY 645constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT 646{ 647 return __get_pair<0>::get(_VSTD::move(__p)); 648} 649 650template <class _T1, class _T2> 651inline _LIBCPP_INLINE_VISIBILITY 652constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT 653{ 654 return __get_pair<1>::get(__p); 655} 656 657template <class _T1, class _T2> 658inline _LIBCPP_INLINE_VISIBILITY 659constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT 660{ 661 return __get_pair<1>::get(__p); 662} 663 664template <class _T1, class _T2> 665inline _LIBCPP_INLINE_VISIBILITY 666constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT 667{ 668 return __get_pair<1>::get(_VSTD::move(__p)); 669} 670 671#endif 672 673#if _LIBCPP_STD_VER > 11 674 675template<class _Tp, _Tp... _Ip> 676struct _LIBCPP_TYPE_VIS_ONLY integer_sequence 677{ 678 typedef _Tp value_type; 679 static_assert( is_integral<_Tp>::value, 680 "std::integer_sequence can only be instantiated with an integral type" ); 681 static 682 _LIBCPP_INLINE_VISIBILITY 683 constexpr 684 size_t 685 size() noexcept { return sizeof...(_Ip); } 686}; 687 688template<size_t... _Ip> 689 using index_sequence = integer_sequence<size_t, _Ip...>; 690 691namespace __detail { 692 693template<typename _Tp, size_t ..._Extra> struct __repeat; 694template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<integer_sequence<_Tp, _Np...>, _Extra...> { 695 typedef integer_sequence<_Tp, 696 _Np..., 697 sizeof...(_Np) + _Np..., 698 2 * sizeof...(_Np) + _Np..., 699 3 * sizeof...(_Np) + _Np..., 700 4 * sizeof...(_Np) + _Np..., 701 5 * sizeof...(_Np) + _Np..., 702 6 * sizeof...(_Np) + _Np..., 703 7 * sizeof...(_Np) + _Np..., 704 _Extra...> type; 705}; 706 707template<size_t _Np> struct __parity; 708template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {}; 709 710template<> struct __make<0> { typedef integer_sequence<size_t> type; }; 711template<> struct __make<1> { typedef integer_sequence<size_t, 0> type; }; 712template<> struct __make<2> { typedef integer_sequence<size_t, 0, 1> type; }; 713template<> struct __make<3> { typedef integer_sequence<size_t, 0, 1, 2> type; }; 714template<> struct __make<4> { typedef integer_sequence<size_t, 0, 1, 2, 3> type; }; 715template<> struct __make<5> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4> type; }; 716template<> struct __make<6> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4, 5> type; }; 717template<> struct __make<7> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4, 5, 6> type; }; 718 719template<> struct __parity<0> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type> {}; }; 720template<> struct __parity<1> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 1> {}; }; 721template<> struct __parity<2> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 2, _Np - 1> {}; }; 722template<> struct __parity<3> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 3, _Np - 2, _Np - 1> {}; }; 723template<> struct __parity<4> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; }; 724template<> struct __parity<5> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; }; 725template<> struct __parity<6> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; }; 726template<> struct __parity<7> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 7, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; }; 727 728template<typename _Tp, typename _Up> struct __convert { 729 template<typename> struct __result; 730 template<_Tp ..._Np> struct __result<integer_sequence<_Tp, _Np...> > { typedef integer_sequence<_Up, _Np...> type; }; 731}; 732template<typename _Tp> struct __convert<_Tp, _Tp> { template<typename _Up> struct __result { typedef _Up type; }; }; 733 734} 735 736template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked = 737 typename __detail::__convert<size_t, _Tp>::template __result<typename __detail::__make<_Np>::type>::type; 738 739template <class _Tp, _Tp _Ep> 740struct __make_integer_sequence 741{ 742 static_assert(is_integral<_Tp>::value, 743 "std::make_integer_sequence can only be instantiated with an integral type" ); 744 static_assert(0 <= _Ep, "std::make_integer_sequence input shall not be negative"); 745 typedef __make_integer_sequence_unchecked<_Tp, _Ep> type; 746}; 747 748template<class _Tp, _Tp _Np> 749 using make_integer_sequence = typename __make_integer_sequence<_Tp, _Np>::type; 750 751template<size_t _Np> 752 using make_index_sequence = make_integer_sequence<size_t, _Np>; 753 754template<class... _Tp> 755 using index_sequence_for = make_index_sequence<sizeof...(_Tp)>; 756 757#endif // _LIBCPP_STD_VER > 11 758 759#if _LIBCPP_STD_VER > 11 760template<class _T1, class _T2 = _T1> 761inline _LIBCPP_INLINE_VISIBILITY 762_T1 exchange(_T1& __obj, _T2 && __new_value) 763{ 764 _T1 __old_value = _VSTD::move(__obj); 765 __obj = _VSTD::forward<_T2>(__new_value); 766 return __old_value; 767} 768#endif // _LIBCPP_STD_VER > 11 769 770_LIBCPP_END_NAMESPACE_STD 771 772#endif // _LIBCPP_UTILITY 773