blob: 2efea28435ad241ec3251252aa1999c28371ebe6 [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
Howard Hinnant08e17472011-10-17 20:05:10 +0000128#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000129#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000130#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000131
132_LIBCPP_BEGIN_NAMESPACE_STD
133
134namespace rel_ops
135{
136
137template<class _Tp>
138inline _LIBCPP_INLINE_VISIBILITY
139bool
140operator!=(const _Tp& __x, const _Tp& __y)
141{
142 return !(__x == __y);
143}
144
145template<class _Tp>
146inline _LIBCPP_INLINE_VISIBILITY
147bool
148operator> (const _Tp& __x, const _Tp& __y)
149{
150 return __y < __x;
151}
152
153template<class _Tp>
154inline _LIBCPP_INLINE_VISIBILITY
155bool
156operator<=(const _Tp& __x, const _Tp& __y)
157{
158 return !(__y < __x);
159}
160
161template<class _Tp>
162inline _LIBCPP_INLINE_VISIBILITY
163bool
164operator>=(const _Tp& __x, const _Tp& __y)
165{
166 return !(__x < __y);
167}
168
169} // rel_ops
170
171// swap_ranges
172
173template <class _ForwardIterator1, class _ForwardIterator2>
174inline _LIBCPP_INLINE_VISIBILITY
175_ForwardIterator2
176swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
177{
178 for(; __first1 != __last1; ++__first1, ++__first2)
179 swap(*__first1, *__first2);
180 return __first2;
181}
182
Howard Hinnant99968442011-11-29 18:15:50 +0000183template<class _Tp, size_t _Np>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000184inline _LIBCPP_INLINE_VISIBILITY
185void
Howard Hinnant99968442011-11-29 18:15:50 +0000186swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000187{
Howard Hinnant99968442011-11-29 18:15:50 +0000188 _VSTD::swap_ranges(__a, __a + _Np, __b);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000189}
190
191template <class _Tp>
192inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant73d21a42010-09-04 23:28:19 +0000193#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000194typename conditional
195<
Howard Hinnant1468b662010-11-19 22:17:28 +0000196 !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000197 const _Tp&,
198 _Tp&&
199>::type
Howard Hinnant73d21a42010-09-04 23:28:19 +0000200#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000201const _Tp&
202#endif
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000203move_if_noexcept(_Tp& __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000204{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000205 return _VSTD::move(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000206}
207
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000208struct _LIBCPP_VISIBLE piecewise_construct_t { };
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000209//constexpr
210extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
211
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000212template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000213struct _LIBCPP_VISIBLE pair
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000214{
215 typedef _T1 first_type;
216 typedef _T2 second_type;
217
218 _T1 first;
219 _T2 second;
220
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000221 // pair(const pair&) = default;
222 // pair(pair&&) = default;
223
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000224 _LIBCPP_INLINE_VISIBILITY pair() : first(), second() {}
225
226 _LIBCPP_INLINE_VISIBILITY pair(const _T1& __x, const _T2& __y)
227 : first(__x), second(__y) {}
228
Howard Hinnant469d4192011-04-29 18:10:55 +0000229 template<class _U1, class _U2>
230 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9c59d382011-07-27 19:25:28 +0000231 pair(const pair<_U1, _U2>& __p
232#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
233 ,typename enable_if<is_constructible<_T1, _U1>::value &&
234 is_constructible<_T2, _U2>::value>::type* = 0
235#endif
236 )
Howard Hinnant469d4192011-04-29 18:10:55 +0000237 : first(__p.first), second(__p.second) {}
238
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000239 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant61aa6012011-07-01 19:24:36 +0000240 pair(const pair& __p)
241 _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
242 is_nothrow_copy_constructible<second_type>::value)
243 : first(__p.first),
244 second(__p.second)
245 {
246 }
247
248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000249 pair& operator=(const pair& __p)
Howard Hinnant61aa6012011-07-01 19:24:36 +0000250 _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value &&
251 is_nothrow_copy_assignable<second_type>::value)
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000252 {
253 first = __p.first;
254 second = __p.second;
255 return *this;
256 }
257
Howard Hinnant73d21a42010-09-04 23:28:19 +0000258#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000259
260 template <class _U1, class _U2,
Howard Hinnant74248882011-07-01 20:12:51 +0000261 class = typename enable_if<is_constructible<first_type, _U1 >::value &&
262 is_constructible<second_type, _U2>::value>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000263 _LIBCPP_INLINE_VISIBILITY
264 pair(_U1&& __u1, _U2&& __u2)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000265 : first(_VSTD::forward<_U1>(__u1)),
266 second(_VSTD::forward<_U2>(__u2))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000267 {}
268
Howard Hinnant469d4192011-04-29 18:10:55 +0000269 template<class _U1, class _U2>
270 _LIBCPP_INLINE_VISIBILITY
271 pair(pair<_U1, _U2>&& __p,
Howard Hinnant74248882011-07-01 20:12:51 +0000272 typename enable_if<is_constructible<_T1, _U1>::value &&
273 is_constructible<_T2, _U2>::value>::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000274 : first(_VSTD::forward<_U1>(__p.first)),
275 second(_VSTD::forward<_U2>(__p.second)) {}
Howard Hinnant469d4192011-04-29 18:10:55 +0000276
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000277 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant61aa6012011-07-01 19:24:36 +0000278 pair(pair&& __p) _NOEXCEPT_(is_nothrow_move_constructible<first_type>::value &&
279 is_nothrow_move_constructible<second_type>::value)
280 : first(_VSTD::forward<first_type>(__p.first)),
281 second(_VSTD::forward<second_type>(__p.second))
282 {
283 }
284
285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000286 pair&
287 operator=(pair&& __p) _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value &&
288 is_nothrow_move_assignable<second_type>::value)
289 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000290 first = _VSTD::forward<first_type>(__p.first);
291 second = _VSTD::forward<second_type>(__p.second);
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000292 return *this;
293 }
294
Michael J. Spencer626916f2010-12-10 19:47:54 +0000295#ifndef _LIBCPP_HAS_NO_VARIADICS
296
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000297 template<class _Tuple,
298 class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type>
299 _LIBCPP_INLINE_VISIBILITY
300 pair(_Tuple&& __p)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000301 : first(_VSTD::forward<typename tuple_element<0,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000302 typename __make_tuple_types<_Tuple>::type>::type>(get<0>(__p))),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000303 second(_VSTD::forward<typename tuple_element<1,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000304 typename __make_tuple_types<_Tuple>::type>::type>(get<1>(__p)))
305 {}
306
Michael J. Spencer626916f2010-12-10 19:47:54 +0000307
Howard Hinnant726a76f2010-11-16 21:10:23 +0000308
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000309 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000310 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000311 pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
312 tuple<_Args2...> __second_args)
Howard Hinnant324bb032010-08-22 00:02:43 +0000313 : pair(__pc, __first_args, __second_args,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000314 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
315 typename __make_tuple_indices<sizeof...(_Args2) >::type())
316 {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000317
318 template <class _Tuple,
319 class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000320 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000321 pair&
322 operator=(_Tuple&& __p)
323 {
324 typedef typename __make_tuple_types<_Tuple>::type _TupleRef;
325 typedef typename tuple_element<0, _TupleRef>::type _U0;
326 typedef typename tuple_element<1, _TupleRef>::type _U1;
Howard Hinnant0949eed2011-06-30 21:18:19 +0000327 first = _VSTD::forward<_U0>(_VSTD::get<0>(__p));
328 second = _VSTD::forward<_U1>(_VSTD::get<1>(__p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000329 return *this;
330 }
331
Michael J. Spencer626916f2010-12-10 19:47:54 +0000332#endif // _LIBCPP_HAS_NO_VARIADICS
333
Howard Hinnant73d21a42010-09-04 23:28:19 +0000334#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000335 _LIBCPP_INLINE_VISIBILITY
336 void
Howard Hinnanta5e01212011-05-27 19:08:18 +0000337 swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value &&
338 __is_nothrow_swappable<second_type>::value)
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000339 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000340 _VSTD::iter_swap(&first, &__p.first);
341 _VSTD::iter_swap(&second, &__p.second);
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000342 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000343private:
Howard Hinnant324bb032010-08-22 00:02:43 +0000344
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000345#ifndef _LIBCPP_HAS_NO_VARIADICS
346 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
Howard Hinnant5f5859c2011-01-13 20:05:05 +0000347 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000348 pair(piecewise_construct_t,
349 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
350 __tuple_indices<_I1...>, __tuple_indices<_I2...>);
Howard Hinnant324bb032010-08-22 00:02:43 +0000351#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000352};
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 __x.first == __y.first && __x.second == __y.second;
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 __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);
376}
377
378template <class _T1, class _T2>
379inline _LIBCPP_INLINE_VISIBILITY
380bool
381operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
382{
383 return __y < __x;
384}
385
386template <class _T1, class _T2>
387inline _LIBCPP_INLINE_VISIBILITY
388bool
389operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
390{
391 return !(__x < __y);
392}
393
394template <class _T1, class _T2>
395inline _LIBCPP_INLINE_VISIBILITY
396bool
397operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
398{
399 return !(__y < __x);
400}
401
402template <class _T1, class _T2>
403inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000404typename enable_if
405<
406 __is_swappable<_T1>::value &&
407 __is_swappable<_T2>::value,
408 void
409>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000410swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000411 _NOEXCEPT_((__is_nothrow_swappable<_T1>::value &&
412 __is_nothrow_swappable<_T2>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000413{
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000414 __x.swap(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415}
416
Howard Hinnant73d21a42010-09-04 23:28:19 +0000417#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000418
419template <class _Tp> class reference_wrapper;
420
421template <class _Tp>
422struct ___make_pair_return
423{
424 typedef _Tp type;
425};
426
427template <class _Tp>
428struct ___make_pair_return<reference_wrapper<_Tp>>
429{
430 typedef _Tp& type;
431};
432
433template <class _Tp>
434struct __make_pair_return
435{
436 typedef typename ___make_pair_return<typename decay<_Tp>::type>::type type;
437};
438
439template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000440inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000441pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
442make_pair(_T1&& __t1, _T2&& __t2)
443{
444 return pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
Howard Hinnant0949eed2011-06-30 21:18:19 +0000445 (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000446}
447
Howard Hinnant73d21a42010-09-04 23:28:19 +0000448#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000449
450template <class _T1, class _T2>
451inline _LIBCPP_INLINE_VISIBILITY
452pair<_T1,_T2>
453make_pair(_T1 __x, _T2 __y)
454{
455 return pair<_T1, _T2>(__x, __y);
456}
457
Howard Hinnant73d21a42010-09-04 23:28:19 +0000458#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459
460#ifndef _LIBCPP_HAS_NO_VARIADICS
461
462template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000463 class _LIBCPP_VISIBLE tuple_size<pair<_T1, _T2> >
464 : public integral_constant<size_t, 2> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000465
466template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000467 class _LIBCPP_VISIBLE tuple_size<const pair<_T1, _T2> >
468 : public integral_constant<size_t, 2> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000469
470template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000471class _LIBCPP_VISIBLE tuple_element<0, pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000472{
473public:
474 typedef _T1 type;
475};
476
477template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000478class _LIBCPP_VISIBLE tuple_element<1, pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000479{
480public:
481 typedef _T2 type;
482};
483
484template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000485class _LIBCPP_VISIBLE tuple_element<0, const pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000486{
487public:
488 typedef const _T1 type;
489};
490
491template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000492class _LIBCPP_VISIBLE tuple_element<1, const pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000493{
494public:
495 typedef const _T2 type;
496};
497
498template <size_t _Ip> struct __get_pair;
499
500template <>
501struct __get_pair<0>
502{
503 template <class _T1, class _T2>
504 static
505 _LIBCPP_INLINE_VISIBILITY
506 _T1&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000507 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000508
509 template <class _T1, class _T2>
510 static
511 _LIBCPP_INLINE_VISIBILITY
512 const _T1&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000513 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000514
515#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
516
517 template <class _T1, class _T2>
518 static
519 _LIBCPP_INLINE_VISIBILITY
520 _T1&&
Howard Hinnant0949eed2011-06-30 21:18:19 +0000521 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000522
523#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524};
525
526template <>
527struct __get_pair<1>
528{
529 template <class _T1, class _T2>
530 static
531 _LIBCPP_INLINE_VISIBILITY
532 _T2&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000533 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000534
535 template <class _T1, class _T2>
536 static
537 _LIBCPP_INLINE_VISIBILITY
538 const _T2&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000539 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000540
541#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
542
543 template <class _T1, class _T2>
544 static
545 _LIBCPP_INLINE_VISIBILITY
546 _T2&&
Howard Hinnant0949eed2011-06-30 21:18:19 +0000547 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000548
549#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000550};
551
552template <size_t _Ip, class _T1, class _T2>
553_LIBCPP_INLINE_VISIBILITY inline
554typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000555get(pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000556{
557 return __get_pair<_Ip>::get(__p);
558}
559
560template <size_t _Ip, class _T1, class _T2>
561_LIBCPP_INLINE_VISIBILITY inline
562const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000563get(const pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000564{
565 return __get_pair<_Ip>::get(__p);
566}
567
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000568#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
569
570template <size_t _Ip, class _T1, class _T2>
571_LIBCPP_INLINE_VISIBILITY inline
572typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000573get(pair<_T1, _T2>&& __p) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000574{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000575 return __get_pair<_Ip>::get(_VSTD::move(__p));
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000576}
577
578#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
579
Howard Hinnant324bb032010-08-22 00:02:43 +0000580#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000581
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000582_LIBCPP_END_NAMESPACE_STD
583
584#endif // _LIBCPP_UTILITY