blob: ddfa27e22232cb000c42d94f9c702a876ca5d3fb [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- utility -----------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_UTILITY
12#define _LIBCPP_UTILITY
13
14/*
15 utility synopsis
16
Louis Dionneb5769a32018-07-05 16:16:03 +000017#include <initializer_list>
18
Howard Hinnantc51e1022010-05-11 19:42:16 +000019namespace std
20{
21
22template <class T>
23 void
24 swap(T& a, T& b);
25
26namespace rel_ops
27{
28 template<class T> bool operator!=(const T&, const T&);
29 template<class T> bool operator> (const T&, const T&);
30 template<class T> bool operator<=(const T&, const T&);
31 template<class T> bool operator>=(const T&, const T&);
32}
33
Howard Hinnantdbfd4b42011-05-27 15:04:19 +000034template<class T>
35void
36swap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value &&
37 is_nothrow_move_assignable<T>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000038
Howard Hinnantdbfd4b42011-05-27 15:04:19 +000039template <class T, size_t N>
40void
41swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)));
42
Marshall Clowfe9aa372013-07-15 20:46:11 +000043template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; // constexpr in C++14
44template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++14
Howard Hinnantdbfd4b42011-05-27 15:04:19 +000045
Marshall Clowfe9aa372013-07-15 20:46:11 +000046template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000047
48template <class T>
49 typename conditional
50 <
Howard Hinnanta9a897e2010-11-19 22:17:28 +000051 !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +000052 const T&,
53 T&&
54 >::type
Marshall Clowfe9aa372013-07-15 20:46:11 +000055 move_if_noexcept(T& x) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000056
Marshall Clow5d305742018-02-11 21:51:49 +000057template <class T> constexpr add_const_t<T>& as_const(T& t) noexcept; // C++17
Marshall Clow845efe42015-11-17 00:08:08 +000058template <class T> void as_const(const T&&) = delete; // C++17
59
Howard Hinnantc51e1022010-05-11 19:42:16 +000060template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
61
62template <class T1, class T2>
63struct pair
64{
65 typedef T1 first_type;
66 typedef T2 second_type;
67
68 T1 first;
69 T2 second;
70
71 pair(const pair&) = default;
Howard Hinnantdbfd4b42011-05-27 15:04:19 +000072 pair(pair&&) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +000073 constexpr pair();
Marshall Clowf00c56c2013-07-16 17:45:44 +000074 pair(const T1& x, const T2& y); // constexpr in C++14
75 template <class U, class V> pair(U&& x, V&& y); // constexpr in C++14
76 template <class U, class V> pair(const pair<U, V>& p); // constexpr in C++14
77 template <class U, class V> pair(pair<U, V>&& p); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000078 template <class... Args1, class... Args2>
79 pair(piecewise_construct_t, tuple<Args1...> first_args,
80 tuple<Args2...> second_args);
81
82 template <class U, class V> pair& operator=(const pair<U, V>& p);
Howard Hinnantdbfd4b42011-05-27 15:04:19 +000083 pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value &&
84 is_nothrow_move_assignable<T2>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000085 template <class U, class V> pair& operator=(pair<U, V>&& p);
86
Eric Fiselier6bfed252016-04-21 23:38:59 +000087 void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> &&
88 is_nothrow_swappable_v<T2>);
Howard Hinnantc51e1022010-05-11 19:42:16 +000089};
90
Marshall Clowf00c56c2013-07-16 17:45:44 +000091template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
92template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
93template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
94template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
95template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
96template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000097
Marshall Clowf00c56c2013-07-16 17:45:44 +000098template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14
Howard Hinnantdbfd4b42011-05-27 15:04:19 +000099template <class T1, class T2>
100void
101swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000102
103struct piecewise_construct_t { };
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000104inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000105
106template <class T> class tuple_size;
107template <size_t I, class T> class tuple_element;
108
Marshall Clowf50d66f2014-03-03 06:18:11 +0000109template <class T1, class T2> struct tuple_size<pair<T1, T2> >;
110template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >;
111template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000112
113template<size_t I, class T1, class T2>
Marshall Clowf50d66f2014-03-03 06:18:11 +0000114 typename tuple_element<I, pair<T1, T2> >::type&
115 get(pair<T1, T2>&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000116
117template<size_t I, class T1, class T2>
Marshall Clow36907512015-11-19 19:45:29 +0000118 const typename tuple_element<I, pair<T1, T2> >::type&
Marshall Clowf50d66f2014-03-03 06:18:11 +0000119 get(const pair<T1, T2>&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120
Howard Hinnant22e97242010-11-17 19:52:17 +0000121template<size_t I, class T1, class T2>
Marshall Clowf50d66f2014-03-03 06:18:11 +0000122 typename tuple_element<I, pair<T1, T2> >::type&&
123 get(pair<T1, T2>&&) noexcept; // constexpr in C++14
Howard Hinnant22e97242010-11-17 19:52:17 +0000124
Eric Fiselier6dea8092015-12-18 00:36:55 +0000125template<size_t I, class T1, class T2>
126 const typename tuple_element<I, pair<T1, T2> >::type&&
127 get(const pair<T1, T2>&&) noexcept; // constexpr in C++14
128
Marshall Clow15b02e02013-07-13 02:54:05 +0000129template<class T1, class T2>
Marshall Clowf50d66f2014-03-03 06:18:11 +0000130 constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000131
Eric Fiselier6dea8092015-12-18 00:36:55 +0000132template<class T1, class T2>
Marshall Clow36907512015-11-19 19:45:29 +0000133 constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000134
Eric Fiselier6dea8092015-12-18 00:36:55 +0000135template<class T1, class T2>
Marshall Clowf50d66f2014-03-03 06:18:11 +0000136 constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000137
Eric Fiselier6dea8092015-12-18 00:36:55 +0000138template<class T1, class T2>
139 constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14
140
141template<class T1, class T2>
142 constexpr T1& get(pair<T2, T1>&) noexcept; // C++14
143
144template<class T1, class T2>
145 constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14
146
147template<class T1, class T2>
148 constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14
149
150template<class T1, class T2>
151 constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14
152
Marshall Clow9a970d82013-07-01 16:26:55 +0000153// C++14
154
155template<class T, T... I>
156struct integer_sequence
157{
158 typedef T value_type;
159
160 static constexpr size_t size() noexcept;
161};
162
163template<size_t... I>
164 using index_sequence = integer_sequence<size_t, I...>;
165
166template<class T, T N>
167 using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
168template<size_t N>
169 using make_index_sequence = make_integer_sequence<size_t, N>;
170
171template<class... T>
172 using index_sequence_for = make_index_sequence<sizeof...(T)>;
173
Marshall Clowfa8ccca2016-06-19 19:29:52 +0000174template<class T, class U=T>
Marshall Clow867ca362013-07-08 20:54:40 +0000175 T exchange(T& obj, U&& new_value);
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +0000176
177// 20.2.7, in-place construction // C++17
Eric Fiselier99b81712016-11-17 19:24:04 +0000178struct in_place_t {
179 explicit in_place_t() = default;
180};
181inline constexpr in_place_t in_place{};
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +0000182template <class T>
Eric Fiselier99b81712016-11-17 19:24:04 +0000183 struct in_place_type_t {
184 explicit in_place_type_t() = default;
185 };
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +0000186template <class T>
Eric Fiselier99b81712016-11-17 19:24:04 +0000187 inline constexpr in_place_type_t<T> in_place_type{};
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +0000188template <size_t I>
Eric Fiselier99b81712016-11-17 19:24:04 +0000189 struct in_place_index_t {
190 explicit in_place_index_t() = default;
191 };
192template <size_t I>
193 inline constexpr in_place_index_t<I> in_place_index{};
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +0000194
Howard Hinnantc51e1022010-05-11 19:42:16 +0000195} // std
196
197*/
198
199#include <__config>
200#include <__tuple>
201#include <type_traits>
Ben Craig23254d22016-04-19 20:13:55 +0000202#include <initializer_list>
Eric Fiselier698a97b2017-01-21 00:02:12 +0000203#include <cstddef>
204#include <cstring>
205#include <cstdint>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000206#include <version>
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +0000207#include <__debug>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000208
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000209#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000210#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000211#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000212
213_LIBCPP_BEGIN_NAMESPACE_STD
214
215namespace rel_ops
216{
217
218template<class _Tp>
219inline _LIBCPP_INLINE_VISIBILITY
220bool
221operator!=(const _Tp& __x, const _Tp& __y)
222{
223 return !(__x == __y);
224}
225
226template<class _Tp>
227inline _LIBCPP_INLINE_VISIBILITY
228bool
229operator> (const _Tp& __x, const _Tp& __y)
230{
231 return __y < __x;
232}
233
234template<class _Tp>
235inline _LIBCPP_INLINE_VISIBILITY
236bool
237operator<=(const _Tp& __x, const _Tp& __y)
238{
239 return !(__y < __x);
240}
241
242template<class _Tp>
243inline _LIBCPP_INLINE_VISIBILITY
244bool
245operator>=(const _Tp& __x, const _Tp& __y)
246{
247 return !(__x < __y);
248}
249
250} // rel_ops
251
252// swap_ranges
253
Marshall Clowfd9a8572015-01-06 19:20:49 +0000254
Howard Hinnantc51e1022010-05-11 19:42:16 +0000255template <class _ForwardIterator1, class _ForwardIterator2>
256inline _LIBCPP_INLINE_VISIBILITY
257_ForwardIterator2
258swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
259{
Eric Fiseliera09a3b42014-10-27 19:28:20 +0000260 for(; __first1 != __last1; ++__first1, (void) ++__first2)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000261 swap(*__first1, *__first2);
262 return __first2;
263}
264
Eric Fiselier6bfed252016-04-21 23:38:59 +0000265// forward declared in <type_traits>
Howard Hinnantc834c512011-11-29 18:15:50 +0000266template<class _Tp, size_t _Np>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000267inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6bfed252016-04-21 23:38:59 +0000268typename enable_if<
269 __is_swappable<_Tp>::value
270>::type
Howard Hinnantc834c512011-11-29 18:15:50 +0000271swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000272{
Howard Hinnantc834c512011-11-29 18:15:50 +0000273 _VSTD::swap_ranges(__a, __a + _Np, __b);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000274}
275
276template <class _Tp>
Marshall Clowfe9aa372013-07-15 20:46:11 +0000277inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000278#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000279typename conditional
280<
Howard Hinnanta9a897e2010-11-19 22:17:28 +0000281 !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282 const _Tp&,
283 _Tp&&
284>::type
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000285#else // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000286const _Tp&
287#endif
Howard Hinnantdbfd4b42011-05-27 15:04:19 +0000288move_if_noexcept(_Tp& __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000290 return _VSTD::move(__x);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291}
292
Marshall Clow845efe42015-11-17 00:08:08 +0000293#if _LIBCPP_STD_VER > 14
294template <class _Tp> constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; }
295template <class _Tp> void as_const(const _Tp&&) = delete;
296#endif
297
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000298struct _LIBCPP_TEMPLATE_VIS piecewise_construct_t { };
Louis Dionne5e0eadd2018-08-01 02:08:59 +0000299#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Louis Dionne5254b372018-10-25 12:13:43 +0000300extern _LIBCPP_EXPORTED_FROM_ABI const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
Howard Hinnant7d7e9582012-04-03 21:09:48 +0000301#else
Marshall Clowbc084382018-01-02 18:57:47 +0000302/* _LIBCPP_INLINE_VAR */ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
Howard Hinnant7d7e9582012-04-03 21:09:48 +0000303#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000304
Eric Fiselierf9618bb2016-10-11 21:22:21 +0000305#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
306struct __non_trivially_copyable_base {
307 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
308 __non_trivially_copyable_base() _NOEXCEPT {}
309 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
310 __non_trivially_copyable_base(__non_trivially_copyable_base const&) _NOEXCEPT {}
311};
312#endif
Eric Fiseliere61db632016-07-25 04:32:07 +0000313
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314template <class _T1, class _T2>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000315struct _LIBCPP_TEMPLATE_VIS pair
Eric Fiselierf9618bb2016-10-11 21:22:21 +0000316#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
317: private __non_trivially_copyable_base
318#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000319{
320 typedef _T1 first_type;
321 typedef _T2 second_type;
322
323 _T1 first;
324 _T2 second;
325
Eric Fiselierf9618bb2016-10-11 21:22:21 +0000326#if !defined(_LIBCPP_CXX03_LANG)
Eric Fiselier08f7fe82016-07-18 01:58:37 +0000327 pair(pair const&) = default;
328 pair(pair&&) = default;
329#else
330 // Use the implicitly declared copy constructor in C++03
Marshall Clowf00c56c2013-07-16 17:45:44 +0000331#endif
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000332
Eric Fiseliere61db632016-07-25 04:32:07 +0000333#ifdef _LIBCPP_CXX03_LANG
334 _LIBCPP_INLINE_VISIBILITY
335 pair() : first(), second() {}
Eric Fiselier737a16d2016-07-25 02:36:42 +0000336
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000337 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere61db632016-07-25 04:32:07 +0000338 pair(_T1 const& __t1, _T2 const& __t2) : first(__t1), second(__t2) {}
339
340 template <class _U1, class _U2>
341 _LIBCPP_INLINE_VISIBILITY
342 pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
343
344 _LIBCPP_INLINE_VISIBILITY
345 pair& operator=(pair const& __p) {
346 first = __p.first;
347 second = __p.second;
348 return *this;
349 }
350#else
351 template <bool _Val>
352 using _EnableB = typename enable_if<_Val, bool>::type;
353
354 struct _CheckArgs {
355 template <class _U1, class _U2>
356 static constexpr bool __enable_default() {
357 return is_default_constructible<_U1>::value
358 && is_default_constructible<_U2>::value;
359 }
360
361 template <class _U1, class _U2>
362 static constexpr bool __enable_explicit() {
363 return is_constructible<first_type, _U1>::value
364 && is_constructible<second_type, _U2>::value
365 && (!is_convertible<_U1, first_type>::value
366 || !is_convertible<_U2, second_type>::value);
367 }
368
369 template <class _U1, class _U2>
370 static constexpr bool __enable_implicit() {
371 return is_constructible<first_type, _U1>::value
372 && is_constructible<second_type, _U2>::value
373 && is_convertible<_U1, first_type>::value
374 && is_convertible<_U2, second_type>::value;
375 }
376 };
377
378 template <bool _MaybeEnable>
379 using _CheckArgsDep = typename conditional<
380 _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type;
381
382 struct _CheckTupleLikeConstructor {
383 template <class _Tuple>
384 static constexpr bool __enable_implicit() {
385 return __tuple_convertible<_Tuple, pair>::value;
386 }
387
388 template <class _Tuple>
389 static constexpr bool __enable_explicit() {
390 return __tuple_constructible<_Tuple, pair>::value
391 && !__tuple_convertible<_Tuple, pair>::value;
392 }
393
394 template <class _Tuple>
395 static constexpr bool __enable_assign() {
396 return __tuple_assignable<_Tuple, pair>::value;
397 }
398 };
399
400 template <class _Tuple>
401 using _CheckTLC = typename conditional<
402 __tuple_like_with_size<_Tuple, 2>::value
403 && !is_same<typename decay<_Tuple>::type, pair>::value,
404 _CheckTupleLikeConstructor,
405 __check_tuple_constructor_fail
406 >::type;
407
408 template<bool _Dummy = true, _EnableB<
409 _CheckArgsDep<_Dummy>::template __enable_default<_T1, _T2>()
410 > = false>
411 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
412 pair() : first(), second() {}
413
414 template <bool _Dummy = true, _EnableB<
415 _CheckArgsDep<_Dummy>::template __enable_explicit<_T1 const&, _T2 const&>()
416 > = false>
417 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
418 explicit pair(_T1 const& __t1, _T2 const& __t2)
419 : first(__t1), second(__t2) {}
420
421 template<bool _Dummy = true, _EnableB<
422 _CheckArgsDep<_Dummy>::template __enable_implicit<_T1 const&, _T2 const&>()
423 > = false>
424 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
425 pair(_T1 const& __t1, _T2 const& __t2)
426 : first(__t1), second(__t2) {}
427
428 template<class _U1, class _U2, _EnableB<
429 _CheckArgs::template __enable_explicit<_U1, _U2>()
430 > = false>
431 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
432 explicit pair(_U1&& __u1, _U2&& __u2)
433 : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
434
435 template<class _U1, class _U2, _EnableB<
436 _CheckArgs::template __enable_implicit<_U1, _U2>()
437 > = false>
438 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
439 pair(_U1&& __u1, _U2&& __u2)
440 : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
441
442 template<class _U1, class _U2, _EnableB<
443 _CheckArgs::template __enable_explicit<_U1 const&, _U2 const&>()
444 > = false>
445 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
446 explicit pair(pair<_U1, _U2> const& __p)
447 : first(__p.first), second(__p.second) {}
448
449 template<class _U1, class _U2, _EnableB<
450 _CheckArgs::template __enable_implicit<_U1 const&, _U2 const&>()
451 > = false>
452 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
453 pair(pair<_U1, _U2> const& __p)
454 : first(__p.first), second(__p.second) {}
455
456 template<class _U1, class _U2, _EnableB<
457 _CheckArgs::template __enable_explicit<_U1, _U2>()
458 > = false>
459 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
460 explicit pair(pair<_U1, _U2>&&__p)
461 : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
462
463 template<class _U1, class _U2, _EnableB<
464 _CheckArgs::template __enable_implicit<_U1, _U2>()
465 > = false>
466 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
467 pair(pair<_U1, _U2>&& __p)
468 : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
469
470 template<class _Tuple, _EnableB<
471 _CheckTLC<_Tuple>::template __enable_explicit<_Tuple>()
472 > = false>
473 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
474 explicit pair(_Tuple&& __p)
475 : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
476 second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {}
477
478 template<class _Tuple, _EnableB<
479 _CheckTLC<_Tuple>::template __enable_implicit<_Tuple>()
480 > = false>
481 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
482 pair(_Tuple&& __p)
483 : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
484 second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {}
485
486 template <class... _Args1, class... _Args2>
487 _LIBCPP_INLINE_VISIBILITY
488 pair(piecewise_construct_t __pc,
489 tuple<_Args1...> __first_args, tuple<_Args2...> __second_args)
490 : pair(__pc, __first_args, __second_args,
491 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
492 typename __make_tuple_indices<sizeof...(_Args2) >::type()) {}
493
494 _LIBCPP_INLINE_VISIBILITY
495 pair& operator=(typename conditional<
496 is_copy_assignable<first_type>::value &&
497 is_copy_assignable<second_type>::value,
498 pair, __nat>::type const& __p)
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000499 _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value &&
500 is_nothrow_copy_assignable<second_type>::value)
Howard Hinnantdbfd4b42011-05-27 15:04:19 +0000501 {
502 first = __p.first;
503 second = __p.second;
504 return *this;
505 }
506
Eric Fiselier737a16d2016-07-25 02:36:42 +0000507 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere61db632016-07-25 04:32:07 +0000508 pair& operator=(typename conditional<
509 is_move_assignable<first_type>::value &&
510 is_move_assignable<second_type>::value,
511 pair, __nat>::type&& __p)
Eric Fiselier737a16d2016-07-25 02:36:42 +0000512 _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value &&
513 is_nothrow_move_assignable<second_type>::value)
514 {
515 first = _VSTD::forward<first_type>(__p.first);
516 second = _VSTD::forward<second_type>(__p.second);
517 return *this;
518 }
Eric Fiseliere61db632016-07-25 04:32:07 +0000519
520 template <class _Tuple, _EnableB<
Eric Fiselier9e0256b2016-08-29 01:43:41 +0000521 _CheckTLC<_Tuple>::template __enable_assign<_Tuple>()
Eric Fiseliere61db632016-07-25 04:32:07 +0000522 > = false>
523 _LIBCPP_INLINE_VISIBILITY
524 pair& operator=(_Tuple&& __p) {
525 first = _VSTD::get<0>(_VSTD::forward<_Tuple>(__p));
526 second = _VSTD::get<1>(_VSTD::forward<_Tuple>(__p));
527 return *this;
528 }
Eric Fiselier737a16d2016-07-25 02:36:42 +0000529#endif
530
Howard Hinnantdbfd4b42011-05-27 15:04:19 +0000531 _LIBCPP_INLINE_VISIBILITY
532 void
Howard Hinnant89ef1212011-05-27 19:08:18 +0000533 swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value &&
534 __is_nothrow_swappable<second_type>::value)
Howard Hinnantdbfd4b42011-05-27 15:04:19 +0000535 {
Marshall Clow8b9bd542015-09-22 17:50:11 +0000536 using _VSTD::swap;
537 swap(first, __p.first);
538 swap(second, __p.second);
Howard Hinnantdbfd4b42011-05-27 15:04:19 +0000539 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000540private:
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000541
Eric Fiseliere61db632016-07-25 04:32:07 +0000542#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000543 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
Howard Hinnantef5aced2011-01-13 20:05:05 +0000544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000545 pair(piecewise_construct_t,
546 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
547 __tuple_indices<_I1...>, __tuple_indices<_I2...>);
Eric Fiseliere61db632016-07-25 04:32:07 +0000548#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000549};
550
Eric Fiselier8df4ac62017-10-04 00:04:26 +0000551#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
552template<class _T1, class _T2>
553pair(_T1, _T2) -> pair<_T1, _T2>;
554#endif // _LIBCPP_HAS_NO_DEDUCTION_GUIDES
555
Howard Hinnantc51e1022010-05-11 19:42:16 +0000556template <class _T1, class _T2>
Marshall Clowf00c56c2013-07-16 17:45:44 +0000557inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000558bool
559operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
560{
561 return __x.first == __y.first && __x.second == __y.second;
562}
563
564template <class _T1, class _T2>
Marshall Clowf00c56c2013-07-16 17:45:44 +0000565inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000566bool
567operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
568{
569 return !(__x == __y);
570}
571
572template <class _T1, class _T2>
Marshall Clowf00c56c2013-07-16 17:45:44 +0000573inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000574bool
575operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
576{
577 return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);
578}
579
580template <class _T1, class _T2>
Marshall Clowf00c56c2013-07-16 17:45:44 +0000581inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000582bool
583operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
584{
585 return __y < __x;
586}
587
588template <class _T1, class _T2>
Marshall Clowf00c56c2013-07-16 17:45:44 +0000589inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590bool
591operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
592{
593 return !(__x < __y);
594}
595
596template <class _T1, class _T2>
Marshall Clowf00c56c2013-07-16 17:45:44 +0000597inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000598bool
599operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
600{
601 return !(__y < __x);
602}
603
604template <class _T1, class _T2>
605inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant44267242011-06-01 19:59:32 +0000606typename enable_if
607<
608 __is_swappable<_T1>::value &&
609 __is_swappable<_T2>::value,
610 void
611>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +0000612swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000613 _NOEXCEPT_((__is_nothrow_swappable<_T1>::value &&
614 __is_nothrow_swappable<_T2>::value))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000615{
Howard Hinnantdbfd4b42011-05-27 15:04:19 +0000616 __x.swap(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617}
618
Louis Dionnedb1892a2018-12-03 14:03:27 +0000619template <class _Tp>
620struct __unwrap_reference { typedef _Tp type; };
621
622template <class _Tp>
623struct __unwrap_reference<reference_wrapper<_Tp> > { typedef _Tp& type; };
624
625#if _LIBCPP_STD_VER > 17
626template <class _Tp>
627struct unwrap_reference : __unwrap_reference<_Tp> { };
628
629template <class _Tp>
630struct unwrap_ref_decay : unwrap_reference<typename decay<_Tp>::type> { };
631#endif // > C++17
632
633template <class _Tp>
634struct __unwrap_ref_decay
635#if _LIBCPP_STD_VER > 17
636 : unwrap_ref_decay<_Tp>
637#else
638 : __unwrap_reference<typename decay<_Tp>::type>
639#endif
640{ };
641
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000642#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000643
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644template <class _T1, class _T2>
Marshall Clowf00c56c2013-07-16 17:45:44 +0000645inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +0000646pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000647make_pair(_T1&& __t1, _T2&& __t2)
648{
Louis Dionnedb1892a2018-12-03 14:03:27 +0000649 return pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000650 (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000651}
652
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000653#else // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000654
655template <class _T1, class _T2>
656inline _LIBCPP_INLINE_VISIBILITY
657pair<_T1,_T2>
658make_pair(_T1 __x, _T2 __y)
659{
660 return pair<_T1, _T2>(__x, __y);
661}
662
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000663#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000664
Howard Hinnantc51e1022010-05-11 19:42:16 +0000665template <class _T1, class _T2>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000666 class _LIBCPP_TEMPLATE_VIS tuple_size<pair<_T1, _T2> >
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000667 : public integral_constant<size_t, 2> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000668
Marshall Clow185577f2017-06-12 16:13:17 +0000669template <size_t _Ip, class _T1, class _T2>
670class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> >
671{
672 static_assert(_Ip < 2, "Index out of bounds in std::tuple_element<std::pair<T1, T2>>");
673};
674
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675template <class _T1, class _T2>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000676class _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000677{
678public:
679 typedef _T1 type;
680};
681
682template <class _T1, class _T2>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000683class _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000684{
685public:
686 typedef _T2 type;
687};
688
Howard Hinnantc51e1022010-05-11 19:42:16 +0000689template <size_t _Ip> struct __get_pair;
690
691template <>
692struct __get_pair<0>
693{
694 template <class _T1, class _T2>
695 static
Marshall Clow0abb1042013-07-17 18:25:36 +0000696 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000697 _T1&
Howard Hinnant89ef1212011-05-27 19:08:18 +0000698 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000699
700 template <class _T1, class _T2>
701 static
Marshall Clow0abb1042013-07-17 18:25:36 +0000702 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000703 const _T1&
Howard Hinnant89ef1212011-05-27 19:08:18 +0000704 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnant22e97242010-11-17 19:52:17 +0000705
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000706#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000707 template <class _T1, class _T2>
708 static
Marshall Clow0abb1042013-07-17 18:25:36 +0000709 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant22e97242010-11-17 19:52:17 +0000710 _T1&&
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000711 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);}
Howard Hinnant22e97242010-11-17 19:52:17 +0000712
Eric Fiselier6dea8092015-12-18 00:36:55 +0000713 template <class _T1, class _T2>
714 static
715 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
716 const _T1&&
717 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);}
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000718#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000719};
720
721template <>
722struct __get_pair<1>
723{
724 template <class _T1, class _T2>
725 static
Marshall Clow0abb1042013-07-17 18:25:36 +0000726 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000727 _T2&
Howard Hinnant89ef1212011-05-27 19:08:18 +0000728 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000729
730 template <class _T1, class _T2>
731 static
Marshall Clow0abb1042013-07-17 18:25:36 +0000732 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000733 const _T2&
Howard Hinnant89ef1212011-05-27 19:08:18 +0000734 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnant22e97242010-11-17 19:52:17 +0000735
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000736#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000737 template <class _T1, class _T2>
738 static
Marshall Clow0abb1042013-07-17 18:25:36 +0000739 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant22e97242010-11-17 19:52:17 +0000740 _T2&&
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000741 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);}
Howard Hinnant22e97242010-11-17 19:52:17 +0000742
Eric Fiselier6dea8092015-12-18 00:36:55 +0000743 template <class _T1, class _T2>
744 static
745 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
746 const _T2&&
747 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);}
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000748#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000749};
750
751template <size_t _Ip, class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000752inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000753typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnant89ef1212011-05-27 19:08:18 +0000754get(pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000755{
756 return __get_pair<_Ip>::get(__p);
757}
758
759template <size_t _Ip, class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000760inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000761const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnant89ef1212011-05-27 19:08:18 +0000762get(const pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763{
764 return __get_pair<_Ip>::get(__p);
765}
766
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000767#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000768template <size_t _Ip, class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000769inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant22e97242010-11-17 19:52:17 +0000770typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
Howard Hinnant89ef1212011-05-27 19:08:18 +0000771get(pair<_T1, _T2>&& __p) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +0000772{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000773 return __get_pair<_Ip>::get(_VSTD::move(__p));
Howard Hinnant22e97242010-11-17 19:52:17 +0000774}
775
Eric Fiselier6dea8092015-12-18 00:36:55 +0000776template <size_t _Ip, class _T1, class _T2>
777inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
778const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
779get(const pair<_T1, _T2>&& __p) _NOEXCEPT
780{
781 return __get_pair<_Ip>::get(_VSTD::move(__p));
782}
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000783#endif // _LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000784
Marshall Clow9a970d82013-07-01 16:26:55 +0000785#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +0000786template <class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000787inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow15b02e02013-07-13 02:54:05 +0000788constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT
789{
Marshall Clowf00c56c2013-07-16 17:45:44 +0000790 return __get_pair<0>::get(__p);
Marshall Clow15b02e02013-07-13 02:54:05 +0000791}
792
793template <class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000794inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow15b02e02013-07-13 02:54:05 +0000795constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT
796{
Marshall Clowf00c56c2013-07-16 17:45:44 +0000797 return __get_pair<0>::get(__p);
Marshall Clow15b02e02013-07-13 02:54:05 +0000798}
799
800template <class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000801inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow15b02e02013-07-13 02:54:05 +0000802constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT
803{
Marshall Clowf00c56c2013-07-16 17:45:44 +0000804 return __get_pair<0>::get(_VSTD::move(__p));
Marshall Clow15b02e02013-07-13 02:54:05 +0000805}
806
807template <class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000808inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6dea8092015-12-18 00:36:55 +0000809constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT
810{
811 return __get_pair<0>::get(_VSTD::move(__p));
812}
813
814template <class _T1, class _T2>
815inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow15b02e02013-07-13 02:54:05 +0000816constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT
817{
Marshall Clowf00c56c2013-07-16 17:45:44 +0000818 return __get_pair<1>::get(__p);
Marshall Clow15b02e02013-07-13 02:54:05 +0000819}
820
821template <class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000822inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow15b02e02013-07-13 02:54:05 +0000823constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT
824{
Marshall Clowf00c56c2013-07-16 17:45:44 +0000825 return __get_pair<1>::get(__p);
Marshall Clow15b02e02013-07-13 02:54:05 +0000826}
827
828template <class _T1, class _T2>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000829inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow15b02e02013-07-13 02:54:05 +0000830constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT
831{
Marshall Clowf00c56c2013-07-16 17:45:44 +0000832 return __get_pair<1>::get(_VSTD::move(__p));
Marshall Clow15b02e02013-07-13 02:54:05 +0000833}
834
Eric Fiselier6dea8092015-12-18 00:36:55 +0000835template <class _T1, class _T2>
836inline _LIBCPP_INLINE_VISIBILITY
837constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT
838{
839 return __get_pair<1>::get(_VSTD::move(__p));
840}
841
Marshall Clow15b02e02013-07-13 02:54:05 +0000842#endif
843
844#if _LIBCPP_STD_VER > 11
Marshall Clow9a970d82013-07-01 16:26:55 +0000845
846template<class _Tp, _Tp... _Ip>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000847struct _LIBCPP_TEMPLATE_VIS integer_sequence
Marshall Clow9a970d82013-07-01 16:26:55 +0000848{
849 typedef _Tp value_type;
850 static_assert( is_integral<_Tp>::value,
851 "std::integer_sequence can only be instantiated with an integral type" );
852 static
853 _LIBCPP_INLINE_VISIBILITY
854 constexpr
855 size_t
856 size() noexcept { return sizeof...(_Ip); }
857};
858
859template<size_t... _Ip>
860 using index_sequence = integer_sequence<size_t, _Ip...>;
861
Eric Fiselierd5746922015-12-09 22:03:06 +0000862#if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
863
864template <class _Tp, _Tp _Ep>
Eric Fiselier2079cc72016-06-30 22:34:43 +0000865using __make_integer_sequence = __make_integer_seq<integer_sequence, _Tp, _Ep>;
Eric Fiselierd5746922015-12-09 22:03:06 +0000866
867#else
868
Marshall Clow2128ea02013-07-03 19:20:30 +0000869template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked =
Eric Fiselier2079cc72016-06-30 22:34:43 +0000870 typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>;
Marshall Clow9a970d82013-07-01 16:26:55 +0000871
872template <class _Tp, _Tp _Ep>
Eric Fiselier2079cc72016-06-30 22:34:43 +0000873struct __make_integer_sequence_checked
Marshall Clow9a970d82013-07-01 16:26:55 +0000874{
875 static_assert(is_integral<_Tp>::value,
876 "std::make_integer_sequence can only be instantiated with an integral type" );
Eric Fiselierd5746922015-12-09 22:03:06 +0000877 static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length");
Eric Fiselier9b7456e2015-12-16 00:35:45 +0000878 // Workaround GCC bug by preventing bad installations when 0 <= _Ep
879 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929
880 typedef __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type;
Marshall Clow9a970d82013-07-01 16:26:55 +0000881};
882
Eric Fiselier2079cc72016-06-30 22:34:43 +0000883template <class _Tp, _Tp _Ep>
884using __make_integer_sequence = typename __make_integer_sequence_checked<_Tp, _Ep>::type;
885
Eric Fiselierd5746922015-12-09 22:03:06 +0000886#endif
887
Marshall Clow9a970d82013-07-01 16:26:55 +0000888template<class _Tp, _Tp _Np>
Eric Fiselier2079cc72016-06-30 22:34:43 +0000889 using make_integer_sequence = __make_integer_sequence<_Tp, _Np>;
Marshall Clow9a970d82013-07-01 16:26:55 +0000890
891template<size_t _Np>
892 using make_index_sequence = make_integer_sequence<size_t, _Np>;
893
894template<class... _Tp>
895 using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;
Marshall Clowfa8ccca2016-06-19 19:29:52 +0000896
Marshall Clow9a970d82013-07-01 16:26:55 +0000897#endif // _LIBCPP_STD_VER > 11
898
Marshall Clow867ca362013-07-08 20:54:40 +0000899#if _LIBCPP_STD_VER > 11
900template<class _T1, class _T2 = _T1>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000901inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clow867ca362013-07-08 20:54:40 +0000902_T1 exchange(_T1& __obj, _T2 && __new_value)
903{
Howard Hinnantecc7ba92013-07-08 21:06:38 +0000904 _T1 __old_value = _VSTD::move(__obj);
905 __obj = _VSTD::forward<_T2>(__new_value);
906 return __old_value;
Marshall Clowfa8ccca2016-06-19 19:29:52 +0000907}
Marshall Clow867ca362013-07-08 20:54:40 +0000908#endif // _LIBCPP_STD_VER > 11
909
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +0000910#if _LIBCPP_STD_VER > 14
911
Eric Fiselier99b81712016-11-17 19:24:04 +0000912struct _LIBCPP_TYPE_VIS in_place_t {
913 explicit in_place_t() = default;
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +0000914};
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000915_LIBCPP_INLINE_VAR constexpr in_place_t in_place{};
Eric Fiselieraea4e192016-10-16 02:51:50 +0000916
917template <class _Tp>
Eric Fiselier2a1b4d92017-04-20 01:45:15 +0000918struct _LIBCPP_TEMPLATE_VIS in_place_type_t {
Eric Fiselier99b81712016-11-17 19:24:04 +0000919 explicit in_place_type_t() = default;
920};
921template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000922_LIBCPP_INLINE_VAR constexpr in_place_type_t<_Tp> in_place_type{};
Eric Fiselieraea4e192016-10-16 02:51:50 +0000923
Eric Fiselier99b81712016-11-17 19:24:04 +0000924template <size_t _Idx>
925struct _LIBCPP_TYPE_VIS in_place_index_t {
926 explicit in_place_index_t() = default;
927};
928template <size_t _Idx>
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000929_LIBCPP_INLINE_VAR constexpr in_place_index_t<_Idx> in_place_index{};
Eric Fiselier99b81712016-11-17 19:24:04 +0000930
931template <class _Tp> struct __is_inplace_type_imp : false_type {};
932template <class _Tp> struct __is_inplace_type_imp<in_place_type_t<_Tp>> : true_type {};
Eric Fiselieraea4e192016-10-16 02:51:50 +0000933
934template <class _Tp>
Eric Fiselier99b81712016-11-17 19:24:04 +0000935using __is_inplace_type = __is_inplace_type_imp<__uncvref_t<_Tp>>;
Eric Fiselier7e0c55e2016-07-24 07:42:13 +0000936
Michael Parka9c61fc2017-06-14 05:51:18 +0000937template <class _Tp> struct __is_inplace_index_imp : false_type {};
938template <size_t _Idx> struct __is_inplace_index_imp<in_place_index_t<_Idx>> : true_type {};
939
940template <class _Tp>
941using __is_inplace_index = __is_inplace_index_imp<__uncvref_t<_Tp>>;
942
Eric Fiseliera8a4f6a2016-07-23 22:19:19 +0000943#endif // _LIBCPP_STD_VER > 14
944
Eric Fiselier698a97b2017-01-21 00:02:12 +0000945template <class _Arg, class _Result>
946struct _LIBCPP_TEMPLATE_VIS unary_function
947{
948 typedef _Arg argument_type;
949 typedef _Result result_type;
950};
951
952template <class _Size>
953inline _LIBCPP_INLINE_VISIBILITY
954_Size
955__loadword(const void* __p)
956{
957 _Size __r;
958 std::memcpy(&__r, __p, sizeof(__r));
959 return __r;
960}
961
962// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
963// is 64 bits. This is because cityhash64 uses 64bit x 64bit
964// multiplication, which can be very slow on 32-bit systems.
965template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
966struct __murmur2_or_cityhash;
967
968template <class _Size>
969struct __murmur2_or_cityhash<_Size, 32>
970{
Eric Fiselier3308e842017-02-08 00:10:10 +0000971 inline _Size operator()(const void* __key, _Size __len)
972 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK;
Eric Fiselier698a97b2017-01-21 00:02:12 +0000973};
974
975// murmur2
976template <class _Size>
977_Size
Eric Fiselier3308e842017-02-08 00:10:10 +0000978__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
Eric Fiselier698a97b2017-01-21 00:02:12 +0000979{
980 const _Size __m = 0x5bd1e995;
981 const _Size __r = 24;
982 _Size __h = __len;
983 const unsigned char* __data = static_cast<const unsigned char*>(__key);
984 for (; __len >= 4; __data += 4, __len -= 4)
985 {
986 _Size __k = __loadword<_Size>(__data);
987 __k *= __m;
988 __k ^= __k >> __r;
989 __k *= __m;
990 __h *= __m;
991 __h ^= __k;
992 }
993 switch (__len)
994 {
995 case 3:
996 __h ^= __data[2] << 16;
Fangrui Songcb135b32018-11-07 23:51:13 +0000997 _LIBCPP_FALLTHROUGH();
Eric Fiselier698a97b2017-01-21 00:02:12 +0000998 case 2:
999 __h ^= __data[1] << 8;
Fangrui Songcb135b32018-11-07 23:51:13 +00001000 _LIBCPP_FALLTHROUGH();
Eric Fiselier698a97b2017-01-21 00:02:12 +00001001 case 1:
1002 __h ^= __data[0];
1003 __h *= __m;
1004 }
1005 __h ^= __h >> 13;
1006 __h *= __m;
1007 __h ^= __h >> 15;
1008 return __h;
1009}
1010
1011template <class _Size>
1012struct __murmur2_or_cityhash<_Size, 64>
1013{
Eric Fiselier3308e842017-02-08 00:10:10 +00001014 inline _Size operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK;
Eric Fiselier698a97b2017-01-21 00:02:12 +00001015
1016 private:
1017 // Some primes between 2^63 and 2^64.
1018 static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
1019 static const _Size __k1 = 0xb492b66fbe98f273ULL;
1020 static const _Size __k2 = 0x9ae16a3b2f90404fULL;
1021 static const _Size __k3 = 0xc949d7c7509e6557ULL;
1022
1023 static _Size __rotate(_Size __val, int __shift) {
1024 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
1025 }
1026
1027 static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
1028 return (__val >> __shift) | (__val << (64 - __shift));
1029 }
1030
1031 static _Size __shift_mix(_Size __val) {
1032 return __val ^ (__val >> 47);
1033 }
1034
Eric Fiselier3308e842017-02-08 00:10:10 +00001035 static _Size __hash_len_16(_Size __u, _Size __v)
1036 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1037 {
Eric Fiselier698a97b2017-01-21 00:02:12 +00001038 const _Size __mul = 0x9ddfea08eb382d69ULL;
1039 _Size __a = (__u ^ __v) * __mul;
1040 __a ^= (__a >> 47);
1041 _Size __b = (__v ^ __a) * __mul;
1042 __b ^= (__b >> 47);
1043 __b *= __mul;
1044 return __b;
1045 }
1046
Eric Fiselier3308e842017-02-08 00:10:10 +00001047 static _Size __hash_len_0_to_16(const char* __s, _Size __len)
1048 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1049 {
Eric Fiselier698a97b2017-01-21 00:02:12 +00001050 if (__len > 8) {
1051 const _Size __a = __loadword<_Size>(__s);
1052 const _Size __b = __loadword<_Size>(__s + __len - 8);
1053 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
1054 }
1055 if (__len >= 4) {
1056 const uint32_t __a = __loadword<uint32_t>(__s);
1057 const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
1058 return __hash_len_16(__len + (__a << 3), __b);
1059 }
1060 if (__len > 0) {
1061 const unsigned char __a = __s[0];
1062 const unsigned char __b = __s[__len >> 1];
1063 const unsigned char __c = __s[__len - 1];
1064 const uint32_t __y = static_cast<uint32_t>(__a) +
1065 (static_cast<uint32_t>(__b) << 8);
1066 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
1067 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
1068 }
1069 return __k2;
1070 }
1071
Eric Fiselier3308e842017-02-08 00:10:10 +00001072 static _Size __hash_len_17_to_32(const char *__s, _Size __len)
1073 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1074 {
Eric Fiselier698a97b2017-01-21 00:02:12 +00001075 const _Size __a = __loadword<_Size>(__s) * __k1;
1076 const _Size __b = __loadword<_Size>(__s + 8);
1077 const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
1078 const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
1079 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
1080 __a + __rotate(__b ^ __k3, 20) - __c + __len);
1081 }
1082
1083 // Return a 16-byte hash for 48 bytes. Quick and dirty.
1084 // Callers do best to use "random-looking" values for a and b.
1085 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
Eric Fiselier3308e842017-02-08 00:10:10 +00001086 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b)
1087 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1088 {
Eric Fiselier698a97b2017-01-21 00:02:12 +00001089 __a += __w;
1090 __b = __rotate(__b + __a + __z, 21);
1091 const _Size __c = __a;
1092 __a += __x;
1093 __a += __y;
1094 __b += __rotate(__a, 44);
1095 return pair<_Size, _Size>(__a + __z, __b + __c);
1096 }
1097
1098 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
1099 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
Eric Fiselier3308e842017-02-08 00:10:10 +00001100 const char* __s, _Size __a, _Size __b)
1101 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1102 {
Eric Fiselier698a97b2017-01-21 00:02:12 +00001103 return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
1104 __loadword<_Size>(__s + 8),
1105 __loadword<_Size>(__s + 16),
1106 __loadword<_Size>(__s + 24),
1107 __a,
1108 __b);
1109 }
1110
1111 // Return an 8-byte hash for 33 to 64 bytes.
Eric Fiselier3308e842017-02-08 00:10:10 +00001112 static _Size __hash_len_33_to_64(const char *__s, size_t __len)
1113 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1114 {
Eric Fiselier698a97b2017-01-21 00:02:12 +00001115 _Size __z = __loadword<_Size>(__s + 24);
1116 _Size __a = __loadword<_Size>(__s) +
1117 (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
1118 _Size __b = __rotate(__a + __z, 52);
1119 _Size __c = __rotate(__a, 37);
1120 __a += __loadword<_Size>(__s + 8);
1121 __c += __rotate(__a, 7);
1122 __a += __loadword<_Size>(__s + 16);
1123 _Size __vf = __a + __z;
1124 _Size __vs = __b + __rotate(__a, 31) + __c;
1125 __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
1126 __z += __loadword<_Size>(__s + __len - 8);
1127 __b = __rotate(__a + __z, 52);
1128 __c = __rotate(__a, 37);
1129 __a += __loadword<_Size>(__s + __len - 24);
1130 __c += __rotate(__a, 7);
1131 __a += __loadword<_Size>(__s + __len - 16);
1132 _Size __wf = __a + __z;
1133 _Size __ws = __b + __rotate(__a, 31) + __c;
1134 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
1135 return __shift_mix(__r * __k0 + __vs) * __k2;
1136 }
1137};
1138
1139// cityhash64
1140template <class _Size>
1141_Size
Eric Fiselier3308e842017-02-08 00:10:10 +00001142__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001143{
1144 const char* __s = static_cast<const char*>(__key);
1145 if (__len <= 32) {
1146 if (__len <= 16) {
1147 return __hash_len_0_to_16(__s, __len);
1148 } else {
1149 return __hash_len_17_to_32(__s, __len);
1150 }
1151 } else if (__len <= 64) {
1152 return __hash_len_33_to_64(__s, __len);
1153 }
1154
1155 // For strings over 64 bytes we hash the end first, and then as we
1156 // loop we keep 56 bytes of state: v, w, x, y, and z.
1157 _Size __x = __loadword<_Size>(__s + __len - 40);
1158 _Size __y = __loadword<_Size>(__s + __len - 16) +
1159 __loadword<_Size>(__s + __len - 56);
1160 _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
1161 __loadword<_Size>(__s + __len - 24));
1162 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
1163 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
1164 __x = __x * __k1 + __loadword<_Size>(__s);
1165
1166 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
1167 __len = (__len - 1) & ~static_cast<_Size>(63);
1168 do {
1169 __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
1170 __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
1171 __x ^= __w.second;
1172 __y += __v.first + __loadword<_Size>(__s + 40);
1173 __z = __rotate(__z + __w.first, 33) * __k1;
1174 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
1175 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
1176 __y + __loadword<_Size>(__s + 16));
1177 std::swap(__z, __x);
1178 __s += 64;
1179 __len -= 64;
1180 } while (__len != 0);
1181 return __hash_len_16(
1182 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
1183 __hash_len_16(__v.second, __w.second) + __x);
1184}
1185
1186template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
1187struct __scalar_hash;
1188
1189template <class _Tp>
1190struct __scalar_hash<_Tp, 0>
1191 : public unary_function<_Tp, size_t>
1192{
1193 _LIBCPP_INLINE_VISIBILITY
1194 size_t operator()(_Tp __v) const _NOEXCEPT
1195 {
1196 union
1197 {
1198 _Tp __t;
1199 size_t __a;
1200 } __u;
1201 __u.__a = 0;
1202 __u.__t = __v;
1203 return __u.__a;
1204 }
1205};
1206
1207template <class _Tp>
1208struct __scalar_hash<_Tp, 1>
1209 : public unary_function<_Tp, size_t>
1210{
1211 _LIBCPP_INLINE_VISIBILITY
1212 size_t operator()(_Tp __v) const _NOEXCEPT
1213 {
1214 union
1215 {
1216 _Tp __t;
1217 size_t __a;
1218 } __u;
1219 __u.__t = __v;
1220 return __u.__a;
1221 }
1222};
1223
1224template <class _Tp>
1225struct __scalar_hash<_Tp, 2>
1226 : public unary_function<_Tp, size_t>
1227{
1228 _LIBCPP_INLINE_VISIBILITY
1229 size_t operator()(_Tp __v) const _NOEXCEPT
1230 {
1231 union
1232 {
1233 _Tp __t;
1234 struct
1235 {
1236 size_t __a;
1237 size_t __b;
1238 } __s;
1239 } __u;
1240 __u.__t = __v;
1241 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
1242 }
1243};
1244
1245template <class _Tp>
1246struct __scalar_hash<_Tp, 3>
1247 : public unary_function<_Tp, size_t>
1248{
1249 _LIBCPP_INLINE_VISIBILITY
1250 size_t operator()(_Tp __v) const _NOEXCEPT
1251 {
1252 union
1253 {
1254 _Tp __t;
1255 struct
1256 {
1257 size_t __a;
1258 size_t __b;
1259 size_t __c;
1260 } __s;
1261 } __u;
1262 __u.__t = __v;
1263 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
1264 }
1265};
1266
1267template <class _Tp>
1268struct __scalar_hash<_Tp, 4>
1269 : public unary_function<_Tp, size_t>
1270{
1271 _LIBCPP_INLINE_VISIBILITY
1272 size_t operator()(_Tp __v) const _NOEXCEPT
1273 {
1274 union
1275 {
1276 _Tp __t;
1277 struct
1278 {
1279 size_t __a;
1280 size_t __b;
1281 size_t __c;
1282 size_t __d;
1283 } __s;
1284 } __u;
1285 __u.__t = __v;
1286 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
1287 }
1288};
1289
1290struct _PairT {
1291 size_t first;
1292 size_t second;
1293};
1294
1295_LIBCPP_INLINE_VISIBILITY
1296inline size_t __hash_combine(size_t __lhs, size_t __rhs) _NOEXCEPT {
1297 typedef __scalar_hash<_PairT> _HashT;
1298 const _PairT __p = {__lhs, __rhs};
1299 return _HashT()(__p);
1300}
1301
1302template<class _Tp>
1303struct _LIBCPP_TEMPLATE_VIS hash<_Tp*>
1304 : public unary_function<_Tp*, size_t>
1305{
1306 _LIBCPP_INLINE_VISIBILITY
1307 size_t operator()(_Tp* __v) const _NOEXCEPT
1308 {
1309 union
1310 {
1311 _Tp* __t;
1312 size_t __a;
1313 } __u;
1314 __u.__t = __v;
1315 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
1316 }
1317};
1318
1319
1320template <>
1321struct _LIBCPP_TEMPLATE_VIS hash<bool>
1322 : public unary_function<bool, size_t>
1323{
1324 _LIBCPP_INLINE_VISIBILITY
1325 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1326};
1327
1328template <>
1329struct _LIBCPP_TEMPLATE_VIS hash<char>
1330 : public unary_function<char, size_t>
1331{
1332 _LIBCPP_INLINE_VISIBILITY
1333 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1334};
1335
1336template <>
1337struct _LIBCPP_TEMPLATE_VIS hash<signed char>
1338 : public unary_function<signed char, size_t>
1339{
1340 _LIBCPP_INLINE_VISIBILITY
1341 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1342};
1343
1344template <>
1345struct _LIBCPP_TEMPLATE_VIS hash<unsigned char>
1346 : public unary_function<unsigned char, size_t>
1347{
1348 _LIBCPP_INLINE_VISIBILITY
1349 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1350};
1351
1352#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
1353
1354template <>
1355struct _LIBCPP_TEMPLATE_VIS hash<char16_t>
1356 : public unary_function<char16_t, size_t>
1357{
1358 _LIBCPP_INLINE_VISIBILITY
1359 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1360};
1361
1362template <>
1363struct _LIBCPP_TEMPLATE_VIS hash<char32_t>
1364 : public unary_function<char32_t, size_t>
1365{
1366 _LIBCPP_INLINE_VISIBILITY
1367 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1368};
1369
1370#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
1371
1372template <>
1373struct _LIBCPP_TEMPLATE_VIS hash<wchar_t>
1374 : public unary_function<wchar_t, size_t>
1375{
1376 _LIBCPP_INLINE_VISIBILITY
1377 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1378};
1379
1380template <>
1381struct _LIBCPP_TEMPLATE_VIS hash<short>
1382 : public unary_function<short, size_t>
1383{
1384 _LIBCPP_INLINE_VISIBILITY
1385 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1386};
1387
1388template <>
1389struct _LIBCPP_TEMPLATE_VIS hash<unsigned short>
1390 : public unary_function<unsigned short, size_t>
1391{
1392 _LIBCPP_INLINE_VISIBILITY
1393 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1394};
1395
1396template <>
1397struct _LIBCPP_TEMPLATE_VIS hash<int>
1398 : public unary_function<int, size_t>
1399{
1400 _LIBCPP_INLINE_VISIBILITY
1401 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1402};
1403
1404template <>
1405struct _LIBCPP_TEMPLATE_VIS hash<unsigned int>
1406 : public unary_function<unsigned int, size_t>
1407{
1408 _LIBCPP_INLINE_VISIBILITY
1409 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1410};
1411
1412template <>
1413struct _LIBCPP_TEMPLATE_VIS hash<long>
1414 : public unary_function<long, size_t>
1415{
1416 _LIBCPP_INLINE_VISIBILITY
1417 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1418};
1419
1420template <>
1421struct _LIBCPP_TEMPLATE_VIS hash<unsigned long>
1422 : public unary_function<unsigned long, size_t>
1423{
1424 _LIBCPP_INLINE_VISIBILITY
1425 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1426};
1427
1428template <>
1429struct _LIBCPP_TEMPLATE_VIS hash<long long>
1430 : public __scalar_hash<long long>
1431{
1432};
1433
1434template <>
1435struct _LIBCPP_TEMPLATE_VIS hash<unsigned long long>
1436 : public __scalar_hash<unsigned long long>
1437{
1438};
1439
1440#ifndef _LIBCPP_HAS_NO_INT128
1441
1442template <>
1443struct _LIBCPP_TEMPLATE_VIS hash<__int128_t>
1444 : public __scalar_hash<__int128_t>
1445{
1446};
1447
1448template <>
1449struct _LIBCPP_TEMPLATE_VIS hash<__uint128_t>
1450 : public __scalar_hash<__uint128_t>
1451{
1452};
1453
1454#endif
1455
1456template <>
1457struct _LIBCPP_TEMPLATE_VIS hash<float>
1458 : public __scalar_hash<float>
1459{
1460 _LIBCPP_INLINE_VISIBILITY
1461 size_t operator()(float __v) const _NOEXCEPT
1462 {
1463 // -0.0 and 0.0 should return same hash
Eric Fiselierb41db9a2018-10-01 01:59:37 +00001464 if (__v == 0.0)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001465 return 0;
1466 return __scalar_hash<float>::operator()(__v);
1467 }
1468};
1469
1470template <>
1471struct _LIBCPP_TEMPLATE_VIS hash<double>
1472 : public __scalar_hash<double>
1473{
1474 _LIBCPP_INLINE_VISIBILITY
1475 size_t operator()(double __v) const _NOEXCEPT
1476 {
1477 // -0.0 and 0.0 should return same hash
Eric Fiselierb41db9a2018-10-01 01:59:37 +00001478 if (__v == 0.0)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001479 return 0;
1480 return __scalar_hash<double>::operator()(__v);
1481 }
1482};
1483
1484template <>
1485struct _LIBCPP_TEMPLATE_VIS hash<long double>
1486 : public __scalar_hash<long double>
1487{
1488 _LIBCPP_INLINE_VISIBILITY
1489 size_t operator()(long double __v) const _NOEXCEPT
1490 {
1491 // -0.0 and 0.0 should return same hash
Eric Fiselierb41db9a2018-10-01 01:59:37 +00001492 if (__v == 0.0)
Eric Fiselier698a97b2017-01-21 00:02:12 +00001493 return 0;
1494#if defined(__i386__)
1495 // Zero out padding bits
1496 union
1497 {
1498 long double __t;
1499 struct
1500 {
1501 size_t __a;
1502 size_t __b;
1503 size_t __c;
1504 size_t __d;
1505 } __s;
1506 } __u;
1507 __u.__s.__a = 0;
1508 __u.__s.__b = 0;
1509 __u.__s.__c = 0;
1510 __u.__s.__d = 0;
1511 __u.__t = __v;
1512 return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d;
1513#elif defined(__x86_64__)
1514 // Zero out padding bits
1515 union
1516 {
1517 long double __t;
1518 struct
1519 {
1520 size_t __a;
1521 size_t __b;
1522 } __s;
1523 } __u;
1524 __u.__s.__a = 0;
1525 __u.__s.__b = 0;
1526 __u.__t = __v;
1527 return __u.__s.__a ^ __u.__s.__b;
1528#else
1529 return __scalar_hash<long double>::operator()(__v);
1530#endif
1531 }
1532};
1533
1534#if _LIBCPP_STD_VER > 11
1535
1536template <class _Tp, bool = is_enum<_Tp>::value>
1537struct _LIBCPP_TEMPLATE_VIS __enum_hash
1538 : public unary_function<_Tp, size_t>
1539{
1540 _LIBCPP_INLINE_VISIBILITY
1541 size_t operator()(_Tp __v) const _NOEXCEPT
1542 {
1543 typedef typename underlying_type<_Tp>::type type;
1544 return hash<type>{}(static_cast<type>(__v));
1545 }
1546};
1547template <class _Tp>
1548struct _LIBCPP_TEMPLATE_VIS __enum_hash<_Tp, false> {
1549 __enum_hash() = delete;
1550 __enum_hash(__enum_hash const&) = delete;
1551 __enum_hash& operator=(__enum_hash const&) = delete;
1552};
1553
1554template <class _Tp>
1555struct _LIBCPP_TEMPLATE_VIS hash : public __enum_hash<_Tp>
1556{
1557};
1558#endif
1559
1560#if _LIBCPP_STD_VER > 14
1561
1562template <>
1563struct _LIBCPP_TEMPLATE_VIS hash<nullptr_t>
1564 : public unary_function<nullptr_t, size_t>
1565{
1566 _LIBCPP_INLINE_VISIBILITY
1567 size_t operator()(nullptr_t) const _NOEXCEPT {
1568 return 662607004ull;
1569 }
1570};
1571#endif
1572
1573#ifndef _LIBCPP_CXX03_LANG
Eric Fiselierd90b9312017-03-03 22:35:58 +00001574template <class _Key, class _Hash>
1575using __check_hash_requirements = integral_constant<bool,
Eric Fiselier698a97b2017-01-21 00:02:12 +00001576 is_copy_constructible<_Hash>::value &&
1577 is_move_constructible<_Hash>::value &&
1578 __invokable_r<size_t, _Hash, _Key const&>::value
1579>;
1580
Eric Fiselierd90b9312017-03-03 22:35:58 +00001581template <class _Key, class _Hash = std::hash<_Key> >
1582using __has_enabled_hash = integral_constant<bool,
1583 __check_hash_requirements<_Key, _Hash>::value &&
1584 is_default_constructible<_Hash>::value
1585>;
1586
Eric Fiselier698a97b2017-01-21 00:02:12 +00001587#if _LIBCPP_STD_VER > 14
1588template <class _Type, class>
1589using __enable_hash_helper_imp = _Type;
1590
1591template <class _Type, class ..._Keys>
1592using __enable_hash_helper = __enable_hash_helper_imp<_Type,
1593 typename enable_if<__all<__has_enabled_hash<_Keys>::value...>::value>::type
1594>;
1595#else
1596template <class _Type, class ...>
1597using __enable_hash_helper = _Type;
1598#endif
1599
1600#endif // !_LIBCPP_CXX03_LANG
1601
Howard Hinnantc51e1022010-05-11 19:42:16 +00001602_LIBCPP_END_NAMESPACE_STD
1603
1604#endif // _LIBCPP_UTILITY