blob: 514ce17f41fa4f39ae14e7119d8dd619b85aeace [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 Hinnant616e92d2012-04-03 23:45:46 +0000209#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_UTILITY)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000210extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
Howard Hinnant2a5349b2012-04-03 21:09:48 +0000211#else
212constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
213#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000214
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000215template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000216struct _LIBCPP_VISIBLE pair
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000217{
218 typedef _T1 first_type;
219 typedef _T2 second_type;
220
221 _T1 first;
222 _T2 second;
223
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000224 // pair(const pair&) = default;
225 // pair(pair&&) = default;
226
Howard Hinnant2a5349b2012-04-03 21:09:48 +0000227 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000228
229 _LIBCPP_INLINE_VISIBILITY pair(const _T1& __x, const _T2& __y)
230 : first(__x), second(__y) {}
231
Howard Hinnant469d4192011-04-29 18:10:55 +0000232 template<class _U1, class _U2>
233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9c59d382011-07-27 19:25:28 +0000234 pair(const pair<_U1, _U2>& __p
235#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantfe592762012-06-09 20:01:23 +0000236 ,typename enable_if<is_convertible<const _U1&, _T1>::value &&
237 is_convertible<const _U2&, _T2>::value>::type* = 0
Howard Hinnant9c59d382011-07-27 19:25:28 +0000238#endif
239 )
Howard Hinnant469d4192011-04-29 18:10:55 +0000240 : first(__p.first), second(__p.second) {}
241
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000242 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant61aa6012011-07-01 19:24:36 +0000243 pair(const pair& __p)
244 _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
245 is_nothrow_copy_constructible<second_type>::value)
246 : first(__p.first),
247 second(__p.second)
248 {
249 }
250
251 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000252 pair& operator=(const pair& __p)
Howard Hinnant61aa6012011-07-01 19:24:36 +0000253 _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value &&
254 is_nothrow_copy_assignable<second_type>::value)
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000255 {
256 first = __p.first;
257 second = __p.second;
258 return *this;
259 }
260
Howard Hinnant73d21a42010-09-04 23:28:19 +0000261#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000262
263 template <class _U1, class _U2,
Howard Hinnantfe592762012-06-09 20:01:23 +0000264 class = typename enable_if<is_convertible<_U1, first_type>::value &&
265 is_convertible<_U2, second_type>::value>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000266 _LIBCPP_INLINE_VISIBILITY
267 pair(_U1&& __u1, _U2&& __u2)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000268 : first(_VSTD::forward<_U1>(__u1)),
269 second(_VSTD::forward<_U2>(__u2))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000270 {}
271
Howard Hinnant469d4192011-04-29 18:10:55 +0000272 template<class _U1, class _U2>
273 _LIBCPP_INLINE_VISIBILITY
274 pair(pair<_U1, _U2>&& __p,
Howard Hinnantfe592762012-06-09 20:01:23 +0000275 typename enable_if<is_convertible<_U1, _T1>::value &&
276 is_convertible<_U2, _T2>::value>::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000277 : first(_VSTD::forward<_U1>(__p.first)),
278 second(_VSTD::forward<_U2>(__p.second)) {}
Howard Hinnant469d4192011-04-29 18:10:55 +0000279
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000280 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant61aa6012011-07-01 19:24:36 +0000281 pair(pair&& __p) _NOEXCEPT_(is_nothrow_move_constructible<first_type>::value &&
282 is_nothrow_move_constructible<second_type>::value)
283 : first(_VSTD::forward<first_type>(__p.first)),
284 second(_VSTD::forward<second_type>(__p.second))
285 {
286 }
287
288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000289 pair&
290 operator=(pair&& __p) _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value &&
291 is_nothrow_move_assignable<second_type>::value)
292 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000293 first = _VSTD::forward<first_type>(__p.first);
294 second = _VSTD::forward<second_type>(__p.second);
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000295 return *this;
296 }
297
Michael J. Spencer626916f2010-12-10 19:47:54 +0000298#ifndef _LIBCPP_HAS_NO_VARIADICS
299
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000300 template<class _Tuple,
301 class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type>
302 _LIBCPP_INLINE_VISIBILITY
303 pair(_Tuple&& __p)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000304 : first(_VSTD::forward<typename tuple_element<0,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000305 typename __make_tuple_types<_Tuple>::type>::type>(get<0>(__p))),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000306 second(_VSTD::forward<typename tuple_element<1,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000307 typename __make_tuple_types<_Tuple>::type>::type>(get<1>(__p)))
308 {}
309
Michael J. Spencer626916f2010-12-10 19:47:54 +0000310
Howard Hinnant726a76f2010-11-16 21:10:23 +0000311
Howard Hinnant6cc99fa2011-12-19 17:58:44 +0000312 template <class... _Args1, class... _Args2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000313 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000314 pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
315 tuple<_Args2...> __second_args)
Howard Hinnant324bb032010-08-22 00:02:43 +0000316 : pair(__pc, __first_args, __second_args,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000317 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
318 typename __make_tuple_indices<sizeof...(_Args2) >::type())
319 {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000320
321 template <class _Tuple,
322 class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000323 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000324 pair&
325 operator=(_Tuple&& __p)
326 {
327 typedef typename __make_tuple_types<_Tuple>::type _TupleRef;
328 typedef typename tuple_element<0, _TupleRef>::type _U0;
329 typedef typename tuple_element<1, _TupleRef>::type _U1;
Howard Hinnant0949eed2011-06-30 21:18:19 +0000330 first = _VSTD::forward<_U0>(_VSTD::get<0>(__p));
331 second = _VSTD::forward<_U1>(_VSTD::get<1>(__p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000332 return *this;
333 }
334
Michael J. Spencer626916f2010-12-10 19:47:54 +0000335#endif // _LIBCPP_HAS_NO_VARIADICS
336
Howard Hinnant73d21a42010-09-04 23:28:19 +0000337#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000338 _LIBCPP_INLINE_VISIBILITY
339 void
Howard Hinnanta5e01212011-05-27 19:08:18 +0000340 swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value &&
341 __is_nothrow_swappable<second_type>::value)
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000342 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000343 _VSTD::iter_swap(&first, &__p.first);
344 _VSTD::iter_swap(&second, &__p.second);
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000345 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000346private:
Howard Hinnant324bb032010-08-22 00:02:43 +0000347
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000348#ifndef _LIBCPP_HAS_NO_VARIADICS
349 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
Howard Hinnant5f5859c2011-01-13 20:05:05 +0000350 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000351 pair(piecewise_construct_t,
352 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
353 __tuple_indices<_I1...>, __tuple_indices<_I2...>);
Howard Hinnant324bb032010-08-22 00:02:43 +0000354#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355};
356
357template <class _T1, class _T2>
358inline _LIBCPP_INLINE_VISIBILITY
359bool
360operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
361{
362 return __x.first == __y.first && __x.second == __y.second;
363}
364
365template <class _T1, class _T2>
366inline _LIBCPP_INLINE_VISIBILITY
367bool
368operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
369{
370 return !(__x == __y);
371}
372
373template <class _T1, class _T2>
374inline _LIBCPP_INLINE_VISIBILITY
375bool
376operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
377{
378 return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);
379}
380
381template <class _T1, class _T2>
382inline _LIBCPP_INLINE_VISIBILITY
383bool
384operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
385{
386 return __y < __x;
387}
388
389template <class _T1, class _T2>
390inline _LIBCPP_INLINE_VISIBILITY
391bool
392operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
393{
394 return !(__x < __y);
395}
396
397template <class _T1, class _T2>
398inline _LIBCPP_INLINE_VISIBILITY
399bool
400operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
401{
402 return !(__y < __x);
403}
404
405template <class _T1, class _T2>
406inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000407typename enable_if
408<
409 __is_swappable<_T1>::value &&
410 __is_swappable<_T2>::value,
411 void
412>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000413swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000414 _NOEXCEPT_((__is_nothrow_swappable<_T1>::value &&
415 __is_nothrow_swappable<_T2>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416{
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000417 __x.swap(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000418}
419
Howard Hinnant73d21a42010-09-04 23:28:19 +0000420#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000421
Howard Hinnant33be35e2012-09-14 00:39:16 +0000422template <class _Tp> class _LIBCPP_VISIBLE reference_wrapper;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423
424template <class _Tp>
425struct ___make_pair_return
426{
427 typedef _Tp type;
428};
429
430template <class _Tp>
431struct ___make_pair_return<reference_wrapper<_Tp>>
432{
433 typedef _Tp& type;
434};
435
436template <class _Tp>
437struct __make_pair_return
438{
439 typedef typename ___make_pair_return<typename decay<_Tp>::type>::type type;
440};
441
442template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000443inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000444pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
445make_pair(_T1&& __t1, _T2&& __t2)
446{
447 return pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
Howard Hinnant0949eed2011-06-30 21:18:19 +0000448 (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000449}
450
Howard Hinnant73d21a42010-09-04 23:28:19 +0000451#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000452
453template <class _T1, class _T2>
454inline _LIBCPP_INLINE_VISIBILITY
455pair<_T1,_T2>
456make_pair(_T1 __x, _T2 __y)
457{
458 return pair<_T1, _T2>(__x, __y);
459}
460
Howard Hinnant73d21a42010-09-04 23:28:19 +0000461#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000463template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000464 class _LIBCPP_VISIBLE tuple_size<pair<_T1, _T2> >
465 : public integral_constant<size_t, 2> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466
467template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000468 class _LIBCPP_VISIBLE tuple_size<const pair<_T1, _T2> >
469 : public integral_constant<size_t, 2> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470
471template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000472class _LIBCPP_VISIBLE tuple_element<0, pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000473{
474public:
475 typedef _T1 type;
476};
477
478template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000479class _LIBCPP_VISIBLE tuple_element<1, pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000480{
481public:
482 typedef _T2 type;
483};
484
485template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000486class _LIBCPP_VISIBLE tuple_element<0, const pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000487{
488public:
489 typedef const _T1 type;
490};
491
492template <class _T1, class _T2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000493class _LIBCPP_VISIBLE tuple_element<1, const pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000494{
495public:
496 typedef const _T2 type;
497};
498
499template <size_t _Ip> struct __get_pair;
500
501template <>
502struct __get_pair<0>
503{
504 template <class _T1, class _T2>
505 static
506 _LIBCPP_INLINE_VISIBILITY
507 _T1&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000508 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000509
510 template <class _T1, class _T2>
511 static
512 _LIBCPP_INLINE_VISIBILITY
513 const _T1&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000514 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000515
516#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
517
518 template <class _T1, class _T2>
519 static
520 _LIBCPP_INLINE_VISIBILITY
521 _T1&&
Howard Hinnant0949eed2011-06-30 21:18:19 +0000522 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000523
524#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000525};
526
527template <>
528struct __get_pair<1>
529{
530 template <class _T1, class _T2>
531 static
532 _LIBCPP_INLINE_VISIBILITY
533 _T2&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000534 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000535
536 template <class _T1, class _T2>
537 static
538 _LIBCPP_INLINE_VISIBILITY
539 const _T2&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000540 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000541
542#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
543
544 template <class _T1, class _T2>
545 static
546 _LIBCPP_INLINE_VISIBILITY
547 _T2&&
Howard Hinnant0949eed2011-06-30 21:18:19 +0000548 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000549
550#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000551};
552
553template <size_t _Ip, class _T1, class _T2>
554_LIBCPP_INLINE_VISIBILITY inline
555typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000556get(pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000557{
558 return __get_pair<_Ip>::get(__p);
559}
560
561template <size_t _Ip, class _T1, class _T2>
562_LIBCPP_INLINE_VISIBILITY inline
563const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000564get(const pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000565{
566 return __get_pair<_Ip>::get(__p);
567}
568
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000569#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
570
571template <size_t _Ip, class _T1, class _T2>
572_LIBCPP_INLINE_VISIBILITY inline
573typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000574get(pair<_T1, _T2>&& __p) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000575{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000576 return __get_pair<_Ip>::get(_VSTD::move(__p));
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000577}
578
579#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
580
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000581_LIBCPP_END_NAMESPACE_STD
582
583#endif // _LIBCPP_UTILITY