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