blob: 6934c1e08d94d61b9964ae13e8218514544d2d2e [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
Howard Hinnanta5e01212011-05-27 19:08:18 +0000184swap(_Tp (&__a)[_N], _Tp (&__b)[_N]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000185{
186 _STD::swap_ranges(__a, __a + _N, __b);
187}
188
189template <class _Tp>
190inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant73d21a42010-09-04 23:28:19 +0000191#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000192typename conditional
193<
Howard Hinnant1468b662010-11-19 22:17:28 +0000194 !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000195 const _Tp&,
196 _Tp&&
197>::type
Howard Hinnant73d21a42010-09-04 23:28:19 +0000198#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000199const _Tp&
200#endif
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000201move_if_noexcept(_Tp& __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000202{
203 return _STD::move(__x);
204}
205
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000206struct _LIBCPP_VISIBLE piecewise_construct_t { };
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000207//constexpr
208extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
209
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000210template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000211struct _LIBCPP_VISIBLE pair
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000212{
213 typedef _T1 first_type;
214 typedef _T2 second_type;
215
216 _T1 first;
217 _T2 second;
218
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000219 // pair(const pair&) = default;
220 // pair(pair&&) = default;
221
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000222 _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 Hinnant469d4192011-04-29 18:10:55 +0000227 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 Hinnante9b2c2d2011-05-27 15:04:19 +0000234 _LIBCPP_INLINE_VISIBILITY
235 pair& operator=(const pair& __p)
236 {
237 first = __p.first;
238 second = __p.second;
239 return *this;
240 }
241
Howard Hinnant73d21a42010-09-04 23:28:19 +0000242#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000243
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 Hinnant469d4192011-04-29 18:10:55 +0000253 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 Hinnante9b2c2d2011-05-27 15:04:19 +0000261 _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. Spencer626916f2010-12-10 19:47:54 +0000271#ifndef _LIBCPP_HAS_NO_VARIADICS
272
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000273 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. Spencer626916f2010-12-10 19:47:54 +0000283
Howard Hinnant726a76f2010-11-16 21:10:23 +0000284
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000285 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000287 pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
288 tuple<_Args2...> __second_args)
Howard Hinnant324bb032010-08-22 00:02:43 +0000289 : pair(__pc, __first_args, __second_args,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000290 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
291 typename __make_tuple_indices<sizeof...(_Args2) >::type())
292 {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000293
294 template <class _Tuple,
295 class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000296 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000297 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. Spencer626916f2010-12-10 19:47:54 +0000308#endif // _LIBCPP_HAS_NO_VARIADICS
309
Howard Hinnant73d21a42010-09-04 23:28:19 +0000310#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000311 _LIBCPP_INLINE_VISIBILITY
312 void
Howard Hinnanta5e01212011-05-27 19:08:18 +0000313 swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value &&
314 __is_nothrow_swappable<second_type>::value)
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000315 {
316 _STD::iter_swap(&first, &__p.first);
317 _STD::iter_swap(&second, &__p.second);
318 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000319private:
Howard Hinnant324bb032010-08-22 00:02:43 +0000320
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000321#ifndef _LIBCPP_HAS_NO_VARIADICS
322 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
Howard Hinnant5f5859c2011-01-13 20:05:05 +0000323 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000324 pair(piecewise_construct_t,
325 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
326 __tuple_indices<_I1...>, __tuple_indices<_I2...>);
Howard Hinnant324bb032010-08-22 00:02:43 +0000327#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000328};
329
330template <class _T1, class _T2>
331inline _LIBCPP_INLINE_VISIBILITY
332bool
333operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
334{
335 return __x.first == __y.first && __x.second == __y.second;
336}
337
338template <class _T1, class _T2>
339inline _LIBCPP_INLINE_VISIBILITY
340bool
341operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
342{
343 return !(__x == __y);
344}
345
346template <class _T1, class _T2>
347inline _LIBCPP_INLINE_VISIBILITY
348bool
349operator< (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
354template <class _T1, class _T2>
355inline _LIBCPP_INLINE_VISIBILITY
356bool
357operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
358{
359 return __y < __x;
360}
361
362template <class _T1, class _T2>
363inline _LIBCPP_INLINE_VISIBILITY
364bool
365operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
366{
367 return !(__x < __y);
368}
369
370template <class _T1, class _T2>
371inline _LIBCPP_INLINE_VISIBILITY
372bool
373operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
374{
375 return !(__y < __x);
376}
377
378template <class _T1, class _T2>
379inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000380typename enable_if
381<
382 __is_swappable<_T1>::value &&
383 __is_swappable<_T2>::value,
384 void
385>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000386swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000387 _NOEXCEPT_((__is_nothrow_swappable<_T1>::value &&
388 __is_nothrow_swappable<_T2>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000389{
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000390 __x.swap(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000391}
392
Howard Hinnant73d21a42010-09-04 23:28:19 +0000393#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394
395template <class _Tp> class reference_wrapper;
396
397template <class _Tp>
398struct ___make_pair_return
399{
400 typedef _Tp type;
401};
402
403template <class _Tp>
404struct ___make_pair_return<reference_wrapper<_Tp>>
405{
406 typedef _Tp& type;
407};
408
409template <class _Tp>
410struct __make_pair_return
411{
412 typedef typename ___make_pair_return<typename decay<_Tp>::type>::type type;
413};
414
415template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000416inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000417pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
418make_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 Hinnant73d21a42010-09-04 23:28:19 +0000424#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000425
426template <class _T1, class _T2>
427inline _LIBCPP_INLINE_VISIBILITY
428pair<_T1,_T2>
429make_pair(_T1 __x, _T2 __y)
430{
431 return pair<_T1, _T2>(__x, __y);
432}
433
Howard Hinnant73d21a42010-09-04 23:28:19 +0000434#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435
436#ifndef _LIBCPP_HAS_NO_VARIADICS
437
438template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000439 class _LIBCPP_VISIBLE tuple_size<pair<_T1, _T2> >
440 : public integral_constant<size_t, 2> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000441
442template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000443 class _LIBCPP_VISIBLE tuple_size<const pair<_T1, _T2> >
444 : public integral_constant<size_t, 2> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000445
446template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000447class _LIBCPP_VISIBLE tuple_element<0, pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448{
449public:
450 typedef _T1 type;
451};
452
453template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000454class _LIBCPP_VISIBLE tuple_element<1, pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000455{
456public:
457 typedef _T2 type;
458};
459
460template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000461class _LIBCPP_VISIBLE tuple_element<0, const pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462{
463public:
464 typedef const _T1 type;
465};
466
467template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000468class _LIBCPP_VISIBLE tuple_element<1, const pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000469{
470public:
471 typedef const _T2 type;
472};
473
474template <size_t _Ip> struct __get_pair;
475
476template <>
477struct __get_pair<0>
478{
479 template <class _T1, class _T2>
480 static
481 _LIBCPP_INLINE_VISIBILITY
482 _T1&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000483 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000484
485 template <class _T1, class _T2>
486 static
487 _LIBCPP_INLINE_VISIBILITY
488 const _T1&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000489 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000490
491#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
492
493 template <class _T1, class _T2>
494 static
495 _LIBCPP_INLINE_VISIBILITY
496 _T1&&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000497 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _STD::forward<_T1>(__p.first);}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000498
499#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000500};
501
502template <>
503struct __get_pair<1>
504{
505 template <class _T1, class _T2>
506 static
507 _LIBCPP_INLINE_VISIBILITY
508 _T2&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000509 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000510
511 template <class _T1, class _T2>
512 static
513 _LIBCPP_INLINE_VISIBILITY
514 const _T2&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000515 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000516
517#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
518
519 template <class _T1, class _T2>
520 static
521 _LIBCPP_INLINE_VISIBILITY
522 _T2&&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000523 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _STD::forward<_T2>(__p.second);}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000524
525#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000526};
527
528template <size_t _Ip, class _T1, class _T2>
529_LIBCPP_INLINE_VISIBILITY inline
530typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000531get(pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532{
533 return __get_pair<_Ip>::get(__p);
534}
535
536template <size_t _Ip, class _T1, class _T2>
537_LIBCPP_INLINE_VISIBILITY inline
538const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000539get(const pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540{
541 return __get_pair<_Ip>::get(__p);
542}
543
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000544#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
545
546template <size_t _Ip, class _T1, class _T2>
547_LIBCPP_INLINE_VISIBILITY inline
548typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000549get(pair<_T1, _T2>&& __p) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000550{
551 return __get_pair<_Ip>::get(_STD::move(__p));
552}
553
554#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
555
Howard Hinnant324bb032010-08-22 00:02:43 +0000556#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000557
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000558_LIBCPP_END_NAMESPACE_STD
559
560#endif // _LIBCPP_UTILITY