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 17#include <initializer_list> 18 19namespace std 20{ 21 22template <class T> 23 void 24 swap(T& a, T& b); 25 26namespace rel_ops 27{ 28 template<class T> bool operator!=(const T&, const T&); 29 template<class T> bool operator> (const T&, const T&); 30 template<class T> bool operator<=(const T&, const T&); 31 template<class T> bool operator>=(const T&, const T&); 32} 33 34template<class T> 35void 36swap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value && 37 is_nothrow_move_assignable<T>::value); 38 39template <class T, size_t N> 40void 41swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b))); 42 43template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; // constexpr in C++14 44template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++14 45 46template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14 47 48template <class T> 49 typename conditional 50 < 51 !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value, 52 const T&, 53 T&& 54 >::type 55 move_if_noexcept(T& x) noexcept; // constexpr in C++14 56 57template <class T> constexpr add_const_t<T>& as_const(T& t) noexcept; // C++17 58template <class T> void as_const(const T&&) = delete; // C++17 59 60template <class T> typename add_rvalue_reference<T>::type declval() noexcept; 61 62template <class T1, class T2> 63struct pair 64{ 65 typedef T1 first_type; 66 typedef T2 second_type; 67 68 T1 first; 69 T2 second; 70 71 pair(const pair&) = default; 72 pair(pair&&) = default; 73 constexpr pair(); 74 pair(const T1& x, const T2& y); // constexpr in C++14 75 template <class U, class V> pair(U&& x, V&& y); // constexpr in C++14 76 template <class U, class V> pair(const pair<U, V>& p); // constexpr in C++14 77 template <class U, class V> pair(pair<U, V>&& p); // constexpr in C++14 78 template <class... Args1, class... Args2> 79 pair(piecewise_construct_t, tuple<Args1...> first_args, 80 tuple<Args2...> second_args); 81 82 template <class U, class V> pair& operator=(const pair<U, V>& p); 83 pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value && 84 is_nothrow_move_assignable<T2>::value); 85 template <class U, class V> pair& operator=(pair<U, V>&& p); 86 87 void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> && 88 is_nothrow_swappable_v<T2>); 89}; 90 91template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 92template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 93template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 94template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 95template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 96template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 97 98template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14 99template <class T1, class T2> 100void 101swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); 102 103struct piecewise_construct_t { }; 104inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); 105 106template <class T> class tuple_size; 107template <size_t I, class T> class tuple_element; 108 109template <class T1, class T2> struct tuple_size<pair<T1, T2> >; 110template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >; 111template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >; 112 113template<size_t I, class T1, class T2> 114 typename tuple_element<I, pair<T1, T2> >::type& 115 get(pair<T1, T2>&) noexcept; // constexpr in C++14 116 117template<size_t I, class T1, class T2> 118 const typename tuple_element<I, pair<T1, T2> >::type& 119 get(const pair<T1, T2>&) noexcept; // constexpr in C++14 120 121template<size_t I, class T1, class T2> 122 typename tuple_element<I, pair<T1, T2> >::type&& 123 get(pair<T1, T2>&&) noexcept; // constexpr in C++14 124 125template<size_t I, class T1, class T2> 126 const typename tuple_element<I, pair<T1, T2> >::type&& 127 get(const pair<T1, T2>&&) noexcept; // constexpr in C++14 128 129template<class T1, class T2> 130 constexpr T1& get(pair<T1, T2>&) noexcept; // C++14 131 132template<class T1, class T2> 133 constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14 134 135template<class T1, class T2> 136 constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14 137 138template<class T1, class T2> 139 constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14 140 141template<class T1, class T2> 142 constexpr T1& get(pair<T2, T1>&) noexcept; // C++14 143 144template<class T1, class T2> 145 constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14 146 147template<class T1, class T2> 148 constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14 149 150template<class T1, class T2> 151 constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14 152 153// C++14 154 155template<class T, T... I> 156struct integer_sequence 157{ 158 typedef T value_type; 159 160 static constexpr size_t size() noexcept; 161}; 162 163template<size_t... I> 164 using index_sequence = integer_sequence<size_t, I...>; 165 166template<class T, T N> 167 using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>; 168template<size_t N> 169 using make_index_sequence = make_integer_sequence<size_t, N>; 170 171template<class... T> 172 using index_sequence_for = make_index_sequence<sizeof...(T)>; 173 174template<class T, class U=T> 175 T exchange(T& obj, U&& new_value); 176 177// 20.2.7, in-place construction // C++17 178struct in_place_t { 179 explicit in_place_t() = default; 180}; 181inline constexpr in_place_t in_place{}; 182template <class T> 183 struct in_place_type_t { 184 explicit in_place_type_t() = default; 185 }; 186template <class T> 187 inline constexpr in_place_type_t<T> in_place_type{}; 188template <size_t I> 189 struct in_place_index_t { 190 explicit in_place_index_t() = default; 191 }; 192template <size_t I> 193 inline constexpr in_place_index_t<I> in_place_index{}; 194 195} // std 196 197*/ 198 199#include <__config> 200#include <__tuple> 201#include <type_traits> 202#include <initializer_list> 203#include <cstddef> 204#include <cstring> 205#include <cstdint> 206#include <version> 207#include <__debug> 208 209#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 210#pragma GCC system_header 211#endif 212 213_LIBCPP_BEGIN_NAMESPACE_STD 214 215namespace rel_ops 216{ 217 218template<class _Tp> 219inline _LIBCPP_INLINE_VISIBILITY 220bool 221operator!=(const _Tp& __x, const _Tp& __y) 222{ 223 return !(__x == __y); 224} 225 226template<class _Tp> 227inline _LIBCPP_INLINE_VISIBILITY 228bool 229operator> (const _Tp& __x, const _Tp& __y) 230{ 231 return __y < __x; 232} 233 234template<class _Tp> 235inline _LIBCPP_INLINE_VISIBILITY 236bool 237operator<=(const _Tp& __x, const _Tp& __y) 238{ 239 return !(__y < __x); 240} 241 242template<class _Tp> 243inline _LIBCPP_INLINE_VISIBILITY 244bool 245operator>=(const _Tp& __x, const _Tp& __y) 246{ 247 return !(__x < __y); 248} 249 250} // rel_ops 251 252// swap_ranges 253 254 255template <class _ForwardIterator1, class _ForwardIterator2> 256inline _LIBCPP_INLINE_VISIBILITY 257_ForwardIterator2 258swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) 259{ 260 for(; __first1 != __last1; ++__first1, (void) ++__first2) 261 swap(*__first1, *__first2); 262 return __first2; 263} 264 265// forward declared in <type_traits> 266template<class _Tp, size_t _Np> 267inline _LIBCPP_INLINE_VISIBILITY 268typename enable_if< 269 __is_swappable<_Tp>::value 270>::type 271swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) 272{ 273 _VSTD::swap_ranges(__a, __a + _Np, __b); 274} 275 276template <class _Tp> 277inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 278#ifndef _LIBCPP_CXX03_LANG 279typename conditional 280< 281 !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, 282 const _Tp&, 283 _Tp&& 284>::type 285#else // _LIBCPP_CXX03_LANG 286const _Tp& 287#endif 288move_if_noexcept(_Tp& __x) _NOEXCEPT 289{ 290 return _VSTD::move(__x); 291} 292 293#if _LIBCPP_STD_VER > 14 294template <class _Tp> constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; } 295template <class _Tp> void as_const(const _Tp&&) = delete; 296#endif 297 298struct _LIBCPP_TEMPLATE_VIS piecewise_construct_t { }; 299#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) 300extern _LIBCPP_EXPORTED_FROM_ABI const piecewise_construct_t piecewise_construct;// = piecewise_construct_t(); 301#else 302/* _LIBCPP_INLINE_VAR */ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); 303#endif 304 305#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR) 306struct __non_trivially_copyable_base { 307 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 308 __non_trivially_copyable_base() _NOEXCEPT {} 309 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 310 __non_trivially_copyable_base(__non_trivially_copyable_base const&) _NOEXCEPT {} 311}; 312#endif 313 314template <class _T1, class _T2> 315struct _LIBCPP_TEMPLATE_VIS pair 316#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR) 317: private __non_trivially_copyable_base 318#endif 319{ 320 typedef _T1 first_type; 321 typedef _T2 second_type; 322 323 _T1 first; 324 _T2 second; 325 326#if !defined(_LIBCPP_CXX03_LANG) 327 pair(pair const&) = default; 328 pair(pair&&) = default; 329#else 330 // Use the implicitly declared copy constructor in C++03 331#endif 332 333#ifdef _LIBCPP_CXX03_LANG 334 _LIBCPP_INLINE_VISIBILITY 335 pair() : first(), second() {} 336 337 _LIBCPP_INLINE_VISIBILITY 338 pair(_T1 const& __t1, _T2 const& __t2) : first(__t1), second(__t2) {} 339 340 template <class _U1, class _U2> 341 _LIBCPP_INLINE_VISIBILITY 342 pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {} 343 344 _LIBCPP_INLINE_VISIBILITY 345 pair& operator=(pair const& __p) { 346 first = __p.first; 347 second = __p.second; 348 return *this; 349 } 350#else 351 template <bool _Val> 352 using _EnableB = typename enable_if<_Val, bool>::type; 353 354 struct _CheckArgs { 355 template <class _U1, class _U2> 356 static constexpr bool __enable_default() { 357 return is_default_constructible<_U1>::value 358 && is_default_constructible<_U2>::value; 359 } 360 361 template <class _U1, class _U2> 362 static constexpr bool __enable_explicit() { 363 return is_constructible<first_type, _U1>::value 364 && is_constructible<second_type, _U2>::value 365 && (!is_convertible<_U1, first_type>::value 366 || !is_convertible<_U2, second_type>::value); 367 } 368 369 template <class _U1, class _U2> 370 static constexpr bool __enable_implicit() { 371 return is_constructible<first_type, _U1>::value 372 && is_constructible<second_type, _U2>::value 373 && is_convertible<_U1, first_type>::value 374 && is_convertible<_U2, second_type>::value; 375 } 376 }; 377 378 template <bool _MaybeEnable> 379 using _CheckArgsDep = typename conditional< 380 _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type; 381 382 struct _CheckTupleLikeConstructor { 383 template <class _Tuple> 384 static constexpr bool __enable_implicit() { 385 return __tuple_convertible<_Tuple, pair>::value; 386 } 387 388 template <class _Tuple> 389 static constexpr bool __enable_explicit() { 390 return __tuple_constructible<_Tuple, pair>::value 391 && !__tuple_convertible<_Tuple, pair>::value; 392 } 393 394 template <class _Tuple> 395 static constexpr bool __enable_assign() { 396 return __tuple_assignable<_Tuple, pair>::value; 397 } 398 }; 399 400 template <class _Tuple> 401 using _CheckTLC = typename conditional< 402 __tuple_like_with_size<_Tuple, 2>::value 403 && !is_same<typename decay<_Tuple>::type, pair>::value, 404 _CheckTupleLikeConstructor, 405 __check_tuple_constructor_fail 406 >::type; 407 408 template<bool _Dummy = true, _EnableB< 409 _CheckArgsDep<_Dummy>::template __enable_default<_T1, _T2>() 410 > = false> 411 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 412 pair() : first(), second() {} 413 414 template <bool _Dummy = true, _EnableB< 415 _CheckArgsDep<_Dummy>::template __enable_explicit<_T1 const&, _T2 const&>() 416 > = false> 417 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 418 explicit pair(_T1 const& __t1, _T2 const& __t2) 419 : first(__t1), second(__t2) {} 420 421 template<bool _Dummy = true, _EnableB< 422 _CheckArgsDep<_Dummy>::template __enable_implicit<_T1 const&, _T2 const&>() 423 > = false> 424 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 425 pair(_T1 const& __t1, _T2 const& __t2) 426 : first(__t1), second(__t2) {} 427 428 template<class _U1, class _U2, _EnableB< 429 _CheckArgs::template __enable_explicit<_U1, _U2>() 430 > = false> 431 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 432 explicit pair(_U1&& __u1, _U2&& __u2) 433 : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {} 434 435 template<class _U1, class _U2, _EnableB< 436 _CheckArgs::template __enable_implicit<_U1, _U2>() 437 > = false> 438 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 439 pair(_U1&& __u1, _U2&& __u2) 440 : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {} 441 442 template<class _U1, class _U2, _EnableB< 443 _CheckArgs::template __enable_explicit<_U1 const&, _U2 const&>() 444 > = false> 445 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 446 explicit pair(pair<_U1, _U2> const& __p) 447 : first(__p.first), second(__p.second) {} 448 449 template<class _U1, class _U2, _EnableB< 450 _CheckArgs::template __enable_implicit<_U1 const&, _U2 const&>() 451 > = false> 452 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 453 pair(pair<_U1, _U2> const& __p) 454 : first(__p.first), second(__p.second) {} 455 456 template<class _U1, class _U2, _EnableB< 457 _CheckArgs::template __enable_explicit<_U1, _U2>() 458 > = false> 459 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 460 explicit pair(pair<_U1, _U2>&&__p) 461 : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {} 462 463 template<class _U1, class _U2, _EnableB< 464 _CheckArgs::template __enable_implicit<_U1, _U2>() 465 > = false> 466 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 467 pair(pair<_U1, _U2>&& __p) 468 : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {} 469 470 template<class _Tuple, _EnableB< 471 _CheckTLC<_Tuple>::template __enable_explicit<_Tuple>() 472 > = false> 473 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 474 explicit pair(_Tuple&& __p) 475 : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))), 476 second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {} 477 478 template<class _Tuple, _EnableB< 479 _CheckTLC<_Tuple>::template __enable_implicit<_Tuple>() 480 > = false> 481 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 482 pair(_Tuple&& __p) 483 : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))), 484 second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {} 485 486 template <class... _Args1, class... _Args2> 487 _LIBCPP_INLINE_VISIBILITY 488 pair(piecewise_construct_t __pc, 489 tuple<_Args1...> __first_args, tuple<_Args2...> __second_args) 490 : pair(__pc, __first_args, __second_args, 491 typename __make_tuple_indices<sizeof...(_Args1)>::type(), 492 typename __make_tuple_indices<sizeof...(_Args2) >::type()) {} 493 494 _LIBCPP_INLINE_VISIBILITY 495 pair& operator=(typename conditional< 496 is_copy_assignable<first_type>::value && 497 is_copy_assignable<second_type>::value, 498 pair, __nat>::type const& __p) 499 _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value && 500 is_nothrow_copy_assignable<second_type>::value) 501 { 502 first = __p.first; 503 second = __p.second; 504 return *this; 505 } 506 507 _LIBCPP_INLINE_VISIBILITY 508 pair& operator=(typename conditional< 509 is_move_assignable<first_type>::value && 510 is_move_assignable<second_type>::value, 511 pair, __nat>::type&& __p) 512 _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value && 513 is_nothrow_move_assignable<second_type>::value) 514 { 515 first = _VSTD::forward<first_type>(__p.first); 516 second = _VSTD::forward<second_type>(__p.second); 517 return *this; 518 } 519 520 template <class _Tuple, _EnableB< 521 _CheckTLC<_Tuple>::template __enable_assign<_Tuple>() 522 > = false> 523 _LIBCPP_INLINE_VISIBILITY 524 pair& operator=(_Tuple&& __p) { 525 first = _VSTD::get<0>(_VSTD::forward<_Tuple>(__p)); 526 second = _VSTD::get<1>(_VSTD::forward<_Tuple>(__p)); 527 return *this; 528 } 529#endif 530 531 _LIBCPP_INLINE_VISIBILITY 532 void 533 swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value && 534 __is_nothrow_swappable<second_type>::value) 535 { 536 using _VSTD::swap; 537 swap(first, __p.first); 538 swap(second, __p.second); 539 } 540private: 541 542#ifndef _LIBCPP_CXX03_LANG 543 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> 544 _LIBCPP_INLINE_VISIBILITY 545 pair(piecewise_construct_t, 546 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, 547 __tuple_indices<_I1...>, __tuple_indices<_I2...>); 548#endif 549}; 550 551#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 552template<class _T1, class _T2> 553pair(_T1, _T2) -> pair<_T1, _T2>; 554#endif // _LIBCPP_HAS_NO_DEDUCTION_GUIDES 555 556template <class _T1, class _T2> 557inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 558bool 559operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 560{ 561 return __x.first == __y.first && __x.second == __y.second; 562} 563 564template <class _T1, class _T2> 565inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 566bool 567operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 568{ 569 return !(__x == __y); 570} 571 572template <class _T1, class _T2> 573inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 574bool 575operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 576{ 577 return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second); 578} 579 580template <class _T1, class _T2> 581inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 582bool 583operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 584{ 585 return __y < __x; 586} 587 588template <class _T1, class _T2> 589inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 590bool 591operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 592{ 593 return !(__x < __y); 594} 595 596template <class _T1, class _T2> 597inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 598bool 599operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 600{ 601 return !(__y < __x); 602} 603 604template <class _T1, class _T2> 605inline _LIBCPP_INLINE_VISIBILITY 606typename enable_if 607< 608 __is_swappable<_T1>::value && 609 __is_swappable<_T2>::value, 610 void 611>::type 612swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) 613 _NOEXCEPT_((__is_nothrow_swappable<_T1>::value && 614 __is_nothrow_swappable<_T2>::value)) 615{ 616 __x.swap(__y); 617} 618 619template <class _Tp> 620struct __unwrap_reference { typedef _Tp type; }; 621 622template <class _Tp> 623struct __unwrap_reference<reference_wrapper<_Tp> > { typedef _Tp& type; }; 624 625#if _LIBCPP_STD_VER > 17 626template <class _Tp> 627struct unwrap_reference : __unwrap_reference<_Tp> { }; 628 629template <class _Tp> 630struct unwrap_ref_decay : unwrap_reference<typename decay<_Tp>::type> { }; 631#endif // > C++17 632 633template <class _Tp> 634struct __unwrap_ref_decay 635#if _LIBCPP_STD_VER > 17 636 : unwrap_ref_decay<_Tp> 637#else 638 : __unwrap_reference<typename decay<_Tp>::type> 639#endif 640{ }; 641 642#ifndef _LIBCPP_CXX03_LANG 643 644template <class _T1, class _T2> 645inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 646pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type> 647make_pair(_T1&& __t1, _T2&& __t2) 648{ 649 return pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type> 650 (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2)); 651} 652 653#else // _LIBCPP_CXX03_LANG 654 655template <class _T1, class _T2> 656inline _LIBCPP_INLINE_VISIBILITY 657pair<_T1,_T2> 658make_pair(_T1 __x, _T2 __y) 659{ 660 return pair<_T1, _T2>(__x, __y); 661} 662 663#endif // _LIBCPP_CXX03_LANG 664 665template <class _T1, class _T2> 666 class _LIBCPP_TEMPLATE_VIS tuple_size<pair<_T1, _T2> > 667 : public integral_constant<size_t, 2> {}; 668 669template <size_t _Ip, class _T1, class _T2> 670class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> > 671{ 672 static_assert(_Ip < 2, "Index out of bounds in std::tuple_element<std::pair<T1, T2>>"); 673}; 674 675template <class _T1, class _T2> 676class _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> > 677{ 678public: 679 typedef _T1 type; 680}; 681 682template <class _T1, class _T2> 683class _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> > 684{ 685public: 686 typedef _T2 type; 687}; 688 689template <size_t _Ip> struct __get_pair; 690 691template <> 692struct __get_pair<0> 693{ 694 template <class _T1, class _T2> 695 static 696 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 697 _T1& 698 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} 699 700 template <class _T1, class _T2> 701 static 702 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 703 const _T1& 704 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} 705 706#ifndef _LIBCPP_CXX03_LANG 707 template <class _T1, class _T2> 708 static 709 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 710 _T1&& 711 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);} 712 713 template <class _T1, class _T2> 714 static 715 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 716 const _T1&& 717 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);} 718#endif // _LIBCPP_CXX03_LANG 719}; 720 721template <> 722struct __get_pair<1> 723{ 724 template <class _T1, class _T2> 725 static 726 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 727 _T2& 728 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} 729 730 template <class _T1, class _T2> 731 static 732 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 733 const _T2& 734 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} 735 736#ifndef _LIBCPP_CXX03_LANG 737 template <class _T1, class _T2> 738 static 739 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 740 _T2&& 741 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);} 742 743 template <class _T1, class _T2> 744 static 745 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 746 const _T2&& 747 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);} 748#endif // _LIBCPP_CXX03_LANG 749}; 750 751template <size_t _Ip, class _T1, class _T2> 752inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 753typename tuple_element<_Ip, pair<_T1, _T2> >::type& 754get(pair<_T1, _T2>& __p) _NOEXCEPT 755{ 756 return __get_pair<_Ip>::get(__p); 757} 758 759template <size_t _Ip, class _T1, class _T2> 760inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 761const typename tuple_element<_Ip, pair<_T1, _T2> >::type& 762get(const pair<_T1, _T2>& __p) _NOEXCEPT 763{ 764 return __get_pair<_Ip>::get(__p); 765} 766 767#ifndef _LIBCPP_CXX03_LANG 768template <size_t _Ip, class _T1, class _T2> 769inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 770typename tuple_element<_Ip, pair<_T1, _T2> >::type&& 771get(pair<_T1, _T2>&& __p) _NOEXCEPT 772{ 773 return __get_pair<_Ip>::get(_VSTD::move(__p)); 774} 775 776template <size_t _Ip, class _T1, class _T2> 777inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 778const typename tuple_element<_Ip, pair<_T1, _T2> >::type&& 779get(const pair<_T1, _T2>&& __p) _NOEXCEPT 780{ 781 return __get_pair<_Ip>::get(_VSTD::move(__p)); 782} 783#endif // _LIBCPP_CXX03_LANG 784 785#if _LIBCPP_STD_VER > 11 786template <class _T1, class _T2> 787inline _LIBCPP_INLINE_VISIBILITY 788constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT 789{ 790 return __get_pair<0>::get(__p); 791} 792 793template <class _T1, class _T2> 794inline _LIBCPP_INLINE_VISIBILITY 795constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT 796{ 797 return __get_pair<0>::get(__p); 798} 799 800template <class _T1, class _T2> 801inline _LIBCPP_INLINE_VISIBILITY 802constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT 803{ 804 return __get_pair<0>::get(_VSTD::move(__p)); 805} 806 807template <class _T1, class _T2> 808inline _LIBCPP_INLINE_VISIBILITY 809constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT 810{ 811 return __get_pair<0>::get(_VSTD::move(__p)); 812} 813 814template <class _T1, class _T2> 815inline _LIBCPP_INLINE_VISIBILITY 816constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT 817{ 818 return __get_pair<1>::get(__p); 819} 820 821template <class _T1, class _T2> 822inline _LIBCPP_INLINE_VISIBILITY 823constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT 824{ 825 return __get_pair<1>::get(__p); 826} 827 828template <class _T1, class _T2> 829inline _LIBCPP_INLINE_VISIBILITY 830constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT 831{ 832 return __get_pair<1>::get(_VSTD::move(__p)); 833} 834 835template <class _T1, class _T2> 836inline _LIBCPP_INLINE_VISIBILITY 837constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT 838{ 839 return __get_pair<1>::get(_VSTD::move(__p)); 840} 841 842#endif 843 844#if _LIBCPP_STD_VER > 11 845 846template<class _Tp, _Tp... _Ip> 847struct _LIBCPP_TEMPLATE_VIS integer_sequence 848{ 849 typedef _Tp value_type; 850 static_assert( is_integral<_Tp>::value, 851 "std::integer_sequence can only be instantiated with an integral type" ); 852 static 853 _LIBCPP_INLINE_VISIBILITY 854 constexpr 855 size_t 856 size() noexcept { return sizeof...(_Ip); } 857}; 858 859template<size_t... _Ip> 860 using index_sequence = integer_sequence<size_t, _Ip...>; 861 862#if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE) 863 864template <class _Tp, _Tp _Ep> 865using __make_integer_sequence = __make_integer_seq<integer_sequence, _Tp, _Ep>; 866 867#else 868 869template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked = 870 typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>; 871 872template <class _Tp, _Tp _Ep> 873struct __make_integer_sequence_checked 874{ 875 static_assert(is_integral<_Tp>::value, 876 "std::make_integer_sequence can only be instantiated with an integral type" ); 877 static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length"); 878 // Workaround GCC bug by preventing bad installations when 0 <= _Ep 879 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929 880 typedef __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type; 881}; 882 883template <class _Tp, _Tp _Ep> 884using __make_integer_sequence = typename __make_integer_sequence_checked<_Tp, _Ep>::type; 885 886#endif 887 888template<class _Tp, _Tp _Np> 889 using make_integer_sequence = __make_integer_sequence<_Tp, _Np>; 890 891template<size_t _Np> 892 using make_index_sequence = make_integer_sequence<size_t, _Np>; 893 894template<class... _Tp> 895 using index_sequence_for = make_index_sequence<sizeof...(_Tp)>; 896 897#endif // _LIBCPP_STD_VER > 11 898 899#if _LIBCPP_STD_VER > 11 900template<class _T1, class _T2 = _T1> 901inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 902_T1 exchange(_T1& __obj, _T2 && __new_value) 903{ 904 _T1 __old_value = _VSTD::move(__obj); 905 __obj = _VSTD::forward<_T2>(__new_value); 906 return __old_value; 907} 908#endif // _LIBCPP_STD_VER > 11 909 910#if _LIBCPP_STD_VER > 14 911 912struct _LIBCPP_TYPE_VIS in_place_t { 913 explicit in_place_t() = default; 914}; 915_LIBCPP_INLINE_VAR constexpr in_place_t in_place{}; 916 917template <class _Tp> 918struct _LIBCPP_TEMPLATE_VIS in_place_type_t { 919 explicit in_place_type_t() = default; 920}; 921template <class _Tp> 922_LIBCPP_INLINE_VAR constexpr in_place_type_t<_Tp> in_place_type{}; 923 924template <size_t _Idx> 925struct _LIBCPP_TYPE_VIS in_place_index_t { 926 explicit in_place_index_t() = default; 927}; 928template <size_t _Idx> 929_LIBCPP_INLINE_VAR constexpr in_place_index_t<_Idx> in_place_index{}; 930 931template <class _Tp> struct __is_inplace_type_imp : false_type {}; 932template <class _Tp> struct __is_inplace_type_imp<in_place_type_t<_Tp>> : true_type {}; 933 934template <class _Tp> 935using __is_inplace_type = __is_inplace_type_imp<__uncvref_t<_Tp>>; 936 937template <class _Tp> struct __is_inplace_index_imp : false_type {}; 938template <size_t _Idx> struct __is_inplace_index_imp<in_place_index_t<_Idx>> : true_type {}; 939 940template <class _Tp> 941using __is_inplace_index = __is_inplace_index_imp<__uncvref_t<_Tp>>; 942 943#endif // _LIBCPP_STD_VER > 14 944 945template <class _Arg, class _Result> 946struct _LIBCPP_TEMPLATE_VIS unary_function 947{ 948 typedef _Arg argument_type; 949 typedef _Result result_type; 950}; 951 952template <class _Size> 953inline _LIBCPP_INLINE_VISIBILITY 954_Size 955__loadword(const void* __p) 956{ 957 _Size __r; 958 std::memcpy(&__r, __p, sizeof(__r)); 959 return __r; 960} 961 962// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t 963// is 64 bits. This is because cityhash64 uses 64bit x 64bit 964// multiplication, which can be very slow on 32-bit systems. 965template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__> 966struct __murmur2_or_cityhash; 967 968template <class _Size> 969struct __murmur2_or_cityhash<_Size, 32> 970{ 971 inline _Size operator()(const void* __key, _Size __len) 972 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK; 973}; 974 975// murmur2 976template <class _Size> 977_Size 978__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len) 979{ 980 const _Size __m = 0x5bd1e995; 981 const _Size __r = 24; 982 _Size __h = __len; 983 const unsigned char* __data = static_cast<const unsigned char*>(__key); 984 for (; __len >= 4; __data += 4, __len -= 4) 985 { 986 _Size __k = __loadword<_Size>(__data); 987 __k *= __m; 988 __k ^= __k >> __r; 989 __k *= __m; 990 __h *= __m; 991 __h ^= __k; 992 } 993 switch (__len) 994 { 995 case 3: 996 __h ^= __data[2] << 16; 997 _LIBCPP_FALLTHROUGH(); 998 case 2: 999 __h ^= __data[1] << 8; 1000 _LIBCPP_FALLTHROUGH(); 1001 case 1: 1002 __h ^= __data[0]; 1003 __h *= __m; 1004 } 1005 __h ^= __h >> 13; 1006 __h *= __m; 1007 __h ^= __h >> 15; 1008 return __h; 1009} 1010 1011template <class _Size> 1012struct __murmur2_or_cityhash<_Size, 64> 1013{ 1014 inline _Size operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK; 1015 1016 private: 1017 // Some primes between 2^63 and 2^64. 1018 static const _Size __k0 = 0xc3a5c85c97cb3127ULL; 1019 static const _Size __k1 = 0xb492b66fbe98f273ULL; 1020 static const _Size __k2 = 0x9ae16a3b2f90404fULL; 1021 static const _Size __k3 = 0xc949d7c7509e6557ULL; 1022 1023 static _Size __rotate(_Size __val, int __shift) { 1024 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift))); 1025 } 1026 1027 static _Size __rotate_by_at_least_1(_Size __val, int __shift) { 1028 return (__val >> __shift) | (__val << (64 - __shift)); 1029 } 1030 1031 static _Size __shift_mix(_Size __val) { 1032 return __val ^ (__val >> 47); 1033 } 1034 1035 static _Size __hash_len_16(_Size __u, _Size __v) 1036 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 1037 { 1038 const _Size __mul = 0x9ddfea08eb382d69ULL; 1039 _Size __a = (__u ^ __v) * __mul; 1040 __a ^= (__a >> 47); 1041 _Size __b = (__v ^ __a) * __mul; 1042 __b ^= (__b >> 47); 1043 __b *= __mul; 1044 return __b; 1045 } 1046 1047 static _Size __hash_len_0_to_16(const char* __s, _Size __len) 1048 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 1049 { 1050 if (__len > 8) { 1051 const _Size __a = __loadword<_Size>(__s); 1052 const _Size __b = __loadword<_Size>(__s + __len - 8); 1053 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b; 1054 } 1055 if (__len >= 4) { 1056 const uint32_t __a = __loadword<uint32_t>(__s); 1057 const uint32_t __b = __loadword<uint32_t>(__s + __len - 4); 1058 return __hash_len_16(__len + (__a << 3), __b); 1059 } 1060 if (__len > 0) { 1061 const unsigned char __a = __s[0]; 1062 const unsigned char __b = __s[__len >> 1]; 1063 const unsigned char __c = __s[__len - 1]; 1064 const uint32_t __y = static_cast<uint32_t>(__a) + 1065 (static_cast<uint32_t>(__b) << 8); 1066 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2); 1067 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2; 1068 } 1069 return __k2; 1070 } 1071 1072 static _Size __hash_len_17_to_32(const char *__s, _Size __len) 1073 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 1074 { 1075 const _Size __a = __loadword<_Size>(__s) * __k1; 1076 const _Size __b = __loadword<_Size>(__s + 8); 1077 const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2; 1078 const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0; 1079 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d, 1080 __a + __rotate(__b ^ __k3, 20) - __c + __len); 1081 } 1082 1083 // Return a 16-byte hash for 48 bytes. Quick and dirty. 1084 // Callers do best to use "random-looking" values for a and b. 1085 static pair<_Size, _Size> __weak_hash_len_32_with_seeds( 1086 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) 1087 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 1088 { 1089 __a += __w; 1090 __b = __rotate(__b + __a + __z, 21); 1091 const _Size __c = __a; 1092 __a += __x; 1093 __a += __y; 1094 __b += __rotate(__a, 44); 1095 return pair<_Size, _Size>(__a + __z, __b + __c); 1096 } 1097 1098 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty. 1099 static pair<_Size, _Size> __weak_hash_len_32_with_seeds( 1100 const char* __s, _Size __a, _Size __b) 1101 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 1102 { 1103 return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s), 1104 __loadword<_Size>(__s + 8), 1105 __loadword<_Size>(__s + 16), 1106 __loadword<_Size>(__s + 24), 1107 __a, 1108 __b); 1109 } 1110 1111 // Return an 8-byte hash for 33 to 64 bytes. 1112 static _Size __hash_len_33_to_64(const char *__s, size_t __len) 1113 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 1114 { 1115 _Size __z = __loadword<_Size>(__s + 24); 1116 _Size __a = __loadword<_Size>(__s) + 1117 (__len + __loadword<_Size>(__s + __len - 16)) * __k0; 1118 _Size __b = __rotate(__a + __z, 52); 1119 _Size __c = __rotate(__a, 37); 1120 __a += __loadword<_Size>(__s + 8); 1121 __c += __rotate(__a, 7); 1122 __a += __loadword<_Size>(__s + 16); 1123 _Size __vf = __a + __z; 1124 _Size __vs = __b + __rotate(__a, 31) + __c; 1125 __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32); 1126 __z += __loadword<_Size>(__s + __len - 8); 1127 __b = __rotate(__a + __z, 52); 1128 __c = __rotate(__a, 37); 1129 __a += __loadword<_Size>(__s + __len - 24); 1130 __c += __rotate(__a, 7); 1131 __a += __loadword<_Size>(__s + __len - 16); 1132 _Size __wf = __a + __z; 1133 _Size __ws = __b + __rotate(__a, 31) + __c; 1134 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0); 1135 return __shift_mix(__r * __k0 + __vs) * __k2; 1136 } 1137}; 1138 1139// cityhash64 1140template <class _Size> 1141_Size 1142__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) 1143{ 1144 const char* __s = static_cast<const char*>(__key); 1145 if (__len <= 32) { 1146 if (__len <= 16) { 1147 return __hash_len_0_to_16(__s, __len); 1148 } else { 1149 return __hash_len_17_to_32(__s, __len); 1150 } 1151 } else if (__len <= 64) { 1152 return __hash_len_33_to_64(__s, __len); 1153 } 1154 1155 // For strings over 64 bytes we hash the end first, and then as we 1156 // loop we keep 56 bytes of state: v, w, x, y, and z. 1157 _Size __x = __loadword<_Size>(__s + __len - 40); 1158 _Size __y = __loadword<_Size>(__s + __len - 16) + 1159 __loadword<_Size>(__s + __len - 56); 1160 _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len, 1161 __loadword<_Size>(__s + __len - 24)); 1162 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z); 1163 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x); 1164 __x = __x * __k1 + __loadword<_Size>(__s); 1165 1166 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks. 1167 __len = (__len - 1) & ~static_cast<_Size>(63); 1168 do { 1169 __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1; 1170 __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1; 1171 __x ^= __w.second; 1172 __y += __v.first + __loadword<_Size>(__s + 40); 1173 __z = __rotate(__z + __w.first, 33) * __k1; 1174 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first); 1175 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second, 1176 __y + __loadword<_Size>(__s + 16)); 1177 std::swap(__z, __x); 1178 __s += 64; 1179 __len -= 64; 1180 } while (__len != 0); 1181 return __hash_len_16( 1182 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z, 1183 __hash_len_16(__v.second, __w.second) + __x); 1184} 1185 1186template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)> 1187struct __scalar_hash; 1188 1189template <class _Tp> 1190struct __scalar_hash<_Tp, 0> 1191 : public unary_function<_Tp, size_t> 1192{ 1193 _LIBCPP_INLINE_VISIBILITY 1194 size_t operator()(_Tp __v) const _NOEXCEPT 1195 { 1196 union 1197 { 1198 _Tp __t; 1199 size_t __a; 1200 } __u; 1201 __u.__a = 0; 1202 __u.__t = __v; 1203 return __u.__a; 1204 } 1205}; 1206 1207template <class _Tp> 1208struct __scalar_hash<_Tp, 1> 1209 : public unary_function<_Tp, size_t> 1210{ 1211 _LIBCPP_INLINE_VISIBILITY 1212 size_t operator()(_Tp __v) const _NOEXCEPT 1213 { 1214 union 1215 { 1216 _Tp __t; 1217 size_t __a; 1218 } __u; 1219 __u.__t = __v; 1220 return __u.__a; 1221 } 1222}; 1223 1224template <class _Tp> 1225struct __scalar_hash<_Tp, 2> 1226 : public unary_function<_Tp, size_t> 1227{ 1228 _LIBCPP_INLINE_VISIBILITY 1229 size_t operator()(_Tp __v) const _NOEXCEPT 1230 { 1231 union 1232 { 1233 _Tp __t; 1234 struct 1235 { 1236 size_t __a; 1237 size_t __b; 1238 } __s; 1239 } __u; 1240 __u.__t = __v; 1241 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); 1242 } 1243}; 1244 1245template <class _Tp> 1246struct __scalar_hash<_Tp, 3> 1247 : public unary_function<_Tp, size_t> 1248{ 1249 _LIBCPP_INLINE_VISIBILITY 1250 size_t operator()(_Tp __v) const _NOEXCEPT 1251 { 1252 union 1253 { 1254 _Tp __t; 1255 struct 1256 { 1257 size_t __a; 1258 size_t __b; 1259 size_t __c; 1260 } __s; 1261 } __u; 1262 __u.__t = __v; 1263 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); 1264 } 1265}; 1266 1267template <class _Tp> 1268struct __scalar_hash<_Tp, 4> 1269 : public unary_function<_Tp, size_t> 1270{ 1271 _LIBCPP_INLINE_VISIBILITY 1272 size_t operator()(_Tp __v) const _NOEXCEPT 1273 { 1274 union 1275 { 1276 _Tp __t; 1277 struct 1278 { 1279 size_t __a; 1280 size_t __b; 1281 size_t __c; 1282 size_t __d; 1283 } __s; 1284 } __u; 1285 __u.__t = __v; 1286 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); 1287 } 1288}; 1289 1290struct _PairT { 1291 size_t first; 1292 size_t second; 1293}; 1294 1295_LIBCPP_INLINE_VISIBILITY 1296inline size_t __hash_combine(size_t __lhs, size_t __rhs) _NOEXCEPT { 1297 typedef __scalar_hash<_PairT> _HashT; 1298 const _PairT __p = {__lhs, __rhs}; 1299 return _HashT()(__p); 1300} 1301 1302template<class _Tp> 1303struct _LIBCPP_TEMPLATE_VIS hash<_Tp*> 1304 : public unary_function<_Tp*, size_t> 1305{ 1306 _LIBCPP_INLINE_VISIBILITY 1307 size_t operator()(_Tp* __v) const _NOEXCEPT 1308 { 1309 union 1310 { 1311 _Tp* __t; 1312 size_t __a; 1313 } __u; 1314 __u.__t = __v; 1315 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); 1316 } 1317}; 1318 1319 1320template <> 1321struct _LIBCPP_TEMPLATE_VIS hash<bool> 1322 : public unary_function<bool, size_t> 1323{ 1324 _LIBCPP_INLINE_VISIBILITY 1325 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1326}; 1327 1328template <> 1329struct _LIBCPP_TEMPLATE_VIS hash<char> 1330 : public unary_function<char, size_t> 1331{ 1332 _LIBCPP_INLINE_VISIBILITY 1333 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1334}; 1335 1336template <> 1337struct _LIBCPP_TEMPLATE_VIS hash<signed char> 1338 : public unary_function<signed char, size_t> 1339{ 1340 _LIBCPP_INLINE_VISIBILITY 1341 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1342}; 1343 1344template <> 1345struct _LIBCPP_TEMPLATE_VIS hash<unsigned char> 1346 : public unary_function<unsigned char, size_t> 1347{ 1348 _LIBCPP_INLINE_VISIBILITY 1349 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1350}; 1351 1352#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 1353 1354template <> 1355struct _LIBCPP_TEMPLATE_VIS hash<char16_t> 1356 : public unary_function<char16_t, size_t> 1357{ 1358 _LIBCPP_INLINE_VISIBILITY 1359 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1360}; 1361 1362template <> 1363struct _LIBCPP_TEMPLATE_VIS hash<char32_t> 1364 : public unary_function<char32_t, size_t> 1365{ 1366 _LIBCPP_INLINE_VISIBILITY 1367 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1368}; 1369 1370#endif // _LIBCPP_HAS_NO_UNICODE_CHARS 1371 1372template <> 1373struct _LIBCPP_TEMPLATE_VIS hash<wchar_t> 1374 : public unary_function<wchar_t, size_t> 1375{ 1376 _LIBCPP_INLINE_VISIBILITY 1377 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1378}; 1379 1380template <> 1381struct _LIBCPP_TEMPLATE_VIS hash<short> 1382 : public unary_function<short, size_t> 1383{ 1384 _LIBCPP_INLINE_VISIBILITY 1385 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1386}; 1387 1388template <> 1389struct _LIBCPP_TEMPLATE_VIS hash<unsigned short> 1390 : public unary_function<unsigned short, size_t> 1391{ 1392 _LIBCPP_INLINE_VISIBILITY 1393 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1394}; 1395 1396template <> 1397struct _LIBCPP_TEMPLATE_VIS hash<int> 1398 : public unary_function<int, size_t> 1399{ 1400 _LIBCPP_INLINE_VISIBILITY 1401 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1402}; 1403 1404template <> 1405struct _LIBCPP_TEMPLATE_VIS hash<unsigned int> 1406 : public unary_function<unsigned int, size_t> 1407{ 1408 _LIBCPP_INLINE_VISIBILITY 1409 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1410}; 1411 1412template <> 1413struct _LIBCPP_TEMPLATE_VIS hash<long> 1414 : public unary_function<long, size_t> 1415{ 1416 _LIBCPP_INLINE_VISIBILITY 1417 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1418}; 1419 1420template <> 1421struct _LIBCPP_TEMPLATE_VIS hash<unsigned long> 1422 : public unary_function<unsigned long, size_t> 1423{ 1424 _LIBCPP_INLINE_VISIBILITY 1425 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1426}; 1427 1428template <> 1429struct _LIBCPP_TEMPLATE_VIS hash<long long> 1430 : public __scalar_hash<long long> 1431{ 1432}; 1433 1434template <> 1435struct _LIBCPP_TEMPLATE_VIS hash<unsigned long long> 1436 : public __scalar_hash<unsigned long long> 1437{ 1438}; 1439 1440#ifndef _LIBCPP_HAS_NO_INT128 1441 1442template <> 1443struct _LIBCPP_TEMPLATE_VIS hash<__int128_t> 1444 : public __scalar_hash<__int128_t> 1445{ 1446}; 1447 1448template <> 1449struct _LIBCPP_TEMPLATE_VIS hash<__uint128_t> 1450 : public __scalar_hash<__uint128_t> 1451{ 1452}; 1453 1454#endif 1455 1456template <> 1457struct _LIBCPP_TEMPLATE_VIS hash<float> 1458 : public __scalar_hash<float> 1459{ 1460 _LIBCPP_INLINE_VISIBILITY 1461 size_t operator()(float __v) const _NOEXCEPT 1462 { 1463 // -0.0 and 0.0 should return same hash 1464 if (__v == 0.0) 1465 return 0; 1466 return __scalar_hash<float>::operator()(__v); 1467 } 1468}; 1469 1470template <> 1471struct _LIBCPP_TEMPLATE_VIS hash<double> 1472 : public __scalar_hash<double> 1473{ 1474 _LIBCPP_INLINE_VISIBILITY 1475 size_t operator()(double __v) const _NOEXCEPT 1476 { 1477 // -0.0 and 0.0 should return same hash 1478 if (__v == 0.0) 1479 return 0; 1480 return __scalar_hash<double>::operator()(__v); 1481 } 1482}; 1483 1484template <> 1485struct _LIBCPP_TEMPLATE_VIS hash<long double> 1486 : public __scalar_hash<long double> 1487{ 1488 _LIBCPP_INLINE_VISIBILITY 1489 size_t operator()(long double __v) const _NOEXCEPT 1490 { 1491 // -0.0 and 0.0 should return same hash 1492 if (__v == 0.0) 1493 return 0; 1494#if defined(__i386__) 1495 // Zero out padding bits 1496 union 1497 { 1498 long double __t; 1499 struct 1500 { 1501 size_t __a; 1502 size_t __b; 1503 size_t __c; 1504 size_t __d; 1505 } __s; 1506 } __u; 1507 __u.__s.__a = 0; 1508 __u.__s.__b = 0; 1509 __u.__s.__c = 0; 1510 __u.__s.__d = 0; 1511 __u.__t = __v; 1512 return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d; 1513#elif defined(__x86_64__) 1514 // Zero out padding bits 1515 union 1516 { 1517 long double __t; 1518 struct 1519 { 1520 size_t __a; 1521 size_t __b; 1522 } __s; 1523 } __u; 1524 __u.__s.__a = 0; 1525 __u.__s.__b = 0; 1526 __u.__t = __v; 1527 return __u.__s.__a ^ __u.__s.__b; 1528#else 1529 return __scalar_hash<long double>::operator()(__v); 1530#endif 1531 } 1532}; 1533 1534#if _LIBCPP_STD_VER > 11 1535 1536template <class _Tp, bool = is_enum<_Tp>::value> 1537struct _LIBCPP_TEMPLATE_VIS __enum_hash 1538 : public unary_function<_Tp, size_t> 1539{ 1540 _LIBCPP_INLINE_VISIBILITY 1541 size_t operator()(_Tp __v) const _NOEXCEPT 1542 { 1543 typedef typename underlying_type<_Tp>::type type; 1544 return hash<type>{}(static_cast<type>(__v)); 1545 } 1546}; 1547template <class _Tp> 1548struct _LIBCPP_TEMPLATE_VIS __enum_hash<_Tp, false> { 1549 __enum_hash() = delete; 1550 __enum_hash(__enum_hash const&) = delete; 1551 __enum_hash& operator=(__enum_hash const&) = delete; 1552}; 1553 1554template <class _Tp> 1555struct _LIBCPP_TEMPLATE_VIS hash : public __enum_hash<_Tp> 1556{ 1557}; 1558#endif 1559 1560#if _LIBCPP_STD_VER > 14 1561 1562template <> 1563struct _LIBCPP_TEMPLATE_VIS hash<nullptr_t> 1564 : public unary_function<nullptr_t, size_t> 1565{ 1566 _LIBCPP_INLINE_VISIBILITY 1567 size_t operator()(nullptr_t) const _NOEXCEPT { 1568 return 662607004ull; 1569 } 1570}; 1571#endif 1572 1573#ifndef _LIBCPP_CXX03_LANG 1574template <class _Key, class _Hash> 1575using __check_hash_requirements = integral_constant<bool, 1576 is_copy_constructible<_Hash>::value && 1577 is_move_constructible<_Hash>::value && 1578 __invokable_r<size_t, _Hash, _Key const&>::value 1579>; 1580 1581template <class _Key, class _Hash = std::hash<_Key> > 1582using __has_enabled_hash = integral_constant<bool, 1583 __check_hash_requirements<_Key, _Hash>::value && 1584 is_default_constructible<_Hash>::value 1585>; 1586 1587#if _LIBCPP_STD_VER > 14 1588template <class _Type, class> 1589using __enable_hash_helper_imp = _Type; 1590 1591template <class _Type, class ..._Keys> 1592using __enable_hash_helper = __enable_hash_helper_imp<_Type, 1593 typename enable_if<__all<__has_enabled_hash<_Keys>::value...>::value>::type 1594>; 1595#else 1596template <class _Type, class ...> 1597using __enable_hash_helper = _Type; 1598#endif 1599 1600#endif // !_LIBCPP_CXX03_LANG 1601 1602_LIBCPP_END_NAMESPACE_STD 1603 1604#endif // _LIBCPP_UTILITY 1605