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