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