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 | // |
| 6 | // This file is distributed under the University of Illinois Open Source |
| 7 | // License. See LICENSE.TXT for details. |
| 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 | < |
| 41 | !has_nothrow_move_constructor<T>::value && has_copy_constructor<T>::value, |
| 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 103 | } // std |
| 104 | |
| 105 | */ |
| 106 | |
| 107 | #include <__config> |
| 108 | #include <__tuple> |
| 109 | #include <type_traits> |
| 110 | |
| 111 | #pragma GCC system_header |
| 112 | |
| 113 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 114 | |
| 115 | namespace rel_ops |
| 116 | { |
| 117 | |
| 118 | template<class _Tp> |
| 119 | inline _LIBCPP_INLINE_VISIBILITY |
| 120 | bool |
| 121 | operator!=(const _Tp& __x, const _Tp& __y) |
| 122 | { |
| 123 | return !(__x == __y); |
| 124 | } |
| 125 | |
| 126 | template<class _Tp> |
| 127 | inline _LIBCPP_INLINE_VISIBILITY |
| 128 | bool |
| 129 | operator> (const _Tp& __x, const _Tp& __y) |
| 130 | { |
| 131 | return __y < __x; |
| 132 | } |
| 133 | |
| 134 | template<class _Tp> |
| 135 | inline _LIBCPP_INLINE_VISIBILITY |
| 136 | bool |
| 137 | operator<=(const _Tp& __x, const _Tp& __y) |
| 138 | { |
| 139 | return !(__y < __x); |
| 140 | } |
| 141 | |
| 142 | template<class _Tp> |
| 143 | inline _LIBCPP_INLINE_VISIBILITY |
| 144 | bool |
| 145 | operator>=(const _Tp& __x, const _Tp& __y) |
| 146 | { |
| 147 | return !(__x < __y); |
| 148 | } |
| 149 | |
| 150 | } // rel_ops |
| 151 | |
| 152 | // swap_ranges |
| 153 | |
| 154 | template <class _ForwardIterator1, class _ForwardIterator2> |
| 155 | inline _LIBCPP_INLINE_VISIBILITY |
| 156 | _ForwardIterator2 |
| 157 | swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) |
| 158 | { |
| 159 | for(; __first1 != __last1; ++__first1, ++__first2) |
| 160 | swap(*__first1, *__first2); |
| 161 | return __first2; |
| 162 | } |
| 163 | |
| 164 | template<class _Tp, size_t _N> |
| 165 | inline _LIBCPP_INLINE_VISIBILITY |
| 166 | void |
| 167 | swap(_Tp (&__a)[_N], _Tp (&__b)[_N]) |
| 168 | { |
| 169 | _STD::swap_ranges(__a, __a + _N, __b); |
| 170 | } |
| 171 | |
| 172 | template <class _Tp> |
| 173 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 174 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 175 | typename conditional |
| 176 | < |
| 177 | !has_nothrow_move_constructor<_Tp>::value && has_copy_constructor<_Tp>::value, |
| 178 | const _Tp&, |
| 179 | _Tp&& |
| 180 | >::type |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 181 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 182 | const _Tp& |
| 183 | #endif |
| 184 | move_if_noexcept(_Tp& __x) |
| 185 | { |
| 186 | return _STD::move(__x); |
| 187 | } |
| 188 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 189 | struct _LIBCPP_VISIBLE piecewise_construct_t { }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 190 | //constexpr |
| 191 | extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t(); |
| 192 | |
| 193 | template <class _T1, class _T2> struct pair; |
| 194 | template <class _T1, class _T2> void swap(pair<_T1, _T2>&, pair<_T1, _T2>&); |
| 195 | |
| 196 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 197 | struct _LIBCPP_VISIBLE pair |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 198 | { |
| 199 | typedef _T1 first_type; |
| 200 | typedef _T2 second_type; |
| 201 | |
| 202 | _T1 first; |
| 203 | _T2 second; |
| 204 | |
| 205 | _LIBCPP_INLINE_VISIBILITY pair() : first(), second() {} |
| 206 | |
| 207 | _LIBCPP_INLINE_VISIBILITY pair(const _T1& __x, const _T2& __y) |
| 208 | : first(__x), second(__y) {} |
| 209 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 210 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 211 | |
| 212 | template <class _U1, class _U2, |
| 213 | class = typename enable_if<is_convertible<_U1, first_type >::value && |
| 214 | is_convertible<_U2, second_type>::value>::type> |
| 215 | _LIBCPP_INLINE_VISIBILITY |
| 216 | pair(_U1&& __u1, _U2&& __u2) |
| 217 | : first(_STD::forward<_U1>(__u1)), |
| 218 | second(_STD::forward<_U2>(__u2)) |
| 219 | {} |
| 220 | |
| 221 | template<class _Tuple, |
| 222 | class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type> |
| 223 | _LIBCPP_INLINE_VISIBILITY |
| 224 | pair(_Tuple&& __p) |
| 225 | : first(_STD::forward<typename tuple_element<0, |
| 226 | typename __make_tuple_types<_Tuple>::type>::type>(get<0>(__p))), |
| 227 | second(_STD::forward<typename tuple_element<1, |
| 228 | typename __make_tuple_types<_Tuple>::type>::type>(get<1>(__p))) |
| 229 | {} |
| 230 | |
Howard Hinnant | 726a76f | 2010-11-16 21:10:23 +0000 | [diff] [blame] | 231 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 232 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 233 | template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 234 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 235 | pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, |
| 236 | tuple<_Args2...> __second_args) |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 237 | : pair(__pc, __first_args, __second_args, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 238 | typename __make_tuple_indices<sizeof...(_Args1)>::type(), |
| 239 | typename __make_tuple_indices<sizeof...(_Args2) >::type()) |
| 240 | {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 241 | |
Howard Hinnant | 726a76f | 2010-11-16 21:10:23 +0000 | [diff] [blame] | 242 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 243 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 244 | template <class _Tuple, |
| 245 | class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 246 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 247 | pair& |
| 248 | operator=(_Tuple&& __p) |
| 249 | { |
| 250 | typedef typename __make_tuple_types<_Tuple>::type _TupleRef; |
| 251 | typedef typename tuple_element<0, _TupleRef>::type _U0; |
| 252 | typedef typename tuple_element<1, _TupleRef>::type _U1; |
| 253 | first = _STD::forward<_U0>(_STD::get<0>(__p)); |
| 254 | second = _STD::forward<_U1>(_STD::get<1>(__p)); |
| 255 | return *this; |
| 256 | } |
| 257 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 258 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 259 | template<class _U1, class _U2> |
| 260 | _LIBCPP_INLINE_VISIBILITY pair(const pair<_U1, _U2>& __p) |
| 261 | : first(__p.first), second(__p.second) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 262 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 263 | void _LIBCPP_INLINE_VISIBILITY swap(pair& __p) {_STD::swap(*this, __p);} |
| 264 | private: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 265 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 266 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 267 | template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> |
| 268 | pair(piecewise_construct_t, |
| 269 | tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, |
| 270 | __tuple_indices<_I1...>, __tuple_indices<_I2...>); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 271 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 272 | }; |
| 273 | |
| 274 | template <class _T1, class _T2> |
| 275 | inline _LIBCPP_INLINE_VISIBILITY |
| 276 | bool |
| 277 | operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 278 | { |
| 279 | return __x.first == __y.first && __x.second == __y.second; |
| 280 | } |
| 281 | |
| 282 | template <class _T1, class _T2> |
| 283 | inline _LIBCPP_INLINE_VISIBILITY |
| 284 | bool |
| 285 | operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 286 | { |
| 287 | return !(__x == __y); |
| 288 | } |
| 289 | |
| 290 | template <class _T1, class _T2> |
| 291 | inline _LIBCPP_INLINE_VISIBILITY |
| 292 | bool |
| 293 | operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 294 | { |
| 295 | return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second); |
| 296 | } |
| 297 | |
| 298 | template <class _T1, class _T2> |
| 299 | inline _LIBCPP_INLINE_VISIBILITY |
| 300 | bool |
| 301 | operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 302 | { |
| 303 | return __y < __x; |
| 304 | } |
| 305 | |
| 306 | template <class _T1, class _T2> |
| 307 | inline _LIBCPP_INLINE_VISIBILITY |
| 308 | bool |
| 309 | operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 310 | { |
| 311 | return !(__x < __y); |
| 312 | } |
| 313 | |
| 314 | template <class _T1, class _T2> |
| 315 | inline _LIBCPP_INLINE_VISIBILITY |
| 316 | bool |
| 317 | operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 318 | { |
| 319 | return !(__y < __x); |
| 320 | } |
| 321 | |
| 322 | template <class _T1, class _T2> |
| 323 | inline _LIBCPP_INLINE_VISIBILITY |
| 324 | void |
| 325 | swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) |
| 326 | { |
| 327 | swap(__x.first, __y.first); |
| 328 | swap(__x.second, __y.second); |
| 329 | } |
| 330 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 331 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 332 | |
| 333 | template <class _Tp> class reference_wrapper; |
| 334 | |
| 335 | template <class _Tp> |
| 336 | struct ___make_pair_return |
| 337 | { |
| 338 | typedef _Tp type; |
| 339 | }; |
| 340 | |
| 341 | template <class _Tp> |
| 342 | struct ___make_pair_return<reference_wrapper<_Tp>> |
| 343 | { |
| 344 | typedef _Tp& type; |
| 345 | }; |
| 346 | |
| 347 | template <class _Tp> |
| 348 | struct __make_pair_return |
| 349 | { |
| 350 | typedef typename ___make_pair_return<typename decay<_Tp>::type>::type type; |
| 351 | }; |
| 352 | |
| 353 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 354 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 355 | pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type> |
| 356 | make_pair(_T1&& __t1, _T2&& __t2) |
| 357 | { |
| 358 | return pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type> |
| 359 | (_STD::forward<_T1>(__t1), _STD::forward<_T2>(__t2)); |
| 360 | } |
| 361 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 362 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 363 | |
| 364 | template <class _T1, class _T2> |
| 365 | inline _LIBCPP_INLINE_VISIBILITY |
| 366 | pair<_T1,_T2> |
| 367 | make_pair(_T1 __x, _T2 __y) |
| 368 | { |
| 369 | return pair<_T1, _T2>(__x, __y); |
| 370 | } |
| 371 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 372 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 373 | |
| 374 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 375 | |
| 376 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 377 | class _LIBCPP_VISIBLE tuple_size<pair<_T1, _T2> > |
| 378 | : public integral_constant<size_t, 2> {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 379 | |
| 380 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 381 | class _LIBCPP_VISIBLE tuple_size<const pair<_T1, _T2> > |
| 382 | : public integral_constant<size_t, 2> {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 383 | |
| 384 | template <class _T1, class _T2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 385 | class _LIBCPP_VISIBLE tuple_element<0, pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 386 | { |
| 387 | public: |
| 388 | typedef _T1 type; |
| 389 | }; |
| 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<1, pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 393 | { |
| 394 | public: |
| 395 | typedef _T2 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<0, const pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 400 | { |
| 401 | public: |
| 402 | typedef const _T1 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<1, const pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 407 | { |
| 408 | public: |
| 409 | typedef const _T2 type; |
| 410 | }; |
| 411 | |
| 412 | template <size_t _Ip> struct __get_pair; |
| 413 | |
| 414 | template <> |
| 415 | struct __get_pair<0> |
| 416 | { |
| 417 | template <class _T1, class _T2> |
| 418 | static |
| 419 | _LIBCPP_INLINE_VISIBILITY |
| 420 | _T1& |
| 421 | get(pair<_T1, _T2>& __p) {return __p.first;} |
| 422 | |
| 423 | template <class _T1, class _T2> |
| 424 | static |
| 425 | _LIBCPP_INLINE_VISIBILITY |
| 426 | const _T1& |
| 427 | get(const pair<_T1, _T2>& __p) {return __p.first;} |
| 428 | }; |
| 429 | |
| 430 | template <> |
| 431 | struct __get_pair<1> |
| 432 | { |
| 433 | template <class _T1, class _T2> |
| 434 | static |
| 435 | _LIBCPP_INLINE_VISIBILITY |
| 436 | _T2& |
| 437 | get(pair<_T1, _T2>& __p) {return __p.second;} |
| 438 | |
| 439 | template <class _T1, class _T2> |
| 440 | static |
| 441 | _LIBCPP_INLINE_VISIBILITY |
| 442 | const _T2& |
| 443 | get(const pair<_T1, _T2>& __p) {return __p.second;} |
| 444 | }; |
| 445 | |
| 446 | template <size_t _Ip, class _T1, class _T2> |
| 447 | _LIBCPP_INLINE_VISIBILITY inline |
| 448 | typename tuple_element<_Ip, pair<_T1, _T2> >::type& |
| 449 | get(pair<_T1, _T2>& __p) |
| 450 | { |
| 451 | return __get_pair<_Ip>::get(__p); |
| 452 | } |
| 453 | |
| 454 | template <size_t _Ip, class _T1, class _T2> |
| 455 | _LIBCPP_INLINE_VISIBILITY inline |
| 456 | const typename tuple_element<_Ip, pair<_T1, _T2> >::type& |
| 457 | get(const pair<_T1, _T2>& __p) |
| 458 | { |
| 459 | return __get_pair<_Ip>::get(__p); |
| 460 | } |
| 461 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 462 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 463 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 464 | _LIBCPP_END_NAMESPACE_STD |
| 465 | |
| 466 | #endif // _LIBCPP_UTILITY |