2 //===-------------------------- utility -----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_UTILITY
12 #define _LIBCPP_UTILITY
17 #include <initializer_list>
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&);
36 swap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value &&
37 is_nothrow_move_assignable<T>::value);
39 template <class T, size_t N>
41 swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)));
43 template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; // constexpr in C++14
44 template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++14
46 template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14
51 !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
55 move_if_noexcept(T& x) noexcept; // constexpr in C++14
57 template <class T> constexpr add_const_t<T>& as_const(T& t) noexcept; // C++17
58 template <class T> void as_const(const T&&) = delete; // C++17
60 template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
62 template <class T1, class T2>
65 typedef T1 first_type;
66 typedef T2 second_type;
71 pair(const pair&) = default;
72 pair(pair&&) = default;
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);
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);
87 void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> &&
88 is_nothrow_swappable_v<T2>);
91 template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
92 template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
93 template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
94 template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
95 template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
96 template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
98 template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14
99 template <class T1, class T2>
101 swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));
103 struct piecewise_construct_t { };
104 inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
106 template <class T> class tuple_size;
107 template <size_t I, class T> class tuple_element;
109 template <class T1, class T2> struct tuple_size<pair<T1, T2> >;
110 template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >;
111 template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >;
113 template<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
117 template<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
121 template<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
125 template<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
129 template<class T1, class T2>
130 constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
132 template<class T1, class T2>
133 constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14
135 template<class T1, class T2>
136 constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14
138 template<class T1, class T2>
139 constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14
141 template<class T1, class T2>
142 constexpr T1& get(pair<T2, T1>&) noexcept; // C++14
144 template<class T1, class T2>
145 constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14
147 template<class T1, class T2>
148 constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14
150 template<class T1, class T2>
151 constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14
155 template<class T, T... I>
156 struct integer_sequence
158 typedef T value_type;
160 static constexpr size_t size() noexcept;
163 template<size_t... I>
164 using index_sequence = integer_sequence<size_t, I...>;
166 template<class T, T N>
167 using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
169 using make_index_sequence = make_integer_sequence<size_t, N>;
172 using index_sequence_for = make_index_sequence<sizeof...(T)>;
174 template<class T, class U=T>
175 T exchange(T& obj, U&& new_value);
177 // 20.2.7, in-place construction // C++17
179 explicit in_place_t() = default;
181 inline constexpr in_place_t in_place{};
183 struct in_place_type_t {
184 explicit in_place_type_t() = default;
187 inline constexpr in_place_type_t<T> in_place_type{};
189 struct in_place_index_t {
190 explicit in_place_index_t() = default;
193 inline constexpr in_place_index_t<I> in_place_index{};
201 #include <type_traits>
202 #include <initializer_list>
208 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
209 #pragma GCC system_header
212 _LIBCPP_BEGIN_NAMESPACE_STD
218 inline _LIBCPP_INLINE_VISIBILITY
220 operator!=(const _Tp& __x, const _Tp& __y)
222 return !(__x == __y);
226 inline _LIBCPP_INLINE_VISIBILITY
228 operator> (const _Tp& __x, const _Tp& __y)
234 inline _LIBCPP_INLINE_VISIBILITY
236 operator<=(const _Tp& __x, const _Tp& __y)
242 inline _LIBCPP_INLINE_VISIBILITY
244 operator>=(const _Tp& __x, const _Tp& __y)
254 template <class _ForwardIterator1, class _ForwardIterator2>
255 inline _LIBCPP_INLINE_VISIBILITY
257 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
259 for(; __first1 != __last1; ++__first1, (void) ++__first2)
260 swap(*__first1, *__first2);
264 // forward declared in <type_traits>
265 template<class _Tp, size_t _Np>
266 inline _LIBCPP_INLINE_VISIBILITY
268 __is_swappable<_Tp>::value
270 swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
272 _VSTD::swap_ranges(__a, __a + _Np, __b);
276 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
277 #ifndef _LIBCPP_CXX03_LANG
280 !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value,
284 #else // _LIBCPP_CXX03_LANG
287 move_if_noexcept(_Tp& __x) _NOEXCEPT
289 return _VSTD::move(__x);
292 #if _LIBCPP_STD_VER > 14
293 template <class _Tp> constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; }
294 template <class _Tp> void as_const(const _Tp&&) = delete;
297 struct _LIBCPP_TEMPLATE_VIS piecewise_construct_t { };
298 #if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
299 extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
301 /* _LIBCPP_INLINE_VAR */ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
304 #if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
305 struct __non_trivially_copyable_base {
306 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
307 __non_trivially_copyable_base() _NOEXCEPT {}
308 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
309 __non_trivially_copyable_base(__non_trivially_copyable_base const&) _NOEXCEPT {}
313 template <class _T1, class _T2>
314 struct _LIBCPP_TEMPLATE_VIS pair
315 #if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
316 : private __non_trivially_copyable_base
319 typedef _T1 first_type;
320 typedef _T2 second_type;
325 #if !defined(_LIBCPP_CXX03_LANG)
326 pair(pair const&) = default;
327 pair(pair&&) = default;
329 // Use the implicitly declared copy constructor in C++03
332 #ifdef _LIBCPP_CXX03_LANG
333 _LIBCPP_INLINE_VISIBILITY
334 pair() : first(), second() {}
336 _LIBCPP_INLINE_VISIBILITY
337 pair(_T1 const& __t1, _T2 const& __t2) : first(__t1), second(__t2) {}
339 template <class _U1, class _U2>
340 _LIBCPP_INLINE_VISIBILITY
341 pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
343 _LIBCPP_INLINE_VISIBILITY
344 pair& operator=(pair const& __p) {
351 using _EnableB = typename enable_if<_Val, bool>::type;
354 template <class _U1, class _U2>
355 static constexpr bool __enable_default() {
356 return is_default_constructible<_U1>::value
357 && is_default_constructible<_U2>::value;
360 template <class _U1, class _U2>
361 static constexpr bool __enable_explicit() {
362 return is_constructible<first_type, _U1>::value
363 && is_constructible<second_type, _U2>::value
364 && (!is_convertible<_U1, first_type>::value
365 || !is_convertible<_U2, second_type>::value);
368 template <class _U1, class _U2>
369 static constexpr bool __enable_implicit() {
370 return is_constructible<first_type, _U1>::value
371 && is_constructible<second_type, _U2>::value
372 && is_convertible<_U1, first_type>::value
373 && is_convertible<_U2, second_type>::value;
377 template <bool _MaybeEnable>
378 using _CheckArgsDep = typename conditional<
379 _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type;
381 struct _CheckTupleLikeConstructor {
382 template <class _Tuple>
383 static constexpr bool __enable_implicit() {
384 return __tuple_convertible<_Tuple, pair>::value;
387 template <class _Tuple>
388 static constexpr bool __enable_explicit() {
389 return __tuple_constructible<_Tuple, pair>::value
390 && !__tuple_convertible<_Tuple, pair>::value;
393 template <class _Tuple>
394 static constexpr bool __enable_assign() {
395 return __tuple_assignable<_Tuple, pair>::value;
399 template <class _Tuple>
400 using _CheckTLC = typename conditional<
401 __tuple_like_with_size<_Tuple, 2>::value
402 && !is_same<typename decay<_Tuple>::type, pair>::value,
403 _CheckTupleLikeConstructor,
404 __check_tuple_constructor_fail
407 template<bool _Dummy = true, _EnableB<
408 _CheckArgsDep<_Dummy>::template __enable_default<_T1, _T2>()
410 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
411 pair() : first(), second() {}
413 template <bool _Dummy = true, _EnableB<
414 _CheckArgsDep<_Dummy>::template __enable_explicit<_T1 const&, _T2 const&>()
416 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
417 explicit pair(_T1 const& __t1, _T2 const& __t2)
418 : first(__t1), second(__t2) {}
420 template<bool _Dummy = true, _EnableB<
421 _CheckArgsDep<_Dummy>::template __enable_implicit<_T1 const&, _T2 const&>()
423 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
424 pair(_T1 const& __t1, _T2 const& __t2)
425 : first(__t1), second(__t2) {}
427 template<class _U1, class _U2, _EnableB<
428 _CheckArgs::template __enable_explicit<_U1, _U2>()
430 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
431 explicit pair(_U1&& __u1, _U2&& __u2)
432 : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
434 template<class _U1, class _U2, _EnableB<
435 _CheckArgs::template __enable_implicit<_U1, _U2>()
437 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
438 pair(_U1&& __u1, _U2&& __u2)
439 : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
441 template<class _U1, class _U2, _EnableB<
442 _CheckArgs::template __enable_explicit<_U1 const&, _U2 const&>()
444 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
445 explicit pair(pair<_U1, _U2> const& __p)
446 : first(__p.first), second(__p.second) {}
448 template<class _U1, class _U2, _EnableB<
449 _CheckArgs::template __enable_implicit<_U1 const&, _U2 const&>()
451 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
452 pair(pair<_U1, _U2> const& __p)
453 : first(__p.first), second(__p.second) {}
455 template<class _U1, class _U2, _EnableB<
456 _CheckArgs::template __enable_explicit<_U1, _U2>()
458 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
459 explicit pair(pair<_U1, _U2>&&__p)
460 : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
462 template<class _U1, class _U2, _EnableB<
463 _CheckArgs::template __enable_implicit<_U1, _U2>()
465 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
466 pair(pair<_U1, _U2>&& __p)
467 : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
469 template<class _Tuple, _EnableB<
470 _CheckTLC<_Tuple>::template __enable_explicit<_Tuple>()
472 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
473 explicit pair(_Tuple&& __p)
474 : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
475 second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {}
477 template<class _Tuple, _EnableB<
478 _CheckTLC<_Tuple>::template __enable_implicit<_Tuple>()
480 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
482 : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
483 second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {}
485 template <class... _Args1, class... _Args2>
486 _LIBCPP_INLINE_VISIBILITY
487 pair(piecewise_construct_t __pc,
488 tuple<_Args1...> __first_args, tuple<_Args2...> __second_args)
489 : pair(__pc, __first_args, __second_args,
490 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
491 typename __make_tuple_indices<sizeof...(_Args2) >::type()) {}
493 _LIBCPP_INLINE_VISIBILITY
494 pair& operator=(typename conditional<
495 is_copy_assignable<first_type>::value &&
496 is_copy_assignable<second_type>::value,
497 pair, __nat>::type const& __p)
498 _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value &&
499 is_nothrow_copy_assignable<second_type>::value)
506 _LIBCPP_INLINE_VISIBILITY
507 pair& operator=(typename conditional<
508 is_move_assignable<first_type>::value &&
509 is_move_assignable<second_type>::value,
510 pair, __nat>::type&& __p)
511 _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value &&
512 is_nothrow_move_assignable<second_type>::value)
514 first = _VSTD::forward<first_type>(__p.first);
515 second = _VSTD::forward<second_type>(__p.second);
519 template <class _Tuple, _EnableB<
520 _CheckTLC<_Tuple>::template __enable_assign<_Tuple>()
522 _LIBCPP_INLINE_VISIBILITY
523 pair& operator=(_Tuple&& __p) {
524 first = _VSTD::get<0>(_VSTD::forward<_Tuple>(__p));
525 second = _VSTD::get<1>(_VSTD::forward<_Tuple>(__p));
530 _LIBCPP_INLINE_VISIBILITY
532 swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value &&
533 __is_nothrow_swappable<second_type>::value)
536 swap(first, __p.first);
537 swap(second, __p.second);
541 #ifndef _LIBCPP_CXX03_LANG
542 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
543 _LIBCPP_INLINE_VISIBILITY
544 pair(piecewise_construct_t,
545 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
546 __tuple_indices<_I1...>, __tuple_indices<_I2...>);
550 #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
551 template<class _T1, class _T2>
552 pair(_T1, _T2) -> pair<_T1, _T2>;
553 #endif // _LIBCPP_HAS_NO_DEDUCTION_GUIDES
555 template <class _T1, class _T2>
556 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
558 operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
560 return __x.first == __y.first && __x.second == __y.second;
563 template <class _T1, class _T2>
564 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
566 operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
568 return !(__x == __y);
571 template <class _T1, class _T2>
572 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
574 operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
576 return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);
579 template <class _T1, class _T2>
580 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
582 operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
587 template <class _T1, class _T2>
588 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
590 operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
595 template <class _T1, class _T2>
596 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
598 operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
603 template <class _T1, class _T2>
604 inline _LIBCPP_INLINE_VISIBILITY
607 __is_swappable<_T1>::value &&
608 __is_swappable<_T2>::value,
611 swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
612 _NOEXCEPT_((__is_nothrow_swappable<_T1>::value &&
613 __is_nothrow_swappable<_T2>::value))
618 #ifndef _LIBCPP_CXX03_LANG
621 struct __make_pair_return_impl
627 struct __make_pair_return_impl<reference_wrapper<_Tp>>
633 struct __make_pair_return
635 typedef typename __make_pair_return_impl<typename decay<_Tp>::type>::type type;
638 template <class _T1, class _T2>
639 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
640 pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
641 make_pair(_T1&& __t1, _T2&& __t2)
643 return pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
644 (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2));
647 #else // _LIBCPP_CXX03_LANG
649 template <class _T1, class _T2>
650 inline _LIBCPP_INLINE_VISIBILITY
652 make_pair(_T1 __x, _T2 __y)
654 return pair<_T1, _T2>(__x, __y);
657 #endif // _LIBCPP_CXX03_LANG
659 template <class _T1, class _T2>
660 class _LIBCPP_TEMPLATE_VIS tuple_size<pair<_T1, _T2> >
661 : public integral_constant<size_t, 2> {};
663 template <size_t _Ip, class _T1, class _T2>
664 class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> >
666 static_assert(_Ip < 2, "Index out of bounds in std::tuple_element<std::pair<T1, T2>>");
669 template <class _T1, class _T2>
670 class _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> >
676 template <class _T1, class _T2>
677 class _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> >
683 template <size_t _Ip> struct __get_pair;
688 template <class _T1, class _T2>
690 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
692 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
694 template <class _T1, class _T2>
696 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
698 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
700 #ifndef _LIBCPP_CXX03_LANG
701 template <class _T1, class _T2>
703 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
705 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);}
707 template <class _T1, class _T2>
709 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
711 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);}
712 #endif // _LIBCPP_CXX03_LANG
718 template <class _T1, class _T2>
720 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
722 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
724 template <class _T1, class _T2>
726 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
728 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
730 #ifndef _LIBCPP_CXX03_LANG
731 template <class _T1, class _T2>
733 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
735 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);}
737 template <class _T1, class _T2>
739 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
741 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);}
742 #endif // _LIBCPP_CXX03_LANG
745 template <size_t _Ip, class _T1, class _T2>
746 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
747 typename tuple_element<_Ip, pair<_T1, _T2> >::type&
748 get(pair<_T1, _T2>& __p) _NOEXCEPT
750 return __get_pair<_Ip>::get(__p);
753 template <size_t _Ip, class _T1, class _T2>
754 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
755 const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
756 get(const pair<_T1, _T2>& __p) _NOEXCEPT
758 return __get_pair<_Ip>::get(__p);
761 #ifndef _LIBCPP_CXX03_LANG
762 template <size_t _Ip, class _T1, class _T2>
763 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
764 typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
765 get(pair<_T1, _T2>&& __p) _NOEXCEPT
767 return __get_pair<_Ip>::get(_VSTD::move(__p));
770 template <size_t _Ip, class _T1, class _T2>
771 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
772 const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
773 get(const pair<_T1, _T2>&& __p) _NOEXCEPT
775 return __get_pair<_Ip>::get(_VSTD::move(__p));
777 #endif // _LIBCPP_CXX03_LANG
779 #if _LIBCPP_STD_VER > 11
780 template <class _T1, class _T2>
781 inline _LIBCPP_INLINE_VISIBILITY
782 constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT
784 return __get_pair<0>::get(__p);
787 template <class _T1, class _T2>
788 inline _LIBCPP_INLINE_VISIBILITY
789 constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT
791 return __get_pair<0>::get(__p);
794 template <class _T1, class _T2>
795 inline _LIBCPP_INLINE_VISIBILITY
796 constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT
798 return __get_pair<0>::get(_VSTD::move(__p));
801 template <class _T1, class _T2>
802 inline _LIBCPP_INLINE_VISIBILITY
803 constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT
805 return __get_pair<0>::get(_VSTD::move(__p));
808 template <class _T1, class _T2>
809 inline _LIBCPP_INLINE_VISIBILITY
810 constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT
812 return __get_pair<1>::get(__p);
815 template <class _T1, class _T2>
816 inline _LIBCPP_INLINE_VISIBILITY
817 constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT
819 return __get_pair<1>::get(__p);
822 template <class _T1, class _T2>
823 inline _LIBCPP_INLINE_VISIBILITY
824 constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT
826 return __get_pair<1>::get(_VSTD::move(__p));
829 template <class _T1, class _T2>
830 inline _LIBCPP_INLINE_VISIBILITY
831 constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT
833 return __get_pair<1>::get(_VSTD::move(__p));
838 #if _LIBCPP_STD_VER > 11
840 template<class _Tp, _Tp... _Ip>
841 struct _LIBCPP_TEMPLATE_VIS integer_sequence
843 typedef _Tp value_type;
844 static_assert( is_integral<_Tp>::value,
845 "std::integer_sequence can only be instantiated with an integral type" );
847 _LIBCPP_INLINE_VISIBILITY
850 size() noexcept { return sizeof...(_Ip); }
853 template<size_t... _Ip>
854 using index_sequence = integer_sequence<size_t, _Ip...>;
856 #if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
858 template <class _Tp, _Tp _Ep>
859 using __make_integer_sequence = __make_integer_seq<integer_sequence, _Tp, _Ep>;
863 template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked =
864 typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>;
866 template <class _Tp, _Tp _Ep>
867 struct __make_integer_sequence_checked
869 static_assert(is_integral<_Tp>::value,
870 "std::make_integer_sequence can only be instantiated with an integral type" );
871 static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length");
872 // Workaround GCC bug by preventing bad installations when 0 <= _Ep
873 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929
874 typedef __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type;
877 template <class _Tp, _Tp _Ep>
878 using __make_integer_sequence = typename __make_integer_sequence_checked<_Tp, _Ep>::type;
882 template<class _Tp, _Tp _Np>
883 using make_integer_sequence = __make_integer_sequence<_Tp, _Np>;
886 using make_index_sequence = make_integer_sequence<size_t, _Np>;
888 template<class... _Tp>
889 using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;
891 #endif // _LIBCPP_STD_VER > 11
893 #if _LIBCPP_STD_VER > 11
894 template<class _T1, class _T2 = _T1>
895 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
896 _T1 exchange(_T1& __obj, _T2 && __new_value)
898 _T1 __old_value = _VSTD::move(__obj);
899 __obj = _VSTD::forward<_T2>(__new_value);
902 #endif // _LIBCPP_STD_VER > 11
904 #if _LIBCPP_STD_VER > 14
906 struct _LIBCPP_TYPE_VIS in_place_t {
907 explicit in_place_t() = default;
909 _LIBCPP_INLINE_VAR constexpr in_place_t in_place{};
912 struct _LIBCPP_TEMPLATE_VIS in_place_type_t {
913 explicit in_place_type_t() = default;
916 _LIBCPP_INLINE_VAR constexpr in_place_type_t<_Tp> in_place_type{};
918 template <size_t _Idx>
919 struct _LIBCPP_TYPE_VIS in_place_index_t {
920 explicit in_place_index_t() = default;
922 template <size_t _Idx>
923 _LIBCPP_INLINE_VAR constexpr in_place_index_t<_Idx> in_place_index{};
925 template <class _Tp> struct __is_inplace_type_imp : false_type {};
926 template <class _Tp> struct __is_inplace_type_imp<in_place_type_t<_Tp>> : true_type {};
929 using __is_inplace_type = __is_inplace_type_imp<__uncvref_t<_Tp>>;
931 template <class _Tp> struct __is_inplace_index_imp : false_type {};
932 template <size_t _Idx> struct __is_inplace_index_imp<in_place_index_t<_Idx>> : true_type {};
935 using __is_inplace_index = __is_inplace_index_imp<__uncvref_t<_Tp>>;
937 #endif // _LIBCPP_STD_VER > 14
939 template <class _Arg, class _Result>
940 struct _LIBCPP_TEMPLATE_VIS unary_function
942 typedef _Arg argument_type;
943 typedef _Result result_type;
946 template <class _Size>
947 inline _LIBCPP_INLINE_VISIBILITY
949 __loadword(const void* __p)
952 std::memcpy(&__r, __p, sizeof(__r));
956 // We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
957 // is 64 bits. This is because cityhash64 uses 64bit x 64bit
958 // multiplication, which can be very slow on 32-bit systems.
959 template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
960 struct __murmur2_or_cityhash;
962 template <class _Size>
963 struct __murmur2_or_cityhash<_Size, 32>
965 inline _Size operator()(const void* __key, _Size __len)
966 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK;
970 template <class _Size>
972 __murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
974 const _Size __m = 0x5bd1e995;
975 const _Size __r = 24;
977 const unsigned char* __data = static_cast<const unsigned char*>(__key);
978 for (; __len >= 4; __data += 4, __len -= 4)
980 _Size __k = __loadword<_Size>(__data);
990 __h ^= __data[2] << 16;
992 __h ^= __data[1] << 8;
1003 template <class _Size>
1004 struct __murmur2_or_cityhash<_Size, 64>
1006 inline _Size operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK;
1009 // Some primes between 2^63 and 2^64.
1010 static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
1011 static const _Size __k1 = 0xb492b66fbe98f273ULL;
1012 static const _Size __k2 = 0x9ae16a3b2f90404fULL;
1013 static const _Size __k3 = 0xc949d7c7509e6557ULL;
1015 static _Size __rotate(_Size __val, int __shift) {
1016 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
1019 static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
1020 return (__val >> __shift) | (__val << (64 - __shift));
1023 static _Size __shift_mix(_Size __val) {
1024 return __val ^ (__val >> 47);
1027 static _Size __hash_len_16(_Size __u, _Size __v)
1028 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1030 const _Size __mul = 0x9ddfea08eb382d69ULL;
1031 _Size __a = (__u ^ __v) * __mul;
1033 _Size __b = (__v ^ __a) * __mul;
1039 static _Size __hash_len_0_to_16(const char* __s, _Size __len)
1040 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1043 const _Size __a = __loadword<_Size>(__s);
1044 const _Size __b = __loadword<_Size>(__s + __len - 8);
1045 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
1048 const uint32_t __a = __loadword<uint32_t>(__s);
1049 const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
1050 return __hash_len_16(__len + (__a << 3), __b);
1053 const unsigned char __a = __s[0];
1054 const unsigned char __b = __s[__len >> 1];
1055 const unsigned char __c = __s[__len - 1];
1056 const uint32_t __y = static_cast<uint32_t>(__a) +
1057 (static_cast<uint32_t>(__b) << 8);
1058 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
1059 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
1064 static _Size __hash_len_17_to_32(const char *__s, _Size __len)
1065 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1067 const _Size __a = __loadword<_Size>(__s) * __k1;
1068 const _Size __b = __loadword<_Size>(__s + 8);
1069 const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
1070 const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
1071 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
1072 __a + __rotate(__b ^ __k3, 20) - __c + __len);
1075 // Return a 16-byte hash for 48 bytes. Quick and dirty.
1076 // Callers do best to use "random-looking" values for a and b.
1077 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
1078 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b)
1079 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1082 __b = __rotate(__b + __a + __z, 21);
1083 const _Size __c = __a;
1086 __b += __rotate(__a, 44);
1087 return pair<_Size, _Size>(__a + __z, __b + __c);
1090 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
1091 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
1092 const char* __s, _Size __a, _Size __b)
1093 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1095 return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
1096 __loadword<_Size>(__s + 8),
1097 __loadword<_Size>(__s + 16),
1098 __loadword<_Size>(__s + 24),
1103 // Return an 8-byte hash for 33 to 64 bytes.
1104 static _Size __hash_len_33_to_64(const char *__s, size_t __len)
1105 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1107 _Size __z = __loadword<_Size>(__s + 24);
1108 _Size __a = __loadword<_Size>(__s) +
1109 (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
1110 _Size __b = __rotate(__a + __z, 52);
1111 _Size __c = __rotate(__a, 37);
1112 __a += __loadword<_Size>(__s + 8);
1113 __c += __rotate(__a, 7);
1114 __a += __loadword<_Size>(__s + 16);
1115 _Size __vf = __a + __z;
1116 _Size __vs = __b + __rotate(__a, 31) + __c;
1117 __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
1118 __z += __loadword<_Size>(__s + __len - 8);
1119 __b = __rotate(__a + __z, 52);
1120 __c = __rotate(__a, 37);
1121 __a += __loadword<_Size>(__s + __len - 24);
1122 __c += __rotate(__a, 7);
1123 __a += __loadword<_Size>(__s + __len - 16);
1124 _Size __wf = __a + __z;
1125 _Size __ws = __b + __rotate(__a, 31) + __c;
1126 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
1127 return __shift_mix(__r * __k0 + __vs) * __k2;
1132 template <class _Size>
1134 __murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
1136 const char* __s = static_cast<const char*>(__key);
1139 return __hash_len_0_to_16(__s, __len);
1141 return __hash_len_17_to_32(__s, __len);
1143 } else if (__len <= 64) {
1144 return __hash_len_33_to_64(__s, __len);
1147 // For strings over 64 bytes we hash the end first, and then as we
1148 // loop we keep 56 bytes of state: v, w, x, y, and z.
1149 _Size __x = __loadword<_Size>(__s + __len - 40);
1150 _Size __y = __loadword<_Size>(__s + __len - 16) +
1151 __loadword<_Size>(__s + __len - 56);
1152 _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
1153 __loadword<_Size>(__s + __len - 24));
1154 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
1155 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
1156 __x = __x * __k1 + __loadword<_Size>(__s);
1158 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
1159 __len = (__len - 1) & ~static_cast<_Size>(63);
1161 __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
1162 __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
1164 __y += __v.first + __loadword<_Size>(__s + 40);
1165 __z = __rotate(__z + __w.first, 33) * __k1;
1166 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
1167 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
1168 __y + __loadword<_Size>(__s + 16));
1169 std::swap(__z, __x);
1172 } while (__len != 0);
1173 return __hash_len_16(
1174 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
1175 __hash_len_16(__v.second, __w.second) + __x);
1178 template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
1179 struct __scalar_hash;
1181 template <class _Tp>
1182 struct __scalar_hash<_Tp, 0>
1183 : public unary_function<_Tp, size_t>
1185 _LIBCPP_INLINE_VISIBILITY
1186 size_t operator()(_Tp __v) const _NOEXCEPT
1199 template <class _Tp>
1200 struct __scalar_hash<_Tp, 1>
1201 : public unary_function<_Tp, size_t>
1203 _LIBCPP_INLINE_VISIBILITY
1204 size_t operator()(_Tp __v) const _NOEXCEPT
1216 template <class _Tp>
1217 struct __scalar_hash<_Tp, 2>
1218 : public unary_function<_Tp, size_t>
1220 _LIBCPP_INLINE_VISIBILITY
1221 size_t operator()(_Tp __v) const _NOEXCEPT
1233 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
1237 template <class _Tp>
1238 struct __scalar_hash<_Tp, 3>
1239 : public unary_function<_Tp, size_t>
1241 _LIBCPP_INLINE_VISIBILITY
1242 size_t operator()(_Tp __v) const _NOEXCEPT
1255 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
1259 template <class _Tp>
1260 struct __scalar_hash<_Tp, 4>
1261 : public unary_function<_Tp, size_t>
1263 _LIBCPP_INLINE_VISIBILITY
1264 size_t operator()(_Tp __v) const _NOEXCEPT
1278 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
1287 _LIBCPP_INLINE_VISIBILITY
1288 inline size_t __hash_combine(size_t __lhs, size_t __rhs) _NOEXCEPT {
1289 typedef __scalar_hash<_PairT> _HashT;
1290 const _PairT __p = {__lhs, __rhs};
1291 return _HashT()(__p);
1295 struct _LIBCPP_TEMPLATE_VIS hash<_Tp*>
1296 : public unary_function<_Tp*, size_t>
1298 _LIBCPP_INLINE_VISIBILITY
1299 size_t operator()(_Tp* __v) const _NOEXCEPT
1307 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
1313 struct _LIBCPP_TEMPLATE_VIS hash<bool>
1314 : public unary_function<bool, size_t>
1316 _LIBCPP_INLINE_VISIBILITY
1317 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1321 struct _LIBCPP_TEMPLATE_VIS hash<char>
1322 : public unary_function<char, size_t>
1324 _LIBCPP_INLINE_VISIBILITY
1325 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1329 struct _LIBCPP_TEMPLATE_VIS hash<signed char>
1330 : public unary_function<signed char, size_t>
1332 _LIBCPP_INLINE_VISIBILITY
1333 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1337 struct _LIBCPP_TEMPLATE_VIS hash<unsigned char>
1338 : public unary_function<unsigned char, size_t>
1340 _LIBCPP_INLINE_VISIBILITY
1341 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1344 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
1347 struct _LIBCPP_TEMPLATE_VIS hash<char16_t>
1348 : public unary_function<char16_t, size_t>
1350 _LIBCPP_INLINE_VISIBILITY
1351 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1355 struct _LIBCPP_TEMPLATE_VIS hash<char32_t>
1356 : public unary_function<char32_t, size_t>
1358 _LIBCPP_INLINE_VISIBILITY
1359 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1362 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
1365 struct _LIBCPP_TEMPLATE_VIS hash<wchar_t>
1366 : public unary_function<wchar_t, size_t>
1368 _LIBCPP_INLINE_VISIBILITY
1369 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1373 struct _LIBCPP_TEMPLATE_VIS hash<short>
1374 : public unary_function<short, size_t>
1376 _LIBCPP_INLINE_VISIBILITY
1377 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1381 struct _LIBCPP_TEMPLATE_VIS hash<unsigned short>
1382 : public unary_function<unsigned short, size_t>
1384 _LIBCPP_INLINE_VISIBILITY
1385 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1389 struct _LIBCPP_TEMPLATE_VIS hash<int>
1390 : public unary_function<int, size_t>
1392 _LIBCPP_INLINE_VISIBILITY
1393 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1397 struct _LIBCPP_TEMPLATE_VIS hash<unsigned int>
1398 : public unary_function<unsigned int, size_t>
1400 _LIBCPP_INLINE_VISIBILITY
1401 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1405 struct _LIBCPP_TEMPLATE_VIS hash<long>
1406 : public unary_function<long, size_t>
1408 _LIBCPP_INLINE_VISIBILITY
1409 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1413 struct _LIBCPP_TEMPLATE_VIS hash<unsigned long>
1414 : public unary_function<unsigned long, size_t>
1416 _LIBCPP_INLINE_VISIBILITY
1417 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1421 struct _LIBCPP_TEMPLATE_VIS hash<long long>
1422 : public __scalar_hash<long long>
1427 struct _LIBCPP_TEMPLATE_VIS hash<unsigned long long>
1428 : public __scalar_hash<unsigned long long>
1432 #ifndef _LIBCPP_HAS_NO_INT128
1435 struct _LIBCPP_TEMPLATE_VIS hash<__int128_t>
1436 : public __scalar_hash<__int128_t>
1441 struct _LIBCPP_TEMPLATE_VIS hash<__uint128_t>
1442 : public __scalar_hash<__uint128_t>
1449 struct _LIBCPP_TEMPLATE_VIS hash<float>
1450 : public __scalar_hash<float>
1452 _LIBCPP_INLINE_VISIBILITY
1453 size_t operator()(float __v) const _NOEXCEPT
1455 // -0.0 and 0.0 should return same hash
1458 return __scalar_hash<float>::operator()(__v);
1463 struct _LIBCPP_TEMPLATE_VIS hash<double>
1464 : public __scalar_hash<double>
1466 _LIBCPP_INLINE_VISIBILITY
1467 size_t operator()(double __v) const _NOEXCEPT
1469 // -0.0 and 0.0 should return same hash
1472 return __scalar_hash<double>::operator()(__v);
1477 struct _LIBCPP_TEMPLATE_VIS hash<long double>
1478 : public __scalar_hash<long double>
1480 _LIBCPP_INLINE_VISIBILITY
1481 size_t operator()(long double __v) const _NOEXCEPT
1483 // -0.0 and 0.0 should return same hash
1486 #if defined(__i386__)
1487 // Zero out padding bits
1504 return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d;
1505 #elif defined(__x86_64__)
1506 // Zero out padding bits
1519 return __u.__s.__a ^ __u.__s.__b;
1521 return __scalar_hash<long double>::operator()(__v);
1526 #if _LIBCPP_STD_VER > 11
1528 template <class _Tp, bool = is_enum<_Tp>::value>
1529 struct _LIBCPP_TEMPLATE_VIS __enum_hash
1530 : public unary_function<_Tp, size_t>
1532 _LIBCPP_INLINE_VISIBILITY
1533 size_t operator()(_Tp __v) const _NOEXCEPT
1535 typedef typename underlying_type<_Tp>::type type;
1536 return hash<type>{}(static_cast<type>(__v));
1539 template <class _Tp>
1540 struct _LIBCPP_TEMPLATE_VIS __enum_hash<_Tp, false> {
1541 __enum_hash() = delete;
1542 __enum_hash(__enum_hash const&) = delete;
1543 __enum_hash& operator=(__enum_hash const&) = delete;
1546 template <class _Tp>
1547 struct _LIBCPP_TEMPLATE_VIS hash : public __enum_hash<_Tp>
1552 #if _LIBCPP_STD_VER > 14
1555 struct _LIBCPP_TEMPLATE_VIS hash<nullptr_t>
1556 : public unary_function<nullptr_t, size_t>
1558 _LIBCPP_INLINE_VISIBILITY
1559 size_t operator()(nullptr_t) const _NOEXCEPT {
1560 return 662607004ull;
1565 #ifndef _LIBCPP_CXX03_LANG
1566 template <class _Key, class _Hash>
1567 using __check_hash_requirements = integral_constant<bool,
1568 is_copy_constructible<_Hash>::value &&
1569 is_move_constructible<_Hash>::value &&
1570 __invokable_r<size_t, _Hash, _Key const&>::value
1573 template <class _Key, class _Hash = std::hash<_Key> >
1574 using __has_enabled_hash = integral_constant<bool,
1575 __check_hash_requirements<_Key, _Hash>::value &&
1576 is_default_constructible<_Hash>::value
1579 #if _LIBCPP_STD_VER > 14
1580 template <class _Type, class>
1581 using __enable_hash_helper_imp = _Type;
1583 template <class _Type, class ..._Keys>
1584 using __enable_hash_helper = __enable_hash_helper_imp<_Type,
1585 typename enable_if<__all<__has_enabled_hash<_Keys>::value...>::value>::type
1588 template <class _Type, class ...>
1589 using __enable_hash_helper = _Type;
1592 #endif // !_LIBCPP_CXX03_LANG
1594 _LIBCPP_END_NAMESPACE_STD
1596 #endif // _LIBCPP_UTILITY