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 |
| 176 | struct in_place_tag { in_place_tag() = delete; }; // C++17 |
| 177 | using in_place_t = in_place_tag(&)(unspecified ); |
| 178 | template <class T> |
| 179 | using in_place_type_t = in_place_tag(&)(unspecified <T>); |
| 180 | template <size_t I> |
| 181 | using in_place_index_t = in_place_tag(&)(unspecified <I>); |
| 182 | in_place_tag in_place(unspecified ); |
| 183 | template <class T> |
| 184 | in_place_tag in_place(unspecified <T>); |
| 185 | template <size_t I> |
| 186 | in_place_tag in_place(unspecified <I>); |
| 187 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 188 | } // std |
| 189 | |
| 190 | */ |
| 191 | |
| 192 | #include <__config> |
| 193 | #include <__tuple> |
| 194 | #include <type_traits> |
Ben Craig | d59d416 | 2016-04-19 20:13:55 +0000 | [diff] [blame] | 195 | #include <initializer_list> |
Eric Fiselier | eef85d9 | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 196 | #include <__debug> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 197 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 198 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 199 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 200 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 201 | |
| 202 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 203 | |
| 204 | namespace rel_ops |
| 205 | { |
| 206 | |
| 207 | template<class _Tp> |
| 208 | inline _LIBCPP_INLINE_VISIBILITY |
| 209 | bool |
| 210 | operator!=(const _Tp& __x, const _Tp& __y) |
| 211 | { |
| 212 | return !(__x == __y); |
| 213 | } |
| 214 | |
| 215 | template<class _Tp> |
| 216 | inline _LIBCPP_INLINE_VISIBILITY |
| 217 | bool |
| 218 | operator> (const _Tp& __x, const _Tp& __y) |
| 219 | { |
| 220 | return __y < __x; |
| 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 !(__x < __y); |
| 237 | } |
| 238 | |
| 239 | } // rel_ops |
| 240 | |
| 241 | // swap_ranges |
| 242 | |
Marshall Clow | fd8ed7f | 2015-01-06 19:20:49 +0000 | [diff] [blame] | 243 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 244 | template <class _ForwardIterator1, class _ForwardIterator2> |
| 245 | inline _LIBCPP_INLINE_VISIBILITY |
| 246 | _ForwardIterator2 |
| 247 | swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) |
| 248 | { |
Eric Fiselier | b991975 | 2014-10-27 19:28:20 +0000 | [diff] [blame] | 249 | for(; __first1 != __last1; ++__first1, (void) ++__first2) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 250 | swap(*__first1, *__first2); |
| 251 | return __first2; |
| 252 | } |
| 253 | |
Eric Fiselier | 8f1e73d | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 254 | // forward declared in <type_traits> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 255 | template<class _Tp, size_t _Np> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 256 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 8f1e73d | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 257 | typename enable_if< |
| 258 | __is_swappable<_Tp>::value |
| 259 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 260 | 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] | 261 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 262 | _VSTD::swap_ranges(__a, __a + _Np, __b); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | template <class _Tp> |
Marshall Clow | 01a0e90 | 2013-07-15 20:46:11 +0000 | [diff] [blame] | 266 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 267 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 268 | typename conditional |
| 269 | < |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 270 | !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 271 | const _Tp&, |
| 272 | _Tp&& |
| 273 | >::type |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 274 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 275 | const _Tp& |
| 276 | #endif |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 277 | move_if_noexcept(_Tp& __x) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 278 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 279 | return _VSTD::move(__x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Marshall Clow | f60d092 | 2015-11-17 00:08:08 +0000 | [diff] [blame] | 282 | #if _LIBCPP_STD_VER > 14 |
| 283 | template <class _Tp> constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; } |
| 284 | template <class _Tp> void as_const(const _Tp&&) = delete; |
| 285 | #endif |
| 286 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 287 | struct _LIBCPP_TYPE_VIS_ONLY piecewise_construct_t { }; |
Howard Hinnant | 616e92d | 2012-04-03 23:45:46 +0000 | [diff] [blame] | 288 | #if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_UTILITY) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 289 | extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t(); |
Howard Hinnant | 2a5349b | 2012-04-03 21:09:48 +0000 | [diff] [blame] | 290 | #else |
| 291 | constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); |
| 292 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 293 | |
Eric Fiselier | e2bd16c | 2016-10-11 21:22:21 +0000 | [diff] [blame] | 294 | #if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR) |
| 295 | struct __non_trivially_copyable_base { |
| 296 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
| 297 | __non_trivially_copyable_base() _NOEXCEPT {} |
| 298 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 299 | __non_trivially_copyable_base(__non_trivially_copyable_base const&) _NOEXCEPT {} |
| 300 | }; |
| 301 | #endif |
Eric Fiselier | e1445fd | 2016-07-25 04:32:07 +0000 | [diff] [blame] | 302 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 303 | template <class _T1, class _T2> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 304 | struct _LIBCPP_TYPE_VIS_ONLY pair |
Eric Fiselier | e2bd16c | 2016-10-11 21:22:21 +0000 | [diff] [blame] | 305 | #if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR) |
| 306 | : private __non_trivially_copyable_base |
| 307 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 308 | { |
| 309 | typedef _T1 first_type; |
| 310 | typedef _T2 second_type; |
| 311 | |
| 312 | _T1 first; |
| 313 | _T2 second; |
| 314 | |
Eric Fiselier | e2bd16c | 2016-10-11 21:22:21 +0000 | [diff] [blame] | 315 | #if !defined(_LIBCPP_CXX03_LANG) |
Eric Fiselier | c71c304 | 2016-07-18 01:58:37 +0000 | [diff] [blame] | 316 | pair(pair const&) = default; |
| 317 | pair(pair&&) = default; |
| 318 | #else |
| 319 | // Use the implicitly declared copy constructor in C++03 |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 320 | #endif |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 321 | |
Eric Fiselier | e1445fd | 2016-07-25 04:32:07 +0000 | [diff] [blame] | 322 | #ifdef _LIBCPP_CXX03_LANG |
| 323 | _LIBCPP_INLINE_VISIBILITY |
| 324 | pair() : first(), second() {} |
Eric Fiselier | 4be71c6 | 2016-07-25 02:36:42 +0000 | [diff] [blame] | 325 | |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 326 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | e1445fd | 2016-07-25 04:32:07 +0000 | [diff] [blame] | 327 | pair(_T1 const& __t1, _T2 const& __t2) : first(__t1), second(__t2) {} |
| 328 | |
| 329 | template <class _U1, class _U2> |
| 330 | _LIBCPP_INLINE_VISIBILITY |
| 331 | pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {} |
| 332 | |
| 333 | _LIBCPP_INLINE_VISIBILITY |
| 334 | pair& operator=(pair const& __p) { |
| 335 | first = __p.first; |
| 336 | second = __p.second; |
| 337 | return *this; |
| 338 | } |
| 339 | #else |
| 340 | template <bool _Val> |
| 341 | using _EnableB = typename enable_if<_Val, bool>::type; |
| 342 | |
| 343 | struct _CheckArgs { |
| 344 | template <class _U1, class _U2> |
| 345 | static constexpr bool __enable_default() { |
| 346 | return is_default_constructible<_U1>::value |
| 347 | && is_default_constructible<_U2>::value; |
| 348 | } |
| 349 | |
| 350 | template <class _U1, class _U2> |
| 351 | static constexpr bool __enable_explicit() { |
| 352 | return is_constructible<first_type, _U1>::value |
| 353 | && is_constructible<second_type, _U2>::value |
| 354 | && (!is_convertible<_U1, first_type>::value |
| 355 | || !is_convertible<_U2, second_type>::value); |
| 356 | } |
| 357 | |
| 358 | template <class _U1, class _U2> |
| 359 | static constexpr bool __enable_implicit() { |
| 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 | |
| 367 | template <bool _MaybeEnable> |
| 368 | using _CheckArgsDep = typename conditional< |
| 369 | _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type; |
| 370 | |
| 371 | struct _CheckTupleLikeConstructor { |
| 372 | template <class _Tuple> |
| 373 | static constexpr bool __enable_implicit() { |
| 374 | return __tuple_convertible<_Tuple, pair>::value; |
| 375 | } |
| 376 | |
| 377 | template <class _Tuple> |
| 378 | static constexpr bool __enable_explicit() { |
| 379 | return __tuple_constructible<_Tuple, pair>::value |
| 380 | && !__tuple_convertible<_Tuple, pair>::value; |
| 381 | } |
| 382 | |
| 383 | template <class _Tuple> |
| 384 | static constexpr bool __enable_assign() { |
| 385 | return __tuple_assignable<_Tuple, pair>::value; |
| 386 | } |
| 387 | }; |
| 388 | |
| 389 | template <class _Tuple> |
| 390 | using _CheckTLC = typename conditional< |
| 391 | __tuple_like_with_size<_Tuple, 2>::value |
| 392 | && !is_same<typename decay<_Tuple>::type, pair>::value, |
| 393 | _CheckTupleLikeConstructor, |
| 394 | __check_tuple_constructor_fail |
| 395 | >::type; |
| 396 | |
| 397 | template<bool _Dummy = true, _EnableB< |
| 398 | _CheckArgsDep<_Dummy>::template __enable_default<_T1, _T2>() |
| 399 | > = false> |
| 400 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 401 | pair() : first(), second() {} |
| 402 | |
| 403 | template <bool _Dummy = true, _EnableB< |
| 404 | _CheckArgsDep<_Dummy>::template __enable_explicit<_T1 const&, _T2 const&>() |
| 405 | > = false> |
| 406 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 407 | explicit pair(_T1 const& __t1, _T2 const& __t2) |
| 408 | : first(__t1), second(__t2) {} |
| 409 | |
| 410 | template<bool _Dummy = true, _EnableB< |
| 411 | _CheckArgsDep<_Dummy>::template __enable_implicit<_T1 const&, _T2 const&>() |
| 412 | > = false> |
| 413 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 414 | pair(_T1 const& __t1, _T2 const& __t2) |
| 415 | : first(__t1), second(__t2) {} |
| 416 | |
| 417 | template<class _U1, class _U2, _EnableB< |
| 418 | _CheckArgs::template __enable_explicit<_U1, _U2>() |
| 419 | > = false> |
| 420 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 421 | explicit pair(_U1&& __u1, _U2&& __u2) |
| 422 | : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {} |
| 423 | |
| 424 | template<class _U1, class _U2, _EnableB< |
| 425 | _CheckArgs::template __enable_implicit<_U1, _U2>() |
| 426 | > = false> |
| 427 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 428 | pair(_U1&& __u1, _U2&& __u2) |
| 429 | : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {} |
| 430 | |
| 431 | template<class _U1, class _U2, _EnableB< |
| 432 | _CheckArgs::template __enable_explicit<_U1 const&, _U2 const&>() |
| 433 | > = false> |
| 434 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 435 | explicit pair(pair<_U1, _U2> const& __p) |
| 436 | : first(__p.first), second(__p.second) {} |
| 437 | |
| 438 | template<class _U1, class _U2, _EnableB< |
| 439 | _CheckArgs::template __enable_implicit<_U1 const&, _U2 const&>() |
| 440 | > = false> |
| 441 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 442 | pair(pair<_U1, _U2> const& __p) |
| 443 | : first(__p.first), second(__p.second) {} |
| 444 | |
| 445 | template<class _U1, class _U2, _EnableB< |
| 446 | _CheckArgs::template __enable_explicit<_U1, _U2>() |
| 447 | > = false> |
| 448 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 449 | explicit pair(pair<_U1, _U2>&&__p) |
| 450 | : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {} |
| 451 | |
| 452 | template<class _U1, class _U2, _EnableB< |
| 453 | _CheckArgs::template __enable_implicit<_U1, _U2>() |
| 454 | > = false> |
| 455 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 456 | pair(pair<_U1, _U2>&& __p) |
| 457 | : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {} |
| 458 | |
| 459 | template<class _Tuple, _EnableB< |
| 460 | _CheckTLC<_Tuple>::template __enable_explicit<_Tuple>() |
| 461 | > = false> |
| 462 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 463 | explicit pair(_Tuple&& __p) |
| 464 | : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))), |
| 465 | second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {} |
| 466 | |
| 467 | template<class _Tuple, _EnableB< |
| 468 | _CheckTLC<_Tuple>::template __enable_implicit<_Tuple>() |
| 469 | > = false> |
| 470 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 471 | 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... _Args1, class... _Args2> |
| 476 | _LIBCPP_INLINE_VISIBILITY |
| 477 | pair(piecewise_construct_t __pc, |
| 478 | tuple<_Args1...> __first_args, tuple<_Args2...> __second_args) |
| 479 | : pair(__pc, __first_args, __second_args, |
| 480 | typename __make_tuple_indices<sizeof...(_Args1)>::type(), |
| 481 | typename __make_tuple_indices<sizeof...(_Args2) >::type()) {} |
| 482 | |
| 483 | _LIBCPP_INLINE_VISIBILITY |
| 484 | pair& operator=(typename conditional< |
| 485 | is_copy_assignable<first_type>::value && |
| 486 | is_copy_assignable<second_type>::value, |
| 487 | pair, __nat>::type const& __p) |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 488 | _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value && |
| 489 | is_nothrow_copy_assignable<second_type>::value) |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 490 | { |
| 491 | first = __p.first; |
| 492 | second = __p.second; |
| 493 | return *this; |
| 494 | } |
| 495 | |
Eric Fiselier | 4be71c6 | 2016-07-25 02:36:42 +0000 | [diff] [blame] | 496 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | e1445fd | 2016-07-25 04:32:07 +0000 | [diff] [blame] | 497 | pair& operator=(typename conditional< |
| 498 | is_move_assignable<first_type>::value && |
| 499 | is_move_assignable<second_type>::value, |
| 500 | pair, __nat>::type&& __p) |
Eric Fiselier | 4be71c6 | 2016-07-25 02:36:42 +0000 | [diff] [blame] | 501 | _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value && |
| 502 | is_nothrow_move_assignable<second_type>::value) |
| 503 | { |
| 504 | first = _VSTD::forward<first_type>(__p.first); |
| 505 | second = _VSTD::forward<second_type>(__p.second); |
| 506 | return *this; |
| 507 | } |
Eric Fiselier | e1445fd | 2016-07-25 04:32:07 +0000 | [diff] [blame] | 508 | |
| 509 | template <class _Tuple, _EnableB< |
Eric Fiselier | 235d71f | 2016-08-29 01:43:41 +0000 | [diff] [blame] | 510 | _CheckTLC<_Tuple>::template __enable_assign<_Tuple>() |
Eric Fiselier | e1445fd | 2016-07-25 04:32:07 +0000 | [diff] [blame] | 511 | > = false> |
| 512 | _LIBCPP_INLINE_VISIBILITY |
| 513 | pair& operator=(_Tuple&& __p) { |
| 514 | first = _VSTD::get<0>(_VSTD::forward<_Tuple>(__p)); |
| 515 | second = _VSTD::get<1>(_VSTD::forward<_Tuple>(__p)); |
| 516 | return *this; |
| 517 | } |
Eric Fiselier | 4be71c6 | 2016-07-25 02:36:42 +0000 | [diff] [blame] | 518 | #endif |
| 519 | |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 520 | _LIBCPP_INLINE_VISIBILITY |
| 521 | void |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 522 | swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value && |
| 523 | __is_nothrow_swappable<second_type>::value) |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 524 | { |
Marshall Clow | 6b0e419 | 2015-09-22 17:50:11 +0000 | [diff] [blame] | 525 | using _VSTD::swap; |
| 526 | swap(first, __p.first); |
| 527 | swap(second, __p.second); |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 528 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 529 | private: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 530 | |
Eric Fiselier | e1445fd | 2016-07-25 04:32:07 +0000 | [diff] [blame] | 531 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 532 | template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> |
Howard Hinnant | 5f5859c | 2011-01-13 20:05:05 +0000 | [diff] [blame] | 533 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 534 | pair(piecewise_construct_t, |
| 535 | tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, |
| 536 | __tuple_indices<_I1...>, __tuple_indices<_I2...>); |
Eric Fiselier | e1445fd | 2016-07-25 04:32:07 +0000 | [diff] [blame] | 537 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 538 | }; |
| 539 | |
| 540 | template <class _T1, class _T2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 541 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 542 | bool |
| 543 | operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 544 | { |
| 545 | return __x.first == __y.first && __x.second == __y.second; |
| 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 == __y); |
| 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.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second); |
| 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 __y < __x; |
| 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 !(__x < __y); |
| 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 !(__y < __x); |
| 586 | } |
| 587 | |
| 588 | template <class _T1, class _T2> |
| 589 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aabf287 | 2011-06-01 19:59:32 +0000 | [diff] [blame] | 590 | typename enable_if |
| 591 | < |
| 592 | __is_swappable<_T1>::value && |
| 593 | __is_swappable<_T2>::value, |
| 594 | void |
| 595 | >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 596 | swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 597 | _NOEXCEPT_((__is_nothrow_swappable<_T1>::value && |
| 598 | __is_nothrow_swappable<_T2>::value)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 599 | { |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 600 | __x.swap(__y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 603 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 604 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 605 | |
| 606 | template <class _Tp> |
Marshall Clow | a71f956 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 607 | struct __make_pair_return_impl |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 608 | { |
| 609 | typedef _Tp type; |
| 610 | }; |
| 611 | |
| 612 | template <class _Tp> |
Marshall Clow | a71f956 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 613 | struct __make_pair_return_impl<reference_wrapper<_Tp>> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 614 | { |
| 615 | typedef _Tp& type; |
| 616 | }; |
| 617 | |
| 618 | template <class _Tp> |
| 619 | struct __make_pair_return |
| 620 | { |
Marshall Clow | a71f956 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 621 | typedef typename __make_pair_return_impl<typename decay<_Tp>::type>::type type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 622 | }; |
| 623 | |
| 624 | template <class _T1, class _T2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 625 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 626 | pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type> |
| 627 | make_pair(_T1&& __t1, _T2&& __t2) |
| 628 | { |
| 629 | 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] | 630 | (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 633 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 634 | |
| 635 | template <class _T1, class _T2> |
| 636 | inline _LIBCPP_INLINE_VISIBILITY |
| 637 | pair<_T1,_T2> |
| 638 | make_pair(_T1 __x, _T2 __y) |
| 639 | { |
| 640 | return pair<_T1, _T2>(__x, __y); |
| 641 | } |
| 642 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 643 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 644 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 645 | template <class _T1, class _T2> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 646 | class _LIBCPP_TYPE_VIS_ONLY tuple_size<pair<_T1, _T2> > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 647 | : public integral_constant<size_t, 2> {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 648 | |
| 649 | template <class _T1, class _T2> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 650 | class _LIBCPP_TYPE_VIS_ONLY tuple_element<0, pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 651 | { |
| 652 | public: |
| 653 | typedef _T1 type; |
| 654 | }; |
| 655 | |
| 656 | template <class _T1, class _T2> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 657 | class _LIBCPP_TYPE_VIS_ONLY tuple_element<1, pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 658 | { |
| 659 | public: |
| 660 | typedef _T2 type; |
| 661 | }; |
| 662 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 663 | template <size_t _Ip> struct __get_pair; |
| 664 | |
| 665 | template <> |
| 666 | struct __get_pair<0> |
| 667 | { |
| 668 | template <class _T1, class _T2> |
| 669 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 670 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 671 | _T1& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 672 | get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 673 | |
| 674 | template <class _T1, class _T2> |
| 675 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 676 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 677 | const _T1& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 678 | get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 679 | |
| 680 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 681 | |
| 682 | template <class _T1, class _T2> |
| 683 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 684 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 685 | _T1&& |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 686 | get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 687 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 688 | template <class _T1, class _T2> |
| 689 | static |
| 690 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 691 | const _T1&& |
| 692 | get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);} |
| 693 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 694 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 695 | }; |
| 696 | |
| 697 | template <> |
| 698 | struct __get_pair<1> |
| 699 | { |
| 700 | template <class _T1, class _T2> |
| 701 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 702 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 703 | _T2& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 704 | get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 705 | |
| 706 | template <class _T1, class _T2> |
| 707 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 708 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 709 | const _T2& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 710 | get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 711 | |
| 712 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 713 | |
| 714 | template <class _T1, class _T2> |
| 715 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 716 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 717 | _T2&& |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 718 | get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 719 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 720 | template <class _T1, class _T2> |
| 721 | static |
| 722 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 723 | const _T2&& |
| 724 | get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);} |
| 725 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 726 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 727 | }; |
| 728 | |
| 729 | template <size_t _Ip, class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 730 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 731 | typename tuple_element<_Ip, pair<_T1, _T2> >::type& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 732 | get(pair<_T1, _T2>& __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 733 | { |
| 734 | return __get_pair<_Ip>::get(__p); |
| 735 | } |
| 736 | |
| 737 | template <size_t _Ip, class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 738 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 739 | const typename tuple_element<_Ip, pair<_T1, _T2> >::type& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 740 | get(const pair<_T1, _T2>& __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 741 | { |
| 742 | return __get_pair<_Ip>::get(__p); |
| 743 | } |
| 744 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 745 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 746 | |
| 747 | template <size_t _Ip, class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 748 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 749 | typename tuple_element<_Ip, pair<_T1, _T2> >::type&& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 750 | get(pair<_T1, _T2>&& __p) _NOEXCEPT |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 751 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 752 | return __get_pair<_Ip>::get(_VSTD::move(__p)); |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 753 | } |
| 754 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 755 | template <size_t _Ip, class _T1, class _T2> |
| 756 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 757 | const typename tuple_element<_Ip, pair<_T1, _T2> >::type&& |
| 758 | get(const pair<_T1, _T2>&& __p) _NOEXCEPT |
| 759 | { |
| 760 | return __get_pair<_Ip>::get(_VSTD::move(__p)); |
| 761 | } |
| 762 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 763 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 764 | |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 765 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 766 | template <class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 767 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 768 | constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT |
| 769 | { |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 770 | return __get_pair<0>::get(__p); |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 771 | } |
| 772 | |
| 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 const & get(pair<_T1, _T2> const& __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 && get(pair<_T1, _T2>&& __p) _NOEXCEPT |
| 783 | { |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 784 | return __get_pair<0>::get(_VSTD::move(__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 |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 789 | constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT |
| 790 | { |
| 791 | return __get_pair<0>::get(_VSTD::move(__p)); |
| 792 | } |
| 793 | |
| 794 | template <class _T1, class _T2> |
| 795 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 796 | constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT |
| 797 | { |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 798 | return __get_pair<1>::get(__p); |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | template <class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 802 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 803 | constexpr _T1 const & get(pair<_T2, _T1> const& __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 && get(pair<_T2, _T1>&& __p) _NOEXCEPT |
| 811 | { |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 812 | return __get_pair<1>::get(_VSTD::move(__p)); |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 813 | } |
| 814 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 815 | template <class _T1, class _T2> |
| 816 | inline _LIBCPP_INLINE_VISIBILITY |
| 817 | constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT |
| 818 | { |
| 819 | return __get_pair<1>::get(_VSTD::move(__p)); |
| 820 | } |
| 821 | |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 822 | #endif |
| 823 | |
| 824 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 825 | |
| 826 | template<class _Tp, _Tp... _Ip> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 827 | struct _LIBCPP_TYPE_VIS_ONLY integer_sequence |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 828 | { |
| 829 | typedef _Tp value_type; |
| 830 | static_assert( is_integral<_Tp>::value, |
| 831 | "std::integer_sequence can only be instantiated with an integral type" ); |
| 832 | static |
| 833 | _LIBCPP_INLINE_VISIBILITY |
| 834 | constexpr |
| 835 | size_t |
| 836 | size() noexcept { return sizeof...(_Ip); } |
| 837 | }; |
| 838 | |
| 839 | template<size_t... _Ip> |
| 840 | using index_sequence = integer_sequence<size_t, _Ip...>; |
| 841 | |
Eric Fiselier | 76d2446 | 2015-12-09 22:03:06 +0000 | [diff] [blame] | 842 | #if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE) |
| 843 | |
| 844 | template <class _Tp, _Tp _Ep> |
Eric Fiselier | a3ccd96 | 2016-06-30 22:34:43 +0000 | [diff] [blame] | 845 | using __make_integer_sequence = __make_integer_seq<integer_sequence, _Tp, _Ep>; |
Eric Fiselier | 76d2446 | 2015-12-09 22:03:06 +0000 | [diff] [blame] | 846 | |
| 847 | #else |
| 848 | |
Marshall Clow | 42e55e9 | 2013-07-03 19:20:30 +0000 | [diff] [blame] | 849 | template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked = |
Eric Fiselier | a3ccd96 | 2016-06-30 22:34:43 +0000 | [diff] [blame] | 850 | typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>; |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 851 | |
| 852 | template <class _Tp, _Tp _Ep> |
Eric Fiselier | a3ccd96 | 2016-06-30 22:34:43 +0000 | [diff] [blame] | 853 | struct __make_integer_sequence_checked |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 854 | { |
| 855 | static_assert(is_integral<_Tp>::value, |
| 856 | "std::make_integer_sequence can only be instantiated with an integral type" ); |
Eric Fiselier | 76d2446 | 2015-12-09 22:03:06 +0000 | [diff] [blame] | 857 | 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] | 858 | // Workaround GCC bug by preventing bad installations when 0 <= _Ep |
| 859 | // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929 |
| 860 | typedef __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type; |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 861 | }; |
| 862 | |
Eric Fiselier | a3ccd96 | 2016-06-30 22:34:43 +0000 | [diff] [blame] | 863 | template <class _Tp, _Tp _Ep> |
| 864 | using __make_integer_sequence = typename __make_integer_sequence_checked<_Tp, _Ep>::type; |
| 865 | |
Eric Fiselier | 76d2446 | 2015-12-09 22:03:06 +0000 | [diff] [blame] | 866 | #endif |
| 867 | |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 868 | template<class _Tp, _Tp _Np> |
Eric Fiselier | a3ccd96 | 2016-06-30 22:34:43 +0000 | [diff] [blame] | 869 | using make_integer_sequence = __make_integer_sequence<_Tp, _Np>; |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 870 | |
| 871 | template<size_t _Np> |
| 872 | using make_index_sequence = make_integer_sequence<size_t, _Np>; |
| 873 | |
| 874 | template<class... _Tp> |
| 875 | using index_sequence_for = make_index_sequence<sizeof...(_Tp)>; |
Marshall Clow | 5270a84 | 2016-06-19 19:29:52 +0000 | [diff] [blame] | 876 | |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 877 | #endif // _LIBCPP_STD_VER > 11 |
| 878 | |
Marshall Clow | e2735d1 | 2013-07-08 20:54:40 +0000 | [diff] [blame] | 879 | #if _LIBCPP_STD_VER > 11 |
| 880 | template<class _T1, class _T2 = _T1> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 881 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e2735d1 | 2013-07-08 20:54:40 +0000 | [diff] [blame] | 882 | _T1 exchange(_T1& __obj, _T2 && __new_value) |
| 883 | { |
Howard Hinnant | 171771a | 2013-07-08 21:06:38 +0000 | [diff] [blame] | 884 | _T1 __old_value = _VSTD::move(__obj); |
| 885 | __obj = _VSTD::forward<_T2>(__new_value); |
| 886 | return __old_value; |
Marshall Clow | 5270a84 | 2016-06-19 19:29:52 +0000 | [diff] [blame] | 887 | } |
Marshall Clow | e2735d1 | 2013-07-08 20:54:40 +0000 | [diff] [blame] | 888 | #endif // _LIBCPP_STD_VER > 11 |
| 889 | |
Eric Fiselier | eef85d9 | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 890 | #if _LIBCPP_STD_VER > 14 |
| 891 | |
| 892 | struct _LIBCPP_TYPE_VIS_ONLY __in_place_tag {}; |
| 893 | template <class> struct _LIBCPP_TYPE_VIS_ONLY __in_place_type_tag {}; |
| 894 | template <size_t> struct _LIBCPP_TYPE_VIS_ONLY __in_place_index_tag {}; |
| 895 | |
| 896 | struct _LIBCPP_TYPE_VIS_ONLY in_place_tag; |
| 897 | |
| 898 | using in_place_t = in_place_tag(&)(__in_place_tag); |
| 899 | template <class _Tp> |
| 900 | using in_place_type_t = in_place_tag(&)(__in_place_type_tag<_Tp>); |
| 901 | template <size_t _Nx> |
| 902 | using in_place_index_t = in_place_tag(&)(__in_place_index_tag<_Nx>); |
| 903 | |
| 904 | struct in_place_tag { |
| 905 | in_place_tag() = delete; |
| 906 | private: |
| 907 | explicit in_place_tag(__in_place_tag) {} |
| 908 | |
| 909 | friend inline in_place_tag in_place(__in_place_tag __t); |
| 910 | template <class _Tp> |
| 911 | friend inline in_place_tag in_place(__in_place_type_tag<_Tp>); |
| 912 | template <size_t _Nx> |
| 913 | friend inline in_place_tag in_place(__in_place_index_tag<_Nx>); |
| 914 | }; |
| 915 | |
| 916 | inline in_place_tag in_place(__in_place_tag __t) { |
| 917 | _LIBCPP_ASSERT(false, "The in_place function cannot be invoked"); |
| 918 | return in_place_tag(__t); |
| 919 | } |
| 920 | template <class _Tp> |
| 921 | inline in_place_tag in_place(__in_place_type_tag<_Tp>) { |
| 922 | _LIBCPP_ASSERT(false, "The in_place function cannot be invoked"); |
| 923 | return in_place_tag(__in_place_tag{}); |
| 924 | } |
| 925 | template <size_t _Nx> |
| 926 | inline in_place_tag in_place(__in_place_index_tag<_Nx>) { |
| 927 | _LIBCPP_ASSERT(false, "The in_place function cannot be invoked"); |
| 928 | return in_place_tag(__in_place_tag{}); |
| 929 | } |
| 930 | |
Eric Fiselier | 846edfb | 2016-10-16 02:51:50 +0000 | [diff] [blame^] | 931 | template <class _Tp> struct __is_inplace_tag_imp : false_type {}; |
| 932 | template <> struct __is_inplace_tag_imp<in_place_tag(__in_place_tag)> : true_type {}; |
| 933 | template <class _Tp> struct __is_inplace_tag_imp<in_place_tag(__in_place_type_tag<_Tp>)> : true_type {}; |
| 934 | template <size_t _Idx> struct __is_inplace_tag_imp<in_place_tag(__in_place_index_tag<_Idx>)> : true_type {}; |
| 935 | |
| 936 | template <class _Tp> |
| 937 | using __is_inplace_tag = __is_inplace_tag_imp<remove_pointer_t<decay_t<_Tp>>>; |
| 938 | |
| 939 | template <class _Tp> struct __is_inplace_type_tag_imp : false_type {}; |
| 940 | template <class _Tp> struct __is_inplace_type_tag_imp<in_place_tag(__in_place_type_tag<_Tp>)> : true_type {}; |
| 941 | |
| 942 | template <class _Tp> |
| 943 | using __is_inplace_type_tag = __is_inplace_type_tag_imp<remove_pointer_t<decay_t<_Tp>>>; |
| 944 | |
Eric Fiselier | 15d8a56 | 2016-07-24 07:42:13 +0000 | [diff] [blame] | 945 | |
Eric Fiselier | eef85d9 | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 946 | #endif // _LIBCPP_STD_VER > 14 |
| 947 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 948 | _LIBCPP_END_NAMESPACE_STD |
| 949 | |
| 950 | #endif // _LIBCPP_UTILITY |