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