blob: 1d1b579897e097cc3e95045a358fde3f97db5231 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- utility -----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_UTILITY
12#define _LIBCPP_UTILITY
13
14/*
15 utility synopsis
16
17namespace std
18{
19
20template <class T>
21 void
22 swap(T& a, T& b);
23
24namespace 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 Hinnante9b2c2d2011-05-27 15:04:19 +000032template<class T>
33void
34swap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value &&
35 is_nothrow_move_assignable<T>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000036
Howard Hinnante9b2c2d2011-05-27 15:04:19 +000037template <class T, size_t N>
38void
39swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)));
40
41template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept;
42template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept;
43
44template <class T> typename remove_reference<T>::type&& move(T&&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000045
46template <class T>
47 typename conditional
48 <
Howard Hinnant1468b662010-11-19 22:17:28 +000049 !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000050 const T&,
51 T&&
52 >::type
Howard Hinnante9b2c2d2011-05-27 15:04:19 +000053 move_if_noexcept(T& x) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000054
55template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
56
57template <class T1, class T2>
58struct 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 Hinnante9b2c2d2011-05-27 15:04:19 +000067 pair(pair&&) = default;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000068 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 Hinnante9b2c2d2011-05-27 15:04:19 +000078 pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value &&
79 is_nothrow_move_assignable<T2>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000080 template <class U, class V> pair& operator=(pair<U, V>&& p);
81
Howard Hinnante9b2c2d2011-05-27 15:04:19 +000082 void swap(pair& p) noexcept(noexcept(swap(first, p.first)) &&
83 noexcept(swap(second, p.second)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000084};
85
86template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&);
87template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&);
88template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&);
89template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&);
90template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&);
91template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&);
92
93template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&);
Howard Hinnante9b2c2d2011-05-27 15:04:19 +000094template <class T1, class T2>
95void
96swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000097
98struct piecewise_construct_t { };
99constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
100
101template <class T> class tuple_size;
102template <size_t I, class T> class tuple_element;
103
104template <class T1, class T2> struct tuple_size<std::pair<T1, T2> >;
105template <class T1, class T2> struct tuple_element<0, std::pair<T1, T2> >;
106template <class T1, class T2> struct tuple_element<1, std::pair<T1, T2> >;
107
108template<size_t I, class T1, class T2>
109 typename tuple_element<I, std::pair<T1, T2> >::type&
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000110 get(std::pair<T1, T2>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000111
112template<size_t I, class T1, class T2>
113 const typename const tuple_element<I, std::pair<T1, T2> >::type&
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000114 get(const std::pair<T1, T2>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000115
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000116template<size_t I, class T1, class T2>
117 typename tuple_element<I, std::pair<T1, T2> >::type&&
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000118 get(std::pair<T1, T2>&&) noexcept;
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000119
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120} // 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
132namespace rel_ops
133{
134
135template<class _Tp>
136inline _LIBCPP_INLINE_VISIBILITY
137bool
138operator!=(const _Tp& __x, const _Tp& __y)
139{
140 return !(__x == __y);
141}
142
143template<class _Tp>
144inline _LIBCPP_INLINE_VISIBILITY
145bool
146operator> (const _Tp& __x, const _Tp& __y)
147{
148 return __y < __x;
149}
150
151template<class _Tp>
152inline _LIBCPP_INLINE_VISIBILITY
153bool
154operator<=(const _Tp& __x, const _Tp& __y)
155{
156 return !(__y < __x);
157}
158
159template<class _Tp>
160inline _LIBCPP_INLINE_VISIBILITY
161bool
162operator>=(const _Tp& __x, const _Tp& __y)
163{
164 return !(__x < __y);
165}
166
167} // rel_ops
168
169// swap_ranges
170
171template <class _ForwardIterator1, class _ForwardIterator2>
172inline _LIBCPP_INLINE_VISIBILITY
173_ForwardIterator2
174swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
175{
176 for(; __first1 != __last1; ++__first1, ++__first2)
177 swap(*__first1, *__first2);
178 return __first2;
179}
180
181template<class _Tp, size_t _N>
182inline _LIBCPP_INLINE_VISIBILITY
183void
184swap(_Tp (&__a)[_N], _Tp (&__b)[_N])
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000185 _NOEXCEPT_(_NOEXCEPT_(swap(_STD::declval<_Tp&>(), _STD::declval<_Tp&>())))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000186{
187 _STD::swap_ranges(__a, __a + _N, __b);
188}
189
190template <class _Tp>
191inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant73d21a42010-09-04 23:28:19 +0000192#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000193typename conditional
194<
Howard Hinnant1468b662010-11-19 22:17:28 +0000195 !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000196 const _Tp&,
197 _Tp&&
198>::type
Howard Hinnant73d21a42010-09-04 23:28:19 +0000199#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000200const _Tp&
201#endif
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000202move_if_noexcept(_Tp& __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000203{
204 return _STD::move(__x);
205}
206
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000207struct _LIBCPP_VISIBLE piecewise_construct_t { };
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000208//constexpr
209extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
210
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000211template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000212struct _LIBCPP_VISIBLE pair
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000213{
214 typedef _T1 first_type;
215 typedef _T2 second_type;
216
217 _T1 first;
218 _T2 second;
219
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000220 // pair(const pair&) = default;
221 // pair(pair&&) = default;
222
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000223 _LIBCPP_INLINE_VISIBILITY pair() : first(), second() {}
224
225 _LIBCPP_INLINE_VISIBILITY pair(const _T1& __x, const _T2& __y)
226 : first(__x), second(__y) {}
227
Howard Hinnant469d4192011-04-29 18:10:55 +0000228 template<class _U1, class _U2>
229 _LIBCPP_INLINE_VISIBILITY
230 pair(const pair<_U1, _U2>& __p,
231 typename enable_if<is_convertible<_U1, _T1>::value &&
232 is_convertible<_U2, _T2>::value>::type* = 0)
233 : first(__p.first), second(__p.second) {}
234
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000235 _LIBCPP_INLINE_VISIBILITY
236 pair& operator=(const pair& __p)
237 {
238 first = __p.first;
239 second = __p.second;
240 return *this;
241 }
242
Howard Hinnant73d21a42010-09-04 23:28:19 +0000243#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000244
245 template <class _U1, class _U2,
246 class = typename enable_if<is_convertible<_U1, first_type >::value &&
247 is_convertible<_U2, second_type>::value>::type>
248 _LIBCPP_INLINE_VISIBILITY
249 pair(_U1&& __u1, _U2&& __u2)
250 : first(_STD::forward<_U1>(__u1)),
251 second(_STD::forward<_U2>(__u2))
252 {}
253
Howard Hinnant469d4192011-04-29 18:10:55 +0000254 template<class _U1, class _U2>
255 _LIBCPP_INLINE_VISIBILITY
256 pair(pair<_U1, _U2>&& __p,
257 typename enable_if<is_convertible<_U1, _T1>::value &&
258 is_convertible<_U2, _T2>::value>::type* = 0)
259 : first(_STD::forward<_U1>(__p.first)),
260 second(_STD::forward<_U2>(__p.second)) {}
261
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000262 _LIBCPP_INLINE_VISIBILITY
263 pair&
264 operator=(pair&& __p) _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value &&
265 is_nothrow_move_assignable<second_type>::value)
266 {
267 first = _STD::forward<first_type>(__p.first);
268 second = _STD::forward<second_type>(__p.second);
269 return *this;
270 }
271
Michael J. Spencer626916f2010-12-10 19:47:54 +0000272#ifndef _LIBCPP_HAS_NO_VARIADICS
273
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000274 template<class _Tuple,
275 class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type>
276 _LIBCPP_INLINE_VISIBILITY
277 pair(_Tuple&& __p)
278 : first(_STD::forward<typename tuple_element<0,
279 typename __make_tuple_types<_Tuple>::type>::type>(get<0>(__p))),
280 second(_STD::forward<typename tuple_element<1,
281 typename __make_tuple_types<_Tuple>::type>::type>(get<1>(__p)))
282 {}
283
Michael J. Spencer626916f2010-12-10 19:47:54 +0000284
Howard Hinnant726a76f2010-11-16 21:10:23 +0000285
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000286 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000287 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000288 pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
289 tuple<_Args2...> __second_args)
Howard Hinnant324bb032010-08-22 00:02:43 +0000290 : pair(__pc, __first_args, __second_args,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000291 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
292 typename __make_tuple_indices<sizeof...(_Args2) >::type())
293 {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000294
295 template <class _Tuple,
296 class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000297 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000298 pair&
299 operator=(_Tuple&& __p)
300 {
301 typedef typename __make_tuple_types<_Tuple>::type _TupleRef;
302 typedef typename tuple_element<0, _TupleRef>::type _U0;
303 typedef typename tuple_element<1, _TupleRef>::type _U1;
304 first = _STD::forward<_U0>(_STD::get<0>(__p));
305 second = _STD::forward<_U1>(_STD::get<1>(__p));
306 return *this;
307 }
308
Michael J. Spencer626916f2010-12-10 19:47:54 +0000309#endif // _LIBCPP_HAS_NO_VARIADICS
310
Howard Hinnant73d21a42010-09-04 23:28:19 +0000311#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000312 _LIBCPP_INLINE_VISIBILITY
313 void
314 swap(pair& __p) _NOEXCEPT_(
315// _NOEXCEPT_(_STD::iter_swap(&first, &__p.first)) &&
316// _NOEXCEPT_(_STD::iter_swap(&second, &__p.second)))
317 _NOEXCEPT_(_STD::iter_swap(&_STD::declval<first_type&>(),
318 &_STD::declval<first_type&>())) &&
319 _NOEXCEPT_(_STD::iter_swap(&_STD::declval<second_type&>(),
320 &_STD::declval<second_type&>())))
321 {
322 _STD::iter_swap(&first, &__p.first);
323 _STD::iter_swap(&second, &__p.second);
324 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000325private:
Howard Hinnant324bb032010-08-22 00:02:43 +0000326
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327#ifndef _LIBCPP_HAS_NO_VARIADICS
328 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
Howard Hinnant5f5859c2011-01-13 20:05:05 +0000329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000330 pair(piecewise_construct_t,
331 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
332 __tuple_indices<_I1...>, __tuple_indices<_I2...>);
Howard Hinnant324bb032010-08-22 00:02:43 +0000333#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000334};
335
336template <class _T1, class _T2>
337inline _LIBCPP_INLINE_VISIBILITY
338bool
339operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
340{
341 return __x.first == __y.first && __x.second == __y.second;
342}
343
344template <class _T1, class _T2>
345inline _LIBCPP_INLINE_VISIBILITY
346bool
347operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
348{
349 return !(__x == __y);
350}
351
352template <class _T1, class _T2>
353inline _LIBCPP_INLINE_VISIBILITY
354bool
355operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
356{
357 return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);
358}
359
360template <class _T1, class _T2>
361inline _LIBCPP_INLINE_VISIBILITY
362bool
363operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
364{
365 return __y < __x;
366}
367
368template <class _T1, class _T2>
369inline _LIBCPP_INLINE_VISIBILITY
370bool
371operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
372{
373 return !(__x < __y);
374}
375
376template <class _T1, class _T2>
377inline _LIBCPP_INLINE_VISIBILITY
378bool
379operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
380{
381 return !(__y < __x);
382}
383
384template <class _T1, class _T2>
385inline _LIBCPP_INLINE_VISIBILITY
386void
387swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000388// _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
389 _NOEXCEPT_(_NOEXCEPT_((_STD::declval<pair<_T1, _T2>&>().swap(_STD::declval<pair<_T1, _T2>&>()))))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000390{
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000391 __x.swap(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000392}
393
Howard Hinnant73d21a42010-09-04 23:28:19 +0000394#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000395
396template <class _Tp> class reference_wrapper;
397
398template <class _Tp>
399struct ___make_pair_return
400{
401 typedef _Tp type;
402};
403
404template <class _Tp>
405struct ___make_pair_return<reference_wrapper<_Tp>>
406{
407 typedef _Tp& type;
408};
409
410template <class _Tp>
411struct __make_pair_return
412{
413 typedef typename ___make_pair_return<typename decay<_Tp>::type>::type type;
414};
415
416template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000417inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000418pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
419make_pair(_T1&& __t1, _T2&& __t2)
420{
421 return pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
422 (_STD::forward<_T1>(__t1), _STD::forward<_T2>(__t2));
423}
424
Howard Hinnant73d21a42010-09-04 23:28:19 +0000425#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000426
427template <class _T1, class _T2>
428inline _LIBCPP_INLINE_VISIBILITY
429pair<_T1,_T2>
430make_pair(_T1 __x, _T2 __y)
431{
432 return pair<_T1, _T2>(__x, __y);
433}
434
Howard Hinnant73d21a42010-09-04 23:28:19 +0000435#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000436
437#ifndef _LIBCPP_HAS_NO_VARIADICS
438
439template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000440 class _LIBCPP_VISIBLE tuple_size<pair<_T1, _T2> >
441 : public integral_constant<size_t, 2> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000442
443template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000444 class _LIBCPP_VISIBLE tuple_size<const pair<_T1, _T2> >
445 : public integral_constant<size_t, 2> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000446
447template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000448class _LIBCPP_VISIBLE tuple_element<0, pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000449{
450public:
451 typedef _T1 type;
452};
453
454template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000455class _LIBCPP_VISIBLE tuple_element<1, pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000456{
457public:
458 typedef _T2 type;
459};
460
461template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000462class _LIBCPP_VISIBLE tuple_element<0, const pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000463{
464public:
465 typedef const _T1 type;
466};
467
468template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000469class _LIBCPP_VISIBLE tuple_element<1, const pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470{
471public:
472 typedef const _T2 type;
473};
474
475template <size_t _Ip> struct __get_pair;
476
477template <>
478struct __get_pair<0>
479{
480 template <class _T1, class _T2>
481 static
482 _LIBCPP_INLINE_VISIBILITY
483 _T1&
484 get(pair<_T1, _T2>& __p) {return __p.first;}
485
486 template <class _T1, class _T2>
487 static
488 _LIBCPP_INLINE_VISIBILITY
489 const _T1&
490 get(const pair<_T1, _T2>& __p) {return __p.first;}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000491
492#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
493
494 template <class _T1, class _T2>
495 static
496 _LIBCPP_INLINE_VISIBILITY
497 _T1&&
498 get(pair<_T1, _T2>&& __p) {return _STD::forward<_T1>(__p.first);}
499
500#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501};
502
503template <>
504struct __get_pair<1>
505{
506 template <class _T1, class _T2>
507 static
508 _LIBCPP_INLINE_VISIBILITY
509 _T2&
510 get(pair<_T1, _T2>& __p) {return __p.second;}
511
512 template <class _T1, class _T2>
513 static
514 _LIBCPP_INLINE_VISIBILITY
515 const _T2&
516 get(const pair<_T1, _T2>& __p) {return __p.second;}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000517
518#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
519
520 template <class _T1, class _T2>
521 static
522 _LIBCPP_INLINE_VISIBILITY
523 _T2&&
524 get(pair<_T1, _T2>&& __p) {return _STD::forward<_T2>(__p.second);}
525
526#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000527};
528
529template <size_t _Ip, class _T1, class _T2>
530_LIBCPP_INLINE_VISIBILITY inline
531typename tuple_element<_Ip, pair<_T1, _T2> >::type&
532get(pair<_T1, _T2>& __p)
533{
534 return __get_pair<_Ip>::get(__p);
535}
536
537template <size_t _Ip, class _T1, class _T2>
538_LIBCPP_INLINE_VISIBILITY inline
539const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
540get(const pair<_T1, _T2>& __p)
541{
542 return __get_pair<_Ip>::get(__p);
543}
544
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000545#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
546
547template <size_t _Ip, class _T1, class _T2>
548_LIBCPP_INLINE_VISIBILITY inline
549typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
550get(pair<_T1, _T2>&& __p)
551{
552 return __get_pair<_Ip>::get(_STD::move(__p));
553}
554
555#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
556
Howard Hinnant324bb032010-08-22 00:02:43 +0000557#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000558
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000559_LIBCPP_END_NAMESPACE_STD
560
561#endif // _LIBCPP_UTILITY