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 | |
| 41 | template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; |
| 42 | template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; |
| 43 | |
| 44 | template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; |
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 |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 53 | move_if_noexcept(T& x) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 54 | |
| 55 | template <class T> typename add_rvalue_reference<T>::type declval() noexcept; |
| 56 | |
| 57 | template <class T1, class T2> |
| 58 | struct pair |
| 59 | { |
| 60 | typedef T1 first_type; |
| 61 | typedef T2 second_type; |
| 62 | |
| 63 | T1 first; |
| 64 | T2 second; |
| 65 | |
| 66 | pair(const pair&) = default; |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 67 | pair(pair&&) = default; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 68 | constexpr pair(); |
| 69 | pair(const T1& x, const T2& y); |
| 70 | template <class U, class V> pair(U&& x, V&& y); |
| 71 | template <class U, class V> pair(const pair<U, V>& p); |
| 72 | template <class U, class V> pair(pair<U, V>&& p); |
| 73 | template <class... Args1, class... Args2> |
| 74 | pair(piecewise_construct_t, tuple<Args1...> first_args, |
| 75 | tuple<Args2...> second_args); |
| 76 | |
| 77 | template <class U, class V> pair& operator=(const pair<U, V>& p); |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 78 | pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value && |
| 79 | is_nothrow_move_assignable<T2>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 80 | template <class U, class V> pair& operator=(pair<U, V>&& p); |
| 81 | |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 82 | void swap(pair& p) noexcept(noexcept(swap(first, p.first)) && |
| 83 | noexcept(swap(second, p.second))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); |
| 87 | template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); |
| 88 | template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); |
| 89 | template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); |
| 90 | template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); |
| 91 | template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); |
| 92 | |
| 93 | template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 94 | template <class T1, class T2> |
| 95 | void |
| 96 | 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] | 97 | |
| 98 | struct piecewise_construct_t { }; |
| 99 | constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); |
| 100 | |
| 101 | template <class T> class tuple_size; |
| 102 | template <size_t I, class T> class tuple_element; |
| 103 | |
| 104 | template <class T1, class T2> struct tuple_size<std::pair<T1, T2> >; |
| 105 | template <class T1, class T2> struct tuple_element<0, std::pair<T1, T2> >; |
| 106 | template <class T1, class T2> struct tuple_element<1, std::pair<T1, T2> >; |
| 107 | |
| 108 | template<size_t I, class T1, class T2> |
| 109 | typename tuple_element<I, std::pair<T1, T2> >::type& |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 110 | get(std::pair<T1, T2>&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 111 | |
| 112 | template<size_t I, class T1, class T2> |
| 113 | const typename const tuple_element<I, std::pair<T1, T2> >::type& |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 114 | get(const std::pair<T1, T2>&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 115 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 116 | template<size_t I, class T1, class T2> |
| 117 | typename tuple_element<I, std::pair<T1, T2> >::type&& |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 118 | get(std::pair<T1, T2>&&) noexcept; |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 119 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 120 | } // std |
| 121 | |
| 122 | */ |
| 123 | |
| 124 | #include <__config> |
| 125 | #include <__tuple> |
| 126 | #include <type_traits> |
| 127 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 128 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 129 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 130 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 131 | |
| 132 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 133 | |
| 134 | namespace rel_ops |
| 135 | { |
| 136 | |
| 137 | template<class _Tp> |
| 138 | inline _LIBCPP_INLINE_VISIBILITY |
| 139 | bool |
| 140 | operator!=(const _Tp& __x, const _Tp& __y) |
| 141 | { |
| 142 | return !(__x == __y); |
| 143 | } |
| 144 | |
| 145 | template<class _Tp> |
| 146 | inline _LIBCPP_INLINE_VISIBILITY |
| 147 | bool |
| 148 | operator> (const _Tp& __x, const _Tp& __y) |
| 149 | { |
| 150 | return __y < __x; |
| 151 | } |
| 152 | |
| 153 | template<class _Tp> |
| 154 | inline _LIBCPP_INLINE_VISIBILITY |
| 155 | bool |
| 156 | operator<=(const _Tp& __x, const _Tp& __y) |
| 157 | { |
| 158 | return !(__y < __x); |
| 159 | } |
| 160 | |
| 161 | template<class _Tp> |
| 162 | inline _LIBCPP_INLINE_VISIBILITY |
| 163 | bool |
| 164 | operator>=(const _Tp& __x, const _Tp& __y) |
| 165 | { |
| 166 | return !(__x < __y); |
| 167 | } |
| 168 | |
| 169 | } // rel_ops |
| 170 | |
| 171 | // swap_ranges |
| 172 | |
| 173 | template <class _ForwardIterator1, class _ForwardIterator2> |
| 174 | inline _LIBCPP_INLINE_VISIBILITY |
| 175 | _ForwardIterator2 |
| 176 | swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) |
| 177 | { |
| 178 | for(; __first1 != __last1; ++__first1, ++__first2) |
| 179 | swap(*__first1, *__first2); |
| 180 | return __first2; |
| 181 | } |
| 182 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 183 | template<class _Tp, size_t _Np> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 184 | inline _LIBCPP_INLINE_VISIBILITY |
| 185 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 186 | 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] | 187 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 188 | _VSTD::swap_ranges(__a, __a + _Np, __b); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | template <class _Tp> |
| 192 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 193 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 194 | typename conditional |
| 195 | < |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 196 | !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 197 | const _Tp&, |
| 198 | _Tp&& |
| 199 | >::type |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 200 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 201 | const _Tp& |
| 202 | #endif |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 203 | move_if_noexcept(_Tp& __x) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 204 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 205 | return _VSTD::move(__x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 208 | struct _LIBCPP_VISIBLE piecewise_construct_t { }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 209 | //constexpr |
| 210 | extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t(); |
| 211 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 212 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 213 | struct _LIBCPP_VISIBLE pair |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 214 | { |
| 215 | typedef _T1 first_type; |
| 216 | typedef _T2 second_type; |
| 217 | |
| 218 | _T1 first; |
| 219 | _T2 second; |
| 220 | |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 221 | // pair(const pair&) = default; |
| 222 | // pair(pair&&) = default; |
| 223 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 224 | _LIBCPP_INLINE_VISIBILITY pair() : first(), second() {} |
| 225 | |
| 226 | _LIBCPP_INLINE_VISIBILITY pair(const _T1& __x, const _T2& __y) |
| 227 | : first(__x), second(__y) {} |
| 228 | |
Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 229 | template<class _U1, class _U2> |
| 230 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9c59d38 | 2011-07-27 19:25:28 +0000 | [diff] [blame] | 231 | pair(const pair<_U1, _U2>& __p |
| 232 | #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE |
| 233 | ,typename enable_if<is_constructible<_T1, _U1>::value && |
| 234 | is_constructible<_T2, _U2>::value>::type* = 0 |
| 235 | #endif |
| 236 | ) |
Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 237 | : first(__p.first), second(__p.second) {} |
| 238 | |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 239 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 240 | pair(const pair& __p) |
| 241 | _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value && |
| 242 | is_nothrow_copy_constructible<second_type>::value) |
| 243 | : first(__p.first), |
| 244 | second(__p.second) |
| 245 | { |
| 246 | } |
| 247 | |
| 248 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 249 | pair& operator=(const pair& __p) |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 250 | _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value && |
| 251 | is_nothrow_copy_assignable<second_type>::value) |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 252 | { |
| 253 | first = __p.first; |
| 254 | second = __p.second; |
| 255 | return *this; |
| 256 | } |
| 257 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 258 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 259 | |
| 260 | template <class _U1, class _U2, |
Howard Hinnant | 7424888 | 2011-07-01 20:12:51 +0000 | [diff] [blame] | 261 | class = typename enable_if<is_constructible<first_type, _U1 >::value && |
| 262 | is_constructible<second_type, _U2>::value>::type> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 263 | _LIBCPP_INLINE_VISIBILITY |
| 264 | pair(_U1&& __u1, _U2&& __u2) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 265 | : first(_VSTD::forward<_U1>(__u1)), |
| 266 | second(_VSTD::forward<_U2>(__u2)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 267 | {} |
| 268 | |
Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 269 | template<class _U1, class _U2> |
| 270 | _LIBCPP_INLINE_VISIBILITY |
| 271 | pair(pair<_U1, _U2>&& __p, |
Howard Hinnant | 7424888 | 2011-07-01 20:12:51 +0000 | [diff] [blame] | 272 | typename enable_if<is_constructible<_T1, _U1>::value && |
| 273 | is_constructible<_T2, _U2>::value>::type* = 0) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 274 | : first(_VSTD::forward<_U1>(__p.first)), |
| 275 | second(_VSTD::forward<_U2>(__p.second)) {} |
Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 276 | |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 277 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 278 | pair(pair&& __p) _NOEXCEPT_(is_nothrow_move_constructible<first_type>::value && |
| 279 | is_nothrow_move_constructible<second_type>::value) |
| 280 | : first(_VSTD::forward<first_type>(__p.first)), |
| 281 | second(_VSTD::forward<second_type>(__p.second)) |
| 282 | { |
| 283 | } |
| 284 | |
| 285 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 286 | pair& |
| 287 | operator=(pair&& __p) _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value && |
| 288 | is_nothrow_move_assignable<second_type>::value) |
| 289 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 290 | first = _VSTD::forward<first_type>(__p.first); |
| 291 | second = _VSTD::forward<second_type>(__p.second); |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 292 | return *this; |
| 293 | } |
| 294 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 295 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 296 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 297 | template<class _Tuple, |
| 298 | class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type> |
| 299 | _LIBCPP_INLINE_VISIBILITY |
| 300 | pair(_Tuple&& __p) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 301 | : first(_VSTD::forward<typename tuple_element<0, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 302 | typename __make_tuple_types<_Tuple>::type>::type>(get<0>(__p))), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 303 | second(_VSTD::forward<typename tuple_element<1, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 304 | typename __make_tuple_types<_Tuple>::type>::type>(get<1>(__p))) |
| 305 | {} |
| 306 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 307 | |
Howard Hinnant | 726a76f | 2010-11-16 21:10:23 +0000 | [diff] [blame] | 308 | |
Howard Hinnant | 6cc99fa | 2011-12-19 17:58:44 +0000 | [diff] [blame^] | 309 | template <class... _Args1, class... _Args2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 310 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 311 | pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, |
| 312 | tuple<_Args2...> __second_args) |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 313 | : pair(__pc, __first_args, __second_args, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 314 | typename __make_tuple_indices<sizeof...(_Args1)>::type(), |
| 315 | typename __make_tuple_indices<sizeof...(_Args2) >::type()) |
| 316 | {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 317 | |
| 318 | template <class _Tuple, |
| 319 | class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 320 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 321 | pair& |
| 322 | operator=(_Tuple&& __p) |
| 323 | { |
| 324 | typedef typename __make_tuple_types<_Tuple>::type _TupleRef; |
| 325 | typedef typename tuple_element<0, _TupleRef>::type _U0; |
| 326 | typedef typename tuple_element<1, _TupleRef>::type _U1; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 327 | first = _VSTD::forward<_U0>(_VSTD::get<0>(__p)); |
| 328 | second = _VSTD::forward<_U1>(_VSTD::get<1>(__p)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 329 | return *this; |
| 330 | } |
| 331 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 332 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 333 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 334 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 335 | _LIBCPP_INLINE_VISIBILITY |
| 336 | void |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 337 | swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value && |
| 338 | __is_nothrow_swappable<second_type>::value) |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 339 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 340 | _VSTD::iter_swap(&first, &__p.first); |
| 341 | _VSTD::iter_swap(&second, &__p.second); |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 342 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 343 | private: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 344 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 345 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 346 | template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> |
Howard Hinnant | 5f5859c | 2011-01-13 20:05:05 +0000 | [diff] [blame] | 347 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 348 | pair(piecewise_construct_t, |
| 349 | tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, |
| 350 | __tuple_indices<_I1...>, __tuple_indices<_I2...>); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 351 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 352 | }; |
| 353 | |
| 354 | template <class _T1, class _T2> |
| 355 | inline _LIBCPP_INLINE_VISIBILITY |
| 356 | bool |
| 357 | operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 358 | { |
| 359 | return __x.first == __y.first && __x.second == __y.second; |
| 360 | } |
| 361 | |
| 362 | template <class _T1, class _T2> |
| 363 | inline _LIBCPP_INLINE_VISIBILITY |
| 364 | bool |
| 365 | operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 366 | { |
| 367 | return !(__x == __y); |
| 368 | } |
| 369 | |
| 370 | template <class _T1, class _T2> |
| 371 | inline _LIBCPP_INLINE_VISIBILITY |
| 372 | bool |
| 373 | operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 374 | { |
| 375 | return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second); |
| 376 | } |
| 377 | |
| 378 | template <class _T1, class _T2> |
| 379 | inline _LIBCPP_INLINE_VISIBILITY |
| 380 | bool |
| 381 | operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 382 | { |
| 383 | return __y < __x; |
| 384 | } |
| 385 | |
| 386 | template <class _T1, class _T2> |
| 387 | inline _LIBCPP_INLINE_VISIBILITY |
| 388 | bool |
| 389 | operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 390 | { |
| 391 | return !(__x < __y); |
| 392 | } |
| 393 | |
| 394 | template <class _T1, class _T2> |
| 395 | inline _LIBCPP_INLINE_VISIBILITY |
| 396 | bool |
| 397 | operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 398 | { |
| 399 | return !(__y < __x); |
| 400 | } |
| 401 | |
| 402 | template <class _T1, class _T2> |
| 403 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aabf287 | 2011-06-01 19:59:32 +0000 | [diff] [blame] | 404 | typename enable_if |
| 405 | < |
| 406 | __is_swappable<_T1>::value && |
| 407 | __is_swappable<_T2>::value, |
| 408 | void |
| 409 | >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 410 | swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 411 | _NOEXCEPT_((__is_nothrow_swappable<_T1>::value && |
| 412 | __is_nothrow_swappable<_T2>::value)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 413 | { |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 414 | __x.swap(__y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 417 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 418 | |
| 419 | template <class _Tp> class reference_wrapper; |
| 420 | |
| 421 | template <class _Tp> |
| 422 | struct ___make_pair_return |
| 423 | { |
| 424 | typedef _Tp type; |
| 425 | }; |
| 426 | |
| 427 | template <class _Tp> |
| 428 | struct ___make_pair_return<reference_wrapper<_Tp>> |
| 429 | { |
| 430 | typedef _Tp& type; |
| 431 | }; |
| 432 | |
| 433 | template <class _Tp> |
| 434 | struct __make_pair_return |
| 435 | { |
| 436 | typedef typename ___make_pair_return<typename decay<_Tp>::type>::type type; |
| 437 | }; |
| 438 | |
| 439 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 440 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 441 | pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type> |
| 442 | make_pair(_T1&& __t1, _T2&& __t2) |
| 443 | { |
| 444 | 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] | 445 | (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 446 | } |
| 447 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 448 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 449 | |
| 450 | template <class _T1, class _T2> |
| 451 | inline _LIBCPP_INLINE_VISIBILITY |
| 452 | pair<_T1,_T2> |
| 453 | make_pair(_T1 __x, _T2 __y) |
| 454 | { |
| 455 | return pair<_T1, _T2>(__x, __y); |
| 456 | } |
| 457 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 458 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 459 | |
| 460 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 461 | |
| 462 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 463 | class _LIBCPP_VISIBLE tuple_size<pair<_T1, _T2> > |
| 464 | : public integral_constant<size_t, 2> {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 465 | |
| 466 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 467 | class _LIBCPP_VISIBLE tuple_size<const pair<_T1, _T2> > |
| 468 | : public integral_constant<size_t, 2> {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 469 | |
| 470 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 471 | class _LIBCPP_VISIBLE tuple_element<0, pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 472 | { |
| 473 | public: |
| 474 | typedef _T1 type; |
| 475 | }; |
| 476 | |
| 477 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 478 | class _LIBCPP_VISIBLE tuple_element<1, pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 479 | { |
| 480 | public: |
| 481 | typedef _T2 type; |
| 482 | }; |
| 483 | |
| 484 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 485 | class _LIBCPP_VISIBLE tuple_element<0, const pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 486 | { |
| 487 | public: |
| 488 | typedef const _T1 type; |
| 489 | }; |
| 490 | |
| 491 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 492 | class _LIBCPP_VISIBLE tuple_element<1, const pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 493 | { |
| 494 | public: |
| 495 | typedef const _T2 type; |
| 496 | }; |
| 497 | |
| 498 | template <size_t _Ip> struct __get_pair; |
| 499 | |
| 500 | template <> |
| 501 | struct __get_pair<0> |
| 502 | { |
| 503 | template <class _T1, class _T2> |
| 504 | static |
| 505 | _LIBCPP_INLINE_VISIBILITY |
| 506 | _T1& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 507 | get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 508 | |
| 509 | template <class _T1, class _T2> |
| 510 | static |
| 511 | _LIBCPP_INLINE_VISIBILITY |
| 512 | const _T1& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 513 | get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 514 | |
| 515 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 516 | |
| 517 | template <class _T1, class _T2> |
| 518 | static |
| 519 | _LIBCPP_INLINE_VISIBILITY |
| 520 | _T1&& |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 521 | get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 522 | |
| 523 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 524 | }; |
| 525 | |
| 526 | template <> |
| 527 | struct __get_pair<1> |
| 528 | { |
| 529 | template <class _T1, class _T2> |
| 530 | static |
| 531 | _LIBCPP_INLINE_VISIBILITY |
| 532 | _T2& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 533 | get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 534 | |
| 535 | template <class _T1, class _T2> |
| 536 | static |
| 537 | _LIBCPP_INLINE_VISIBILITY |
| 538 | const _T2& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 539 | get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 540 | |
| 541 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 542 | |
| 543 | template <class _T1, class _T2> |
| 544 | static |
| 545 | _LIBCPP_INLINE_VISIBILITY |
| 546 | _T2&& |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 547 | get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 548 | |
| 549 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 550 | }; |
| 551 | |
| 552 | template <size_t _Ip, class _T1, class _T2> |
| 553 | _LIBCPP_INLINE_VISIBILITY inline |
| 554 | typename tuple_element<_Ip, pair<_T1, _T2> >::type& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 555 | get(pair<_T1, _T2>& __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 556 | { |
| 557 | return __get_pair<_Ip>::get(__p); |
| 558 | } |
| 559 | |
| 560 | template <size_t _Ip, class _T1, class _T2> |
| 561 | _LIBCPP_INLINE_VISIBILITY inline |
| 562 | const typename tuple_element<_Ip, pair<_T1, _T2> >::type& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 563 | get(const pair<_T1, _T2>& __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 564 | { |
| 565 | return __get_pair<_Ip>::get(__p); |
| 566 | } |
| 567 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 568 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 569 | |
| 570 | template <size_t _Ip, class _T1, class _T2> |
| 571 | _LIBCPP_INLINE_VISIBILITY inline |
| 572 | typename tuple_element<_Ip, pair<_T1, _T2> >::type&& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 573 | get(pair<_T1, _T2>&& __p) _NOEXCEPT |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 574 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 575 | return __get_pair<_Ip>::get(_VSTD::move(__p)); |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 579 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 580 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 581 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 582 | _LIBCPP_END_NAMESPACE_STD |
| 583 | |
| 584 | #endif // _LIBCPP_UTILITY |