blob: 49e7b3e85c6710dcf7da68ca0cbf6aaaae542c53 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- utility -----------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// 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
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_UTILITY
11#define _LIBCPP_UTILITY
12
13/*
14 utility synopsis
15
Louis Dionneb5769a32018-07-05 16:16:03 +000016#include <initializer_list>
17
Howard Hinnantc51e1022010-05-11 19:42:16 +000018namespace 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
Howard Hinnantdbfd4b42011-05-27 15:04:19 +000033template<class T>
34void
35swap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value &&
36 is_nothrow_move_assignable<T>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000037
Howard Hinnantdbfd4b42011-05-27 15:04:19 +000038template <class T, size_t N>
39void
40swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)));
41
Marshall Clowfe9aa372013-07-15 20:46:11 +000042template <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
Howard Hinnantdbfd4b42011-05-27 15:04:19 +000044
Marshall Clowfe9aa372013-07-15 20:46:11 +000045template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000046
47template <class T>
48 typename conditional
49 <
Howard Hinnanta9a897e2010-11-19 22:17:28 +000050 !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +000051 const T&,
52 T&&
53 >::type
Marshall Clowfe9aa372013-07-15 20:46:11 +000054 move_if_noexcept(T& x) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000055
Marshall Clow5d305742018-02-11 21:51:49 +000056template <class T> constexpr add_const_t<T>& as_const(T& t) noexcept; // C++17
Marshall Clow845efe42015-11-17 00:08:08 +000057template <class T> void as_const(const T&&) = delete; // C++17
58
Howard Hinnantc51e1022010-05-11 19:42:16 +000059template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
60
Kamlesh Kumarc1964592021-04-20 04:48:34 +053061template<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
Howard Hinnantc51e1022010-05-11 19:42:16 +000069template <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;
Howard Hinnantdbfd4b42011-05-27 15:04:19 +000079 pair(pair&&) = default;
Louis Dionnea7a2beb2019-09-26 14:51:10 +000080 explicit(see-below) constexpr pair();
Louis Dionne1afad1d2019-07-22 20:45:23 +000081 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
Howard Hinnantc51e1022010-05-11 19:42:16 +000085 template <class... Args1, class... Args2>
86 pair(piecewise_construct_t, tuple<Args1...> first_args,
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050087 tuple<Args2...> second_args); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000088
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050089 template <class U, class V> pair& operator=(const pair<U, V>& p); // constexpr in C++20
Howard Hinnantdbfd4b42011-05-27 15:04:19 +000090 pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value &&
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050091 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
Howard Hinnantc51e1022010-05-11 19:42:16 +000093
Eric Fiselier6bfed252016-04-21 23:38:59 +000094 void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> &&
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050095 is_nothrow_swappable_v<T2>); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000096};
97
Marshall Clowf00c56c2013-07-16 17:45:44 +000098template <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
Howard Hinnantc51e1022010-05-11 19:42:16 +0000104
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500105template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14
Howard Hinnantdbfd4b42011-05-27 15:04:19 +0000106template <class T1, class T2>
107void
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500108swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000109
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000110struct piecewise_construct_t { explicit piecewise_construct_t() = default; };
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000111inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000112
Marshall Clowce62b4d2019-01-11 21:57:12 +0000113template <class T> struct tuple_size;
Louis Dionnee684aa62019-04-01 16:39:34 +0000114template <size_t I, class T> struct tuple_element;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000115
Marshall Clowf50d66f2014-03-03 06:18:11 +0000116template <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> >;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000119
120template<size_t I, class T1, class T2>
Marshall Clowf50d66f2014-03-03 06:18:11 +0000121 typename tuple_element<I, pair<T1, T2> >::type&
122 get(pair<T1, T2>&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000123
124template<size_t I, class T1, class T2>
Marshall Clow36907512015-11-19 19:45:29 +0000125 const typename tuple_element<I, pair<T1, T2> >::type&
Marshall Clowf50d66f2014-03-03 06:18:11 +0000126 get(const pair<T1, T2>&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000127
Howard Hinnant22e97242010-11-17 19:52:17 +0000128template<size_t I, class T1, class T2>
Marshall Clowf50d66f2014-03-03 06:18:11 +0000129 typename tuple_element<I, pair<T1, T2> >::type&&
130 get(pair<T1, T2>&&) noexcept; // constexpr in C++14
Howard Hinnant22e97242010-11-17 19:52:17 +0000131
Eric Fiselier6dea8092015-12-18 00:36:55 +0000132template<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
Marshall Clow15b02e02013-07-13 02:54:05 +0000136template<class T1, class T2>
Marshall Clowf50d66f2014-03-03 06:18:11 +0000137 constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000138
Eric Fiselier6dea8092015-12-18 00:36:55 +0000139template<class T1, class T2>
Marshall Clow36907512015-11-19 19:45:29 +0000140 constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000141
Eric Fiselier6dea8092015-12-18 00:36:55 +0000142template<class T1, class T2>
Marshall Clowf50d66f2014-03-03 06:18:11 +0000143 constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000144
Eric Fiselier6dea8092015-12-18 00:36:55 +0000145template<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
Marshall Clow9a970d82013-07-01 16:26:55 +0000160// 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
Marshall Clowfa8ccca2016-06-19 19:29:52 +0000181template<class T, class U=T>
Marshall Clow867ca362013-07-08 20:54:40 +0000182 T exchange(T& obj, U&& new_value);
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +0000183
184// 20.2.7, in-place construction // C++17
Eric Fiselier99b81712016-11-17 19:24:04 +0000185struct in_place_t {
186 explicit in_place_t() = default;
187};
188inline constexpr in_place_t in_place{};
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +0000189template <class T>
Eric Fiselier99b81712016-11-17 19:24:04 +0000190 struct in_place_type_t {
191 explicit in_place_type_t() = default;
192 };
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +0000193template <class T>
Eric Fiselier99b81712016-11-17 19:24:04 +0000194 inline constexpr in_place_type_t<T> in_place_type{};
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +0000195template <size_t I>
Eric Fiselier99b81712016-11-17 19:24:04 +0000196 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{};
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +0000201
Marek Kurdej4fc4b4c2021-03-05 09:19:39 +0100202// [utility.underlying], to_underlying
203template <class T>
204 constexpr underlying_type_t<T> to_underlying( T value ) noexcept; // C++2b
205
Howard Hinnantc51e1022010-05-11 19:42:16 +0000206} // std
207
208*/
209
210#include <__config>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400211#include <__debug>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000212#include <__tuple>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000213#include <__utility/declval.h>
214#include <__utility/forward.h>
215#include <__utility/move.h>
216#include <__utility/swap.h>
Mark de Wevera8b93aa2021-04-24 17:28:35 +0200217#include <__utility/to_underlying.h>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400218#include <compare>
Eric Fiselier698a97b2017-01-21 00:02:12 +0000219#include <cstddef>
Eric Fiselier698a97b2017-01-21 00:02:12 +0000220#include <cstdint>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400221#include <cstring>
222#include <initializer_list>
Kamlesh Kumarc1964592021-04-20 04:48:34 +0530223#include <limits>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400224#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000225#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000226
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000227#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000228#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000229#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000230
Kamlesh Kumarc1964592021-04-20 04:48:34 +0530231_LIBCPP_PUSH_MACROS
232#include <__undef_macros>
233
Howard Hinnantc51e1022010-05-11 19:42:16 +0000234_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
Marshall Clow845efe42015-11-17 00:08:08 +0000273#if _LIBCPP_STD_VER > 14
Arthur O'Dwyer108facb2021-04-05 14:56:03 -0400274template <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;
Marshall Clow845efe42015-11-17 00:08:08 +0000279#endif
280
Kamlesh Kumarc1964592021-04-20 04:48:34 +0530281#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,
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -0400288#ifndef _LIBCPP_HAS_NO_CHAR8_T
Kamlesh Kumarc1964592021-04-20 04:48:34 +0530289 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
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000357struct _LIBCPP_TEMPLATE_VIS piecewise_construct_t { explicit piecewise_construct_t() = default; };
Louis Dionne5e0eadd2018-08-01 02:08:59 +0000358#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Louis Dionne5254b372018-10-25 12:13:43 +0000359extern _LIBCPP_EXPORTED_FROM_ABI const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
Howard Hinnant7d7e9582012-04-03 21:09:48 +0000360#else
Marshall Clowbc084382018-01-02 18:57:47 +0000361/* _LIBCPP_INLINE_VAR */ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
Howard Hinnant7d7e9582012-04-03 21:09:48 +0000362#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000363
Eric Fiselierf9618bb2016-10-11 21:22:21 +0000364#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
Eric Fiselierbfb285c2019-01-16 01:54:34 +0000365template <class, class>
Eric Fiselierf9618bb2016-10-11 21:22:21 +0000366struct __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
Eric Fiseliere61db632016-07-25 04:32:07 +0000373
Howard Hinnantc51e1022010-05-11 19:42:16 +0000374template <class _T1, class _T2>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000375struct _LIBCPP_TEMPLATE_VIS pair
Eric Fiselierf9618bb2016-10-11 21:22:21 +0000376#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
Eric Fiselierbfb285c2019-01-16 01:54:34 +0000377: private __non_trivially_copyable_base<_T1, _T2>
Eric Fiselierf9618bb2016-10-11 21:22:21 +0000378#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379{
380 typedef _T1 first_type;
381 typedef _T2 second_type;
382
383 _T1 first;
384 _T2 second;
385
Eric Fiselierf9618bb2016-10-11 21:22:21 +0000386#if !defined(_LIBCPP_CXX03_LANG)
Eric Fiselier08f7fe82016-07-18 01:58:37 +0000387 pair(pair const&) = default;
388 pair(pair&&) = default;
389#else
390 // Use the implicitly declared copy constructor in C++03
Marshall Clowf00c56c2013-07-16 17:45:44 +0000391#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000392
Eric Fiseliere61db632016-07-25 04:32:07 +0000393#ifdef _LIBCPP_CXX03_LANG
394 _LIBCPP_INLINE_VISIBILITY
395 pair() : first(), second() {}
Eric Fiselier737a16d2016-07-25 02:36:42 +0000396
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000397 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere61db632016-07-25 04:32:07 +0000398 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>
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000412 using _EnableB _LIBCPP_NODEBUG_TYPE = typename enable_if<_Val, bool>::type;
Eric Fiseliere61db632016-07-25 04:32:07 +0000413
414 struct _CheckArgs {
Eric Fiselier18d72a02019-09-30 20:55:30 +0000415 template <int&...>
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000416 static constexpr bool __enable_explicit_default() {
Eric Fiselier18d72a02019-09-30 20:55:30 +0000417 return is_default_constructible<_T1>::value
418 && is_default_constructible<_T2>::value
419 && !__enable_implicit_default<>();
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000420 }
421
Eric Fiselier18d72a02019-09-30 20:55:30 +0000422 template <int&...>
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000423 static constexpr bool __enable_implicit_default() {
Eric Fiselier18d72a02019-09-30 20:55:30 +0000424 return __is_implicitly_default_constructible<_T1>::value
425 && __is_implicitly_default_constructible<_T2>::value;
Eric Fiseliere61db632016-07-25 04:32:07 +0000426 }
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>
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000446 using _CheckArgsDep _LIBCPP_NODEBUG_TYPE = typename conditional<
Eric Fiseliere61db632016-07-25 04:32:07 +0000447 _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>
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000468 using _CheckTLC _LIBCPP_NODEBUG_TYPE = typename conditional<
Eric Fiseliere61db632016-07-25 04:32:07 +0000469 __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<
Eric Fiselier18d72a02019-09-30 20:55:30 +0000476 _CheckArgsDep<_Dummy>::__enable_explicit_default()
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000477 > = 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<
Eric Fiselier18d72a02019-09-30 20:55:30 +0000484 _CheckArgsDep<_Dummy>::__enable_implicit_default()
Eric Fiseliere61db632016-07-25 04:32:07 +0000485 > = false>
486 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Louis Dionnee7e477a2018-12-11 14:22:28 +0000487 pair() _NOEXCEPT_(is_nothrow_default_constructible<first_type>::value &&
488 is_nothrow_default_constructible<second_type>::value)
489 : first(), second() {}
Eric Fiseliere61db632016-07-25 04:32:07 +0000490
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)
Louis Dionnee7e477a2018-12-11 14:22:28 +0000496 _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
497 is_nothrow_copy_constructible<second_type>::value)
Eric Fiseliere61db632016-07-25 04:32:07 +0000498 : 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)
Louis Dionnee7e477a2018-12-11 14:22:28 +0000505 _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
506 is_nothrow_copy_constructible<second_type>::value)
Eric Fiseliere61db632016-07-25 04:32:07 +0000507 : 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)
Louis Dionnee7e477a2018-12-11 14:22:28 +0000514 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value &&
515 is_nothrow_constructible<second_type, _U2>::value))
Eric Fiseliere61db632016-07-25 04:32:07 +0000516 : 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)
Louis Dionnee7e477a2018-12-11 14:22:28 +0000523 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value &&
524 is_nothrow_constructible<second_type, _U2>::value))
Eric Fiseliere61db632016-07-25 04:32:07 +0000525 : 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)
Louis Dionnee7e477a2018-12-11 14:22:28 +0000532 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value &&
533 is_nothrow_constructible<second_type, _U2 const&>::value))
Eric Fiseliere61db632016-07-25 04:32:07 +0000534 : 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)
Louis Dionnee7e477a2018-12-11 14:22:28 +0000541 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value &&
542 is_nothrow_constructible<second_type, _U2 const&>::value))
Eric Fiseliere61db632016-07-25 04:32:07 +0000543 : 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)
Louis Dionnee7e477a2018-12-11 14:22:28 +0000550 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value &&
551 is_nothrow_constructible<second_type, _U2&&>::value))
Eric Fiseliere61db632016-07-25 04:32:07 +0000552 : 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)
Louis Dionnee7e477a2018-12-11 14:22:28 +0000559 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value &&
560 is_nothrow_constructible<second_type, _U2&&>::value))
Eric Fiseliere61db632016-07-25 04:32:07 +0000561 : 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>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +0200580 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiseliere61db632016-07-25 04:32:07 +0000581 pair(piecewise_construct_t __pc,
582 tuple<_Args1...> __first_args, tuple<_Args2...> __second_args)
Louis Dionnee7e477a2018-12-11 14:22:28 +0000583 _NOEXCEPT_((is_nothrow_constructible<first_type, _Args1...>::value &&
584 is_nothrow_constructible<second_type, _Args2...>::value))
Eric Fiseliere61db632016-07-25 04:32:07 +0000585 : pair(__pc, __first_args, __second_args,
586 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
587 typename __make_tuple_indices<sizeof...(_Args2) >::type()) {}
588
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +0200589 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiseliere61db632016-07-25 04:32:07 +0000590 pair& operator=(typename conditional<
591 is_copy_assignable<first_type>::value &&
592 is_copy_assignable<second_type>::value,
593 pair, __nat>::type const& __p)
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000594 _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value &&
595 is_nothrow_copy_assignable<second_type>::value)
Howard Hinnantdbfd4b42011-05-27 15:04:19 +0000596 {
597 first = __p.first;
598 second = __p.second;
599 return *this;
600 }
601
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +0200602 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiseliere61db632016-07-25 04:32:07 +0000603 pair& operator=(typename conditional<
604 is_move_assignable<first_type>::value &&
605 is_move_assignable<second_type>::value,
606 pair, __nat>::type&& __p)
Eric Fiselier737a16d2016-07-25 02:36:42 +0000607 _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 }
Eric Fiseliere61db632016-07-25 04:32:07 +0000614
615 template <class _Tuple, _EnableB<
Eric Fiselier9e0256b2016-08-29 01:43:41 +0000616 _CheckTLC<_Tuple>::template __enable_assign<_Tuple>()
Eric Fiseliere61db632016-07-25 04:32:07 +0000617 > = false>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +0200618 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiseliere61db632016-07-25 04:32:07 +0000619 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 }
Eric Fiselier737a16d2016-07-25 02:36:42 +0000624#endif
625
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +0200626 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantdbfd4b42011-05-27 15:04:19 +0000627 void
Howard Hinnant89ef1212011-05-27 19:08:18 +0000628 swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value &&
629 __is_nothrow_swappable<second_type>::value)
Howard Hinnantdbfd4b42011-05-27 15:04:19 +0000630 {
Marshall Clow8b9bd542015-09-22 17:50:11 +0000631 using _VSTD::swap;
632 swap(first, __p.first);
633 swap(second, __p.second);
Howard Hinnantdbfd4b42011-05-27 15:04:19 +0000634 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000635private:
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000636
Eric Fiseliere61db632016-07-25 04:32:07 +0000637#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000638 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +0200639 _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...>);
Eric Fiseliere61db632016-07-25 04:32:07 +0000643#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644};
645
Eric Fiselier8df4ac62017-10-04 00:04:26 +0000646#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
Howard Hinnantc51e1022010-05-11 19:42:16 +0000651template <class _T1, class _T2>
Marshall Clowf00c56c2013-07-16 17:45:44 +0000652inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000653bool
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>
Marshall Clowf00c56c2013-07-16 17:45:44 +0000660inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000661bool
662operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
663{
664 return !(__x == __y);
665}
666
667template <class _T1, class _T2>
Marshall Clowf00c56c2013-07-16 17:45:44 +0000668inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669bool
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>
Marshall Clowf00c56c2013-07-16 17:45:44 +0000676inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000677bool
678operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
679{
680 return __y < __x;
681}
682
683template <class _T1, class _T2>
Marshall Clowf00c56c2013-07-16 17:45:44 +0000684inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000685bool
686operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
687{
688 return !(__x < __y);
689}
690
691template <class _T1, class _T2>
Marshall Clowf00c56c2013-07-16 17:45:44 +0000692inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693bool
694operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
695{
696 return !(__y < __x);
697}
698
699template <class _T1, class _T2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +0200700inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant44267242011-06-01 19:59:32 +0000701typename enable_if
702<
703 __is_swappable<_T1>::value &&
704 __is_swappable<_T2>::value,
705 void
706>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +0000707swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000708 _NOEXCEPT_((__is_nothrow_swappable<_T1>::value &&
709 __is_nothrow_swappable<_T2>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000710{
Howard Hinnantdbfd4b42011-05-27 15:04:19 +0000711 __x.swap(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000712}
713
Louis Dionnedb1892a2018-12-03 14:03:27 +0000714template <class _Tp>
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000715struct __unwrap_reference { typedef _LIBCPP_NODEBUG_TYPE _Tp type; };
Louis Dionnedb1892a2018-12-03 14:03:27 +0000716
717template <class _Tp>
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000718struct __unwrap_reference<reference_wrapper<_Tp> > { typedef _LIBCPP_NODEBUG_TYPE _Tp& type; };
Louis Dionnedb1892a2018-12-03 14:03:27 +0000719
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
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000737#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000738
Howard Hinnantc51e1022010-05-11 19:42:16 +0000739template <class _T1, class _T2>
Marshall Clowf00c56c2013-07-16 17:45:44 +0000740inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +0000741pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000742make_pair(_T1&& __t1, _T2&& __t2)
743{
Louis Dionnedb1892a2018-12-03 14:03:27 +0000744 return pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000745 (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000746}
747
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000748#else // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000749
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
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400758#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000759
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760template <class _T1, class _T2>
Marshall Clowce62b4d2019-01-11 21:57:12 +0000761 struct _LIBCPP_TEMPLATE_VIS tuple_size<pair<_T1, _T2> >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000762 : public integral_constant<size_t, 2> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763
Marshall Clow185577f2017-06-12 16:13:17 +0000764template <size_t _Ip, class _T1, class _T2>
Louis Dionnee684aa62019-04-01 16:39:34 +0000765struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> >
Marshall Clow185577f2017-06-12 16:13:17 +0000766{
767 static_assert(_Ip < 2, "Index out of bounds in std::tuple_element<std::pair<T1, T2>>");
768};
769
Howard Hinnantc51e1022010-05-11 19:42:16 +0000770template <class _T1, class _T2>
Louis Dionnee684aa62019-04-01 16:39:34 +0000771struct _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000772{
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000773 typedef _LIBCPP_NODEBUG_TYPE _T1 type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774};
775
776template <class _T1, class _T2>
Louis Dionnee684aa62019-04-01 16:39:34 +0000777struct _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000778{
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000779 typedef _LIBCPP_NODEBUG_TYPE _T2 type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000780};
781
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782template <size_t _Ip> struct __get_pair;
783
784template <>
785struct __get_pair<0>
786{
787 template <class _T1, class _T2>
788 static
Marshall Clow0abb1042013-07-17 18:25:36 +0000789 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000790 _T1&
Howard Hinnant89ef1212011-05-27 19:08:18 +0000791 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000792
793 template <class _T1, class _T2>
794 static
Marshall Clow0abb1042013-07-17 18:25:36 +0000795 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000796 const _T1&
Howard Hinnant89ef1212011-05-27 19:08:18 +0000797 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnant22e97242010-11-17 19:52:17 +0000798
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000799#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000800 template <class _T1, class _T2>
801 static
Marshall Clow0abb1042013-07-17 18:25:36 +0000802 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant22e97242010-11-17 19:52:17 +0000803 _T1&&
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000804 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);}
Howard Hinnant22e97242010-11-17 19:52:17 +0000805
Eric Fiselier6dea8092015-12-18 00:36:55 +0000806 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);}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400811#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000812};
813
814template <>
815struct __get_pair<1>
816{
817 template <class _T1, class _T2>
818 static
Marshall Clow0abb1042013-07-17 18:25:36 +0000819 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000820 _T2&
Howard Hinnant89ef1212011-05-27 19:08:18 +0000821 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000822
823 template <class _T1, class _T2>
824 static
Marshall Clow0abb1042013-07-17 18:25:36 +0000825 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000826 const _T2&
Howard Hinnant89ef1212011-05-27 19:08:18 +0000827 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnant22e97242010-11-17 19:52:17 +0000828
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000829#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000830 template <class _T1, class _T2>
831 static
Marshall Clow0abb1042013-07-17 18:25:36 +0000832 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant22e97242010-11-17 19:52:17 +0000833 _T2&&
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000834 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);}
Howard Hinnant22e97242010-11-17 19:52:17 +0000835
Eric Fiselier6dea8092015-12-18 00:36:55 +0000836 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);}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400841#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000842};
843
844template <size_t _Ip, class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000845inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000846typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnant89ef1212011-05-27 19:08:18 +0000847get(pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000848{
849 return __get_pair<_Ip>::get(__p);
850}
851
852template <size_t _Ip, class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000853inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000854const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnant89ef1212011-05-27 19:08:18 +0000855get(const pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856{
857 return __get_pair<_Ip>::get(__p);
858}
859
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000860#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000861template <size_t _Ip, class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000862inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant22e97242010-11-17 19:52:17 +0000863typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
Howard Hinnant89ef1212011-05-27 19:08:18 +0000864get(pair<_T1, _T2>&& __p) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +0000865{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000866 return __get_pair<_Ip>::get(_VSTD::move(__p));
Howard Hinnant22e97242010-11-17 19:52:17 +0000867}
868
Eric Fiselier6dea8092015-12-18 00:36:55 +0000869template <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}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400876#endif // _LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000877
Marshall Clow9a970d82013-07-01 16:26:55 +0000878#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +0000879template <class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000880inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow15b02e02013-07-13 02:54:05 +0000881constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT
882{
Marshall Clowf00c56c2013-07-16 17:45:44 +0000883 return __get_pair<0>::get(__p);
Marshall Clow15b02e02013-07-13 02:54:05 +0000884}
885
886template <class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000887inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow15b02e02013-07-13 02:54:05 +0000888constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT
889{
Marshall Clowf00c56c2013-07-16 17:45:44 +0000890 return __get_pair<0>::get(__p);
Marshall Clow15b02e02013-07-13 02:54:05 +0000891}
892
893template <class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000894inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow15b02e02013-07-13 02:54:05 +0000895constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT
896{
Marshall Clowf00c56c2013-07-16 17:45:44 +0000897 return __get_pair<0>::get(_VSTD::move(__p));
Marshall Clow15b02e02013-07-13 02:54:05 +0000898}
899
900template <class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000901inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6dea8092015-12-18 00:36:55 +0000902constexpr _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
Marshall Clow15b02e02013-07-13 02:54:05 +0000909constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT
910{
Marshall Clowf00c56c2013-07-16 17:45:44 +0000911 return __get_pair<1>::get(__p);
Marshall Clow15b02e02013-07-13 02:54:05 +0000912}
913
914template <class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000915inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow15b02e02013-07-13 02:54:05 +0000916constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT
917{
Marshall Clowf00c56c2013-07-16 17:45:44 +0000918 return __get_pair<1>::get(__p);
Marshall Clow15b02e02013-07-13 02:54:05 +0000919}
920
921template <class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000922inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow15b02e02013-07-13 02:54:05 +0000923constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT
924{
Marshall Clowf00c56c2013-07-16 17:45:44 +0000925 return __get_pair<1>::get(_VSTD::move(__p));
Marshall Clow15b02e02013-07-13 02:54:05 +0000926}
927
Eric Fiselier6dea8092015-12-18 00:36:55 +0000928template <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
Marshall Clow15b02e02013-07-13 02:54:05 +0000935#endif
936
937#if _LIBCPP_STD_VER > 11
Marshall Clow9a970d82013-07-01 16:26:55 +0000938
939template<class _Tp, _Tp... _Ip>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000940struct _LIBCPP_TEMPLATE_VIS integer_sequence
Marshall Clow9a970d82013-07-01 16:26:55 +0000941{
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
Eric Fiselierd5746922015-12-09 22:03:06 +0000955#if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
956
957template <class _Tp, _Tp _Ep>
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000958using __make_integer_sequence _LIBCPP_NODEBUG_TYPE = __make_integer_seq<integer_sequence, _Tp, _Ep>;
Eric Fiselierd5746922015-12-09 22:03:06 +0000959
960#else
961
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000962template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked _LIBCPP_NODEBUG_TYPE =
Eric Fiselier2079cc72016-06-30 22:34:43 +0000963 typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>;
Marshall Clow9a970d82013-07-01 16:26:55 +0000964
965template <class _Tp, _Tp _Ep>
Eric Fiselier2079cc72016-06-30 22:34:43 +0000966struct __make_integer_sequence_checked
Marshall Clow9a970d82013-07-01 16:26:55 +0000967{
968 static_assert(is_integral<_Tp>::value,
969 "std::make_integer_sequence can only be instantiated with an integral type" );
Eric Fiselierd5746922015-12-09 22:03:06 +0000970 static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length");
Eric Fiselier9b7456e2015-12-16 00:35:45 +0000971 // Workaround GCC bug by preventing bad installations when 0 <= _Ep
972 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000973 typedef _LIBCPP_NODEBUG_TYPE __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type;
Marshall Clow9a970d82013-07-01 16:26:55 +0000974};
975
Eric Fiselier2079cc72016-06-30 22:34:43 +0000976template <class _Tp, _Tp _Ep>
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000977using __make_integer_sequence _LIBCPP_NODEBUG_TYPE = typename __make_integer_sequence_checked<_Tp, _Ep>::type;
Eric Fiselier2079cc72016-06-30 22:34:43 +0000978
Eric Fiselierd5746922015-12-09 22:03:06 +0000979#endif
980
Marshall Clow9a970d82013-07-01 16:26:55 +0000981template<class _Tp, _Tp _Np>
Eric Fiselier2079cc72016-06-30 22:34:43 +0000982 using make_integer_sequence = __make_integer_sequence<_Tp, _Np>;
Marshall Clow9a970d82013-07-01 16:26:55 +0000983
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)>;
Marshall Clowfa8ccca2016-06-19 19:29:52 +0000989
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400990#endif // _LIBCPP_STD_VER > 11
Marshall Clow9a970d82013-07-01 16:26:55 +0000991
Marshall Clow867ca362013-07-08 20:54:40 +0000992#if _LIBCPP_STD_VER > 11
993template<class _T1, class _T2 = _T1>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000994inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clow867ca362013-07-08 20:54:40 +0000995_T1 exchange(_T1& __obj, _T2 && __new_value)
996{
Howard Hinnantecc7ba92013-07-08 21:06:38 +0000997 _T1 __old_value = _VSTD::move(__obj);
998 __obj = _VSTD::forward<_T2>(__new_value);
999 return __old_value;
Marshall Clowfa8ccca2016-06-19 19:29:52 +00001000}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001001#endif // _LIBCPP_STD_VER > 11
Marshall Clow867ca362013-07-08 20:54:40 +00001002
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +00001003#if _LIBCPP_STD_VER > 14
1004
Eric Fiselier99b81712016-11-17 19:24:04 +00001005struct _LIBCPP_TYPE_VIS in_place_t {
1006 explicit in_place_t() = default;
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +00001007};
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001008_LIBCPP_INLINE_VAR constexpr in_place_t in_place{};
Eric Fiselieraea4e192016-10-16 02:51:50 +00001009
1010template <class _Tp>
Eric Fiselier2a1b4d92017-04-20 01:45:15 +00001011struct _LIBCPP_TEMPLATE_VIS in_place_type_t {
Eric Fiselier99b81712016-11-17 19:24:04 +00001012 explicit in_place_type_t() = default;
1013};
1014template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001015_LIBCPP_INLINE_VAR constexpr in_place_type_t<_Tp> in_place_type{};
Eric Fiselieraea4e192016-10-16 02:51:50 +00001016
Eric Fiselier99b81712016-11-17 19:24:04 +00001017template <size_t _Idx>
Martin Storsjö4d6f2212021-04-06 10:55:33 +03001018struct _LIBCPP_TEMPLATE_VIS in_place_index_t {
Eric Fiselier99b81712016-11-17 19:24:04 +00001019 explicit in_place_index_t() = default;
1020};
1021template <size_t _Idx>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001022_LIBCPP_INLINE_VAR constexpr in_place_index_t<_Idx> in_place_index{};
Eric Fiselier99b81712016-11-17 19:24:04 +00001023
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 {};
Eric Fiselieraea4e192016-10-16 02:51:50 +00001026
1027template <class _Tp>
Eric Fiselier99b81712016-11-17 19:24:04 +00001028using __is_inplace_type = __is_inplace_type_imp<__uncvref_t<_Tp>>;
Eric Fiselier7e0c55e2016-07-24 07:42:13 +00001029
Michael Parka9c61fc2017-06-14 05:51:18 +00001030template <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
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +00001036#endif // _LIBCPP_STD_VER > 14
1037
Eric Fiselier698a97b2017-01-21 00:02:12 +00001038template <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;
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05001051 _VSTD::memcpy(&__r, __p, sizeof(__r));
Eric Fiselier698a97b2017-01-21 00:02:12 +00001052 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{
Eric Fiselier3308e842017-02-08 00:10:10 +00001064 inline _Size operator()(const void* __key, _Size __len)
1065 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK;
Eric Fiselier698a97b2017-01-21 00:02:12 +00001066};
1067
1068// murmur2
1069template <class _Size>
1070_Size
Eric Fiselier3308e842017-02-08 00:10:10 +00001071__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001072{
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;
Fangrui Songcb135b32018-11-07 23:51:13 +00001090 _LIBCPP_FALLTHROUGH();
Eric Fiselier698a97b2017-01-21 00:02:12 +00001091 case 2:
1092 __h ^= __data[1] << 8;
Fangrui Songcb135b32018-11-07 23:51:13 +00001093 _LIBCPP_FALLTHROUGH();
Eric Fiselier698a97b2017-01-21 00:02:12 +00001094 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{
Eric Fiselier3308e842017-02-08 00:10:10 +00001107 inline _Size operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK;
Eric Fiselier698a97b2017-01-21 00:02:12 +00001108
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
Eric Fiselier3308e842017-02-08 00:10:10 +00001128 static _Size __hash_len_16(_Size __u, _Size __v)
1129 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1130 {
Eric Fiselier698a97b2017-01-21 00:02:12 +00001131 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
Eric Fiselier3308e842017-02-08 00:10:10 +00001140 static _Size __hash_len_0_to_16(const char* __s, _Size __len)
1141 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1142 {
Eric Fiselier698a97b2017-01-21 00:02:12 +00001143 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
Eric Fiselier3308e842017-02-08 00:10:10 +00001165 static _Size __hash_len_17_to_32(const char *__s, _Size __len)
1166 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1167 {
Eric Fiselier698a97b2017-01-21 00:02:12 +00001168 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(
Eric Fiselier3308e842017-02-08 00:10:10 +00001179 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b)
1180 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1181 {
Eric Fiselier698a97b2017-01-21 00:02:12 +00001182 __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(
Eric Fiselier3308e842017-02-08 00:10:10 +00001193 const char* __s, _Size __a, _Size __b)
1194 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1195 {
Eric Fiselier698a97b2017-01-21 00:02:12 +00001196 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.
Eric Fiselier3308e842017-02-08 00:10:10 +00001205 static _Size __hash_len_33_to_64(const char *__s, size_t __len)
1206 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1207 {
Eric Fiselier698a97b2017-01-21 00:02:12 +00001208 _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
Eric Fiselier3308e842017-02-08 00:10:10 +00001235__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001236{
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));
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05001270 _VSTD::swap(__z, __x);
Eric Fiselier698a97b2017-01-21 00:02:12 +00001271 __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
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001282_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001283template <class _Tp>
1284struct __scalar_hash<_Tp, 0>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001285#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001286 : public unary_function<_Tp, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001287#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001288{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001289_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001294 _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
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001308_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001309template <class _Tp>
1310struct __scalar_hash<_Tp, 1>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001311#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001312 : public unary_function<_Tp, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001313#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001314{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001315_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001320 _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
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001333_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001334template <class _Tp>
1335struct __scalar_hash<_Tp, 2>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001336#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001337 : public unary_function<_Tp, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001338#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001339{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001340_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001345 _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
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001362_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001363template <class _Tp>
1364struct __scalar_hash<_Tp, 3>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001365#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001366 : public unary_function<_Tp, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001367#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001368{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001369_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001374 _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
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001392_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001393template <class _Tp>
1394struct __scalar_hash<_Tp, 4>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001395#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001396 : public unary_function<_Tp, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001397#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001398{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001399_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001404 _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
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001435_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001436template<class _Tp>
1437struct _LIBCPP_TEMPLATE_VIS hash<_Tp*>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001438#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001439 : public unary_function<_Tp*, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001440#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001441{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001442_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001447 _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
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001460_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001461template <>
1462struct _LIBCPP_TEMPLATE_VIS hash<bool>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001463#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001464 : public unary_function<bool, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001465#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001466{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001467_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001472 _LIBCPP_INLINE_VISIBILITY
1473 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1474};
1475
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001476_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001477template <>
1478struct _LIBCPP_TEMPLATE_VIS hash<char>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001479#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001480 : public unary_function<char, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001481#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001482{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001483_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001488 _LIBCPP_INLINE_VISIBILITY
1489 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1490};
1491
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001492_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001493template <>
1494struct _LIBCPP_TEMPLATE_VIS hash<signed char>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001495#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001496 : public unary_function<signed char, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001497#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001498{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001499_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001504 _LIBCPP_INLINE_VISIBILITY
1505 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1506};
1507
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001508_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001509template <>
1510struct _LIBCPP_TEMPLATE_VIS hash<unsigned char>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001511#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001512 : public unary_function<unsigned char, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001513#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001514{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001515_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001520 _LIBCPP_INLINE_VISIBILITY
1521 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1522};
1523
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -04001524#ifndef _LIBCPP_HAS_NO_CHAR8_T
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001525_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Yuriy Chernyshovfbb87fa2020-12-08 13:39:56 -05001526template <>
1527struct _LIBCPP_TEMPLATE_VIS hash<char8_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001528#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Yuriy Chernyshovfbb87fa2020-12-08 13:39:56 -05001529 : public unary_function<char8_t, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001530#endif
Yuriy Chernyshovfbb87fa2020-12-08 13:39:56 -05001531{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001532_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
Yuriy Chernyshovfbb87fa2020-12-08 13:39:56 -05001537 _LIBCPP_INLINE_VISIBILITY
1538 size_t operator()(char8_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1539};
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -04001540#endif // !_LIBCPP_HAS_NO_CHAR8_T
Yuriy Chernyshovfbb87fa2020-12-08 13:39:56 -05001541
Eric Fiselier698a97b2017-01-21 00:02:12 +00001542#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
1543
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001544_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001545template <>
1546struct _LIBCPP_TEMPLATE_VIS hash<char16_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001547#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001548 : public unary_function<char16_t, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001549#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001550{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001551_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001556 _LIBCPP_INLINE_VISIBILITY
1557 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1558};
1559
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001560_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001561template <>
1562struct _LIBCPP_TEMPLATE_VIS hash<char32_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001563#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001564 : public unary_function<char32_t, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001565#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001566{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001567_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001572 _LIBCPP_INLINE_VISIBILITY
1573 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1574};
1575
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001576#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Eric Fiselier698a97b2017-01-21 00:02:12 +00001577
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001578_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001579template <>
1580struct _LIBCPP_TEMPLATE_VIS hash<wchar_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001581#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001582 : public unary_function<wchar_t, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001583#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001584{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001585_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001590 _LIBCPP_INLINE_VISIBILITY
1591 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1592};
1593
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001594_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001595template <>
1596struct _LIBCPP_TEMPLATE_VIS hash<short>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001597#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001598 : public unary_function<short, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001599#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001600{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001601_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001606 _LIBCPP_INLINE_VISIBILITY
1607 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1608};
1609
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001610_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001611template <>
1612struct _LIBCPP_TEMPLATE_VIS hash<unsigned short>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001613#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001614 : public unary_function<unsigned short, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001615#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001616{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001617_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001622 _LIBCPP_INLINE_VISIBILITY
1623 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1624};
1625
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001626_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001627template <>
1628struct _LIBCPP_TEMPLATE_VIS hash<int>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001629#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001630 : public unary_function<int, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001631#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001632{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001633_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001638 _LIBCPP_INLINE_VISIBILITY
1639 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1640};
1641
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001642_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001643template <>
1644struct _LIBCPP_TEMPLATE_VIS hash<unsigned int>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001645#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001646 : public unary_function<unsigned int, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001647#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001648{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001649_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001654 _LIBCPP_INLINE_VISIBILITY
1655 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1656};
1657
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001658_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001659template <>
1660struct _LIBCPP_TEMPLATE_VIS hash<long>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001661#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001662 : public unary_function<long, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001663#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001664{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001665_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001670 _LIBCPP_INLINE_VISIBILITY
1671 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1672};
1673
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001674_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001675template <>
1676struct _LIBCPP_TEMPLATE_VIS hash<unsigned long>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001677#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001678 : public unary_function<unsigned long, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001679#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001680{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001681_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001686 _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
Bruce Mitchenerb5da8e92019-07-01 16:13:31 +00001726 if (__v == 0.0f)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001727 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
Eric Fiselierb41db9a2018-10-01 01:59:37 +00001740 if (__v == 0.0)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001741 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
Bruce Mitchenerb5da8e92019-07-01 16:13:31 +00001754 if (__v == 0.0L)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001755 return 0;
Harald van Dijk6de97772020-11-29 13:52:28 +00001756#if defined(__i386__) || (defined(__x86_64__) && defined(__ILP32__))
Eric Fiselier698a97b2017-01-21 00:02:12 +00001757 // 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
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001798_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001799template <class _Tp, bool = is_enum<_Tp>::value>
1800struct _LIBCPP_TEMPLATE_VIS __enum_hash
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001801#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001802 : public unary_function<_Tp, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001803#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001804{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001805_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
Eric Fiselier698a97b2017-01-21 00:02:12 +00001810 _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
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001832_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Eric Fiselier698a97b2017-01-21 00:02:12 +00001833template <>
1834struct _LIBCPP_TEMPLATE_VIS hash<nullptr_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001835#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001836 : public unary_function<nullptr_t, size_t>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001837#endif
Eric Fiselier698a97b2017-01-21 00:02:12 +00001838{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001839_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 }
Eric Fiselier698a97b2017-01-21 00:02:12 +00001848};
1849#endif
1850
1851#ifndef _LIBCPP_CXX03_LANG
Eric Fiselierd90b9312017-03-03 22:35:58 +00001852template <class _Key, class _Hash>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001853using __check_hash_requirements _LIBCPP_NODEBUG_TYPE = integral_constant<bool,
Eric Fiselier698a97b2017-01-21 00:02:12 +00001854 is_copy_constructible<_Hash>::value &&
1855 is_move_constructible<_Hash>::value &&
1856 __invokable_r<size_t, _Hash, _Key const&>::value
1857>;
1858
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05001859template <class _Key, class _Hash = hash<_Key> >
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001860using __has_enabled_hash _LIBCPP_NODEBUG_TYPE = integral_constant<bool,
Eric Fiselierd90b9312017-03-03 22:35:58 +00001861 __check_hash_requirements<_Key, _Hash>::value &&
1862 is_default_constructible<_Hash>::value
1863>;
1864
Eric Fiselier698a97b2017-01-21 00:02:12 +00001865#if _LIBCPP_STD_VER > 14
1866template <class _Type, class>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001867using __enable_hash_helper_imp _LIBCPP_NODEBUG_TYPE = _Type;
Eric Fiselier698a97b2017-01-21 00:02:12 +00001868
1869template <class _Type, class ..._Keys>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001870using __enable_hash_helper _LIBCPP_NODEBUG_TYPE = __enable_hash_helper_imp<_Type,
Eric Fiselier698a97b2017-01-21 00:02:12 +00001871 typename enable_if<__all<__has_enabled_hash<_Keys>::value...>::value>::type
1872>;
1873#else
1874template <class _Type, class ...>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001875using __enable_hash_helper _LIBCPP_NODEBUG_TYPE = _Type;
Eric Fiselier698a97b2017-01-21 00:02:12 +00001876#endif
1877
1878#endif // !_LIBCPP_CXX03_LANG
1879
Howard Hinnantc51e1022010-05-11 19:42:16 +00001880_LIBCPP_END_NAMESPACE_STD
1881
Kamlesh Kumarc1964592021-04-20 04:48:34 +05301882_LIBCPP_POP_MACROS
1883
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001884#endif // _LIBCPP_UTILITY