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