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