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 | { |
| 186 | _STD::swap_ranges(__a, __a + _N, __b); |
| 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 | { |
| 203 | return _STD::move(__x); |
| 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, |
| 230 | typename enable_if<is_convertible<_U1, _T1>::value && |
| 231 | is_convertible<_U2, _T2>::value>::type* = 0) |
| 232 | : first(__p.first), second(__p.second) {} |
| 233 | |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 234 | _LIBCPP_INLINE_VISIBILITY |
| 235 | pair& operator=(const pair& __p) |
| 236 | { |
| 237 | first = __p.first; |
| 238 | second = __p.second; |
| 239 | return *this; |
| 240 | } |
| 241 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 242 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 243 | |
| 244 | template <class _U1, class _U2, |
| 245 | class = typename enable_if<is_convertible<_U1, first_type >::value && |
| 246 | is_convertible<_U2, second_type>::value>::type> |
| 247 | _LIBCPP_INLINE_VISIBILITY |
| 248 | pair(_U1&& __u1, _U2&& __u2) |
| 249 | : first(_STD::forward<_U1>(__u1)), |
| 250 | second(_STD::forward<_U2>(__u2)) |
| 251 | {} |
| 252 | |
Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 253 | template<class _U1, class _U2> |
| 254 | _LIBCPP_INLINE_VISIBILITY |
| 255 | pair(pair<_U1, _U2>&& __p, |
| 256 | typename enable_if<is_convertible<_U1, _T1>::value && |
| 257 | is_convertible<_U2, _T2>::value>::type* = 0) |
| 258 | : first(_STD::forward<_U1>(__p.first)), |
| 259 | second(_STD::forward<_U2>(__p.second)) {} |
| 260 | |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 261 | _LIBCPP_INLINE_VISIBILITY |
| 262 | pair& |
| 263 | operator=(pair&& __p) _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value && |
| 264 | is_nothrow_move_assignable<second_type>::value) |
| 265 | { |
| 266 | first = _STD::forward<first_type>(__p.first); |
| 267 | second = _STD::forward<second_type>(__p.second); |
| 268 | return *this; |
| 269 | } |
| 270 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 271 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 272 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 273 | template<class _Tuple, |
| 274 | class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type> |
| 275 | _LIBCPP_INLINE_VISIBILITY |
| 276 | pair(_Tuple&& __p) |
| 277 | : first(_STD::forward<typename tuple_element<0, |
| 278 | typename __make_tuple_types<_Tuple>::type>::type>(get<0>(__p))), |
| 279 | second(_STD::forward<typename tuple_element<1, |
| 280 | typename __make_tuple_types<_Tuple>::type>::type>(get<1>(__p))) |
| 281 | {} |
| 282 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 283 | |
Howard Hinnant | 726a76f | 2010-11-16 21:10:23 +0000 | [diff] [blame] | 284 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 285 | template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 286 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 287 | pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, |
| 288 | tuple<_Args2...> __second_args) |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 289 | : pair(__pc, __first_args, __second_args, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 290 | typename __make_tuple_indices<sizeof...(_Args1)>::type(), |
| 291 | typename __make_tuple_indices<sizeof...(_Args2) >::type()) |
| 292 | {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 293 | |
| 294 | template <class _Tuple, |
| 295 | class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 296 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 297 | pair& |
| 298 | operator=(_Tuple&& __p) |
| 299 | { |
| 300 | typedef typename __make_tuple_types<_Tuple>::type _TupleRef; |
| 301 | typedef typename tuple_element<0, _TupleRef>::type _U0; |
| 302 | typedef typename tuple_element<1, _TupleRef>::type _U1; |
| 303 | first = _STD::forward<_U0>(_STD::get<0>(__p)); |
| 304 | second = _STD::forward<_U1>(_STD::get<1>(__p)); |
| 305 | return *this; |
| 306 | } |
| 307 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 308 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 309 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 310 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 311 | _LIBCPP_INLINE_VISIBILITY |
| 312 | void |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 313 | swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value && |
| 314 | __is_nothrow_swappable<second_type>::value) |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 315 | { |
| 316 | _STD::iter_swap(&first, &__p.first); |
| 317 | _STD::iter_swap(&second, &__p.second); |
| 318 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 319 | private: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 320 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 321 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 322 | template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> |
Howard Hinnant | 5f5859c | 2011-01-13 20:05:05 +0000 | [diff] [blame] | 323 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 324 | pair(piecewise_construct_t, |
| 325 | tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, |
| 326 | __tuple_indices<_I1...>, __tuple_indices<_I2...>); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 327 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 328 | }; |
| 329 | |
| 330 | template <class _T1, class _T2> |
| 331 | inline _LIBCPP_INLINE_VISIBILITY |
| 332 | bool |
| 333 | operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 334 | { |
| 335 | return __x.first == __y.first && __x.second == __y.second; |
| 336 | } |
| 337 | |
| 338 | template <class _T1, class _T2> |
| 339 | inline _LIBCPP_INLINE_VISIBILITY |
| 340 | bool |
| 341 | operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 342 | { |
| 343 | return !(__x == __y); |
| 344 | } |
| 345 | |
| 346 | template <class _T1, class _T2> |
| 347 | inline _LIBCPP_INLINE_VISIBILITY |
| 348 | bool |
| 349 | operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 350 | { |
| 351 | return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second); |
| 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 __y < __x; |
| 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 !(__y < __x); |
| 376 | } |
| 377 | |
| 378 | template <class _T1, class _T2> |
| 379 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aabf287 | 2011-06-01 19:59:32 +0000 | [diff] [blame^] | 380 | typename enable_if |
| 381 | < |
| 382 | __is_swappable<_T1>::value && |
| 383 | __is_swappable<_T2>::value, |
| 384 | void |
| 385 | >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 386 | swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 387 | _NOEXCEPT_((__is_nothrow_swappable<_T1>::value && |
| 388 | __is_nothrow_swappable<_T2>::value)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 389 | { |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 390 | __x.swap(__y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 393 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 394 | |
| 395 | template <class _Tp> class reference_wrapper; |
| 396 | |
| 397 | template <class _Tp> |
| 398 | struct ___make_pair_return |
| 399 | { |
| 400 | typedef _Tp type; |
| 401 | }; |
| 402 | |
| 403 | template <class _Tp> |
| 404 | struct ___make_pair_return<reference_wrapper<_Tp>> |
| 405 | { |
| 406 | typedef _Tp& type; |
| 407 | }; |
| 408 | |
| 409 | template <class _Tp> |
| 410 | struct __make_pair_return |
| 411 | { |
| 412 | typedef typename ___make_pair_return<typename decay<_Tp>::type>::type type; |
| 413 | }; |
| 414 | |
| 415 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 416 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 417 | pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type> |
| 418 | make_pair(_T1&& __t1, _T2&& __t2) |
| 419 | { |
| 420 | return pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type> |
| 421 | (_STD::forward<_T1>(__t1), _STD::forward<_T2>(__t2)); |
| 422 | } |
| 423 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 424 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 425 | |
| 426 | template <class _T1, class _T2> |
| 427 | inline _LIBCPP_INLINE_VISIBILITY |
| 428 | pair<_T1,_T2> |
| 429 | make_pair(_T1 __x, _T2 __y) |
| 430 | { |
| 431 | return pair<_T1, _T2>(__x, __y); |
| 432 | } |
| 433 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 434 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 435 | |
| 436 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 437 | |
| 438 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 439 | class _LIBCPP_VISIBLE tuple_size<pair<_T1, _T2> > |
| 440 | : public integral_constant<size_t, 2> {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 441 | |
| 442 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 443 | class _LIBCPP_VISIBLE tuple_size<const pair<_T1, _T2> > |
| 444 | : public integral_constant<size_t, 2> {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 445 | |
| 446 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 447 | class _LIBCPP_VISIBLE tuple_element<0, pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 448 | { |
| 449 | public: |
| 450 | typedef _T1 type; |
| 451 | }; |
| 452 | |
| 453 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 454 | class _LIBCPP_VISIBLE tuple_element<1, pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 455 | { |
| 456 | public: |
| 457 | typedef _T2 type; |
| 458 | }; |
| 459 | |
| 460 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 461 | class _LIBCPP_VISIBLE tuple_element<0, const pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 462 | { |
| 463 | public: |
| 464 | typedef const _T1 type; |
| 465 | }; |
| 466 | |
| 467 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 468 | class _LIBCPP_VISIBLE tuple_element<1, const pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 469 | { |
| 470 | public: |
| 471 | typedef const _T2 type; |
| 472 | }; |
| 473 | |
| 474 | template <size_t _Ip> struct __get_pair; |
| 475 | |
| 476 | template <> |
| 477 | struct __get_pair<0> |
| 478 | { |
| 479 | template <class _T1, class _T2> |
| 480 | static |
| 481 | _LIBCPP_INLINE_VISIBILITY |
| 482 | _T1& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 483 | get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 484 | |
| 485 | template <class _T1, class _T2> |
| 486 | static |
| 487 | _LIBCPP_INLINE_VISIBILITY |
| 488 | const _T1& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 489 | get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 490 | |
| 491 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 492 | |
| 493 | template <class _T1, class _T2> |
| 494 | static |
| 495 | _LIBCPP_INLINE_VISIBILITY |
| 496 | _T1&& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 497 | get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _STD::forward<_T1>(__p.first);} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 498 | |
| 499 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 500 | }; |
| 501 | |
| 502 | template <> |
| 503 | struct __get_pair<1> |
| 504 | { |
| 505 | template <class _T1, class _T2> |
| 506 | static |
| 507 | _LIBCPP_INLINE_VISIBILITY |
| 508 | _T2& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 509 | get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 510 | |
| 511 | template <class _T1, class _T2> |
| 512 | static |
| 513 | _LIBCPP_INLINE_VISIBILITY |
| 514 | const _T2& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 515 | get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 516 | |
| 517 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 518 | |
| 519 | template <class _T1, class _T2> |
| 520 | static |
| 521 | _LIBCPP_INLINE_VISIBILITY |
| 522 | _T2&& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 523 | get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _STD::forward<_T2>(__p.second);} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 524 | |
| 525 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 526 | }; |
| 527 | |
| 528 | template <size_t _Ip, class _T1, class _T2> |
| 529 | _LIBCPP_INLINE_VISIBILITY inline |
| 530 | typename tuple_element<_Ip, pair<_T1, _T2> >::type& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 531 | get(pair<_T1, _T2>& __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 532 | { |
| 533 | return __get_pair<_Ip>::get(__p); |
| 534 | } |
| 535 | |
| 536 | template <size_t _Ip, class _T1, class _T2> |
| 537 | _LIBCPP_INLINE_VISIBILITY inline |
| 538 | const typename tuple_element<_Ip, pair<_T1, _T2> >::type& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 539 | get(const pair<_T1, _T2>& __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 540 | { |
| 541 | return __get_pair<_Ip>::get(__p); |
| 542 | } |
| 543 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 544 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 545 | |
| 546 | template <size_t _Ip, class _T1, class _T2> |
| 547 | _LIBCPP_INLINE_VISIBILITY inline |
| 548 | typename tuple_element<_Ip, pair<_T1, _T2> >::type&& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 549 | get(pair<_T1, _T2>&& __p) _NOEXCEPT |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 550 | { |
| 551 | return __get_pair<_Ip>::get(_STD::move(__p)); |
| 552 | } |
| 553 | |
| 554 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 555 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 556 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 557 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 558 | _LIBCPP_END_NAMESPACE_STD |
| 559 | |
| 560 | #endif // _LIBCPP_UTILITY |