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