blob: 8b982da72b91e81f2cdd4fff5bf2ed9ad56dacdc [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
Marshall Clow01a0e902013-07-15 20:46:11 +000041template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; // constexpr in C++14
42template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++14
Howard Hinnante9b2c2d2011-05-27 15:04:19 +000043
Marshall Clow01a0e902013-07-15 20:46:11 +000044template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14
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
Marshall Clow01a0e902013-07-15 20:46:11 +000053 move_if_noexcept(T& x) noexcept; // constexpr in C++14
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();
Marshall Clow206f6cd2013-07-16 17:45:44 +000069 pair(const T1& x, const T2& y); // constexpr in C++14
70 template <class U, class V> pair(U&& x, V&& y); // constexpr in C++14
71 template <class U, class V> pair(const pair<U, V>& p); // constexpr in C++14
72 template <class U, class V> pair(pair<U, V>&& p); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000073 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
Marshall Clow206f6cd2013-07-16 17:45:44 +000086template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
87template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
88template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
89template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
90template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
91template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000092
Marshall Clow206f6cd2013-07-16 17:45:44 +000093template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14
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
Marshall Clow50fe0c72014-03-03 06:18:11 +0000104template <class T1, class T2> struct tuple_size<pair<T1, T2> >;
105template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >;
106template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000107
108template<size_t I, class T1, class T2>
Marshall Clow50fe0c72014-03-03 06:18:11 +0000109 typename tuple_element<I, pair<T1, T2> >::type&
110 get(pair<T1, T2>&) noexcept; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000111
112template<size_t I, class T1, class T2>
Marshall Clow50fe0c72014-03-03 06:18:11 +0000113 const typename const tuple_element<I, pair<T1, T2> >::type&
114 get(const pair<T1, T2>&) noexcept; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000115
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000116template<size_t I, class T1, class T2>
Marshall Clow50fe0c72014-03-03 06:18:11 +0000117 typename tuple_element<I, pair<T1, T2> >::type&&
118 get(pair<T1, T2>&&) noexcept; // constexpr in C++14
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000119
Marshall Clowe8029e52013-07-13 02:54:05 +0000120template<class T1, class T2>
Marshall Clow50fe0c72014-03-03 06:18:11 +0000121 constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
Marshall Clowe8029e52013-07-13 02:54:05 +0000122
123template<size_t I, class T1, class T2>
Marshall Clow50fe0c72014-03-03 06:18:11 +0000124 constexpr T1 const& get(pair<T1, T2> const &) noexcept; // C++14
Marshall Clowe8029e52013-07-13 02:54:05 +0000125
126template<size_t I, class T1, class T2>
Marshall Clow50fe0c72014-03-03 06:18:11 +0000127 constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14
Marshall Clowe8029e52013-07-13 02:54:05 +0000128
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000129// C++14
130
131template<class T, T... I>
132struct integer_sequence
133{
134 typedef T value_type;
135
136 static constexpr size_t size() noexcept;
137};
138
139template<size_t... I>
140 using index_sequence = integer_sequence<size_t, I...>;
141
142template<class T, T N>
143 using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
144template<size_t N>
145 using make_index_sequence = make_integer_sequence<size_t, N>;
146
147template<class... T>
148 using index_sequence_for = make_index_sequence<sizeof...(T)>;
149
Marshall Clowe2735d12013-07-08 20:54:40 +0000150template<class T, class U=T>
151 T exchange(T& obj, U&& new_value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000152} // std
153
154*/
155
156#include <__config>
157#include <__tuple>
158#include <type_traits>
159
Howard Hinnant08e17472011-10-17 20:05:10 +0000160#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000161#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000162#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000163
164_LIBCPP_BEGIN_NAMESPACE_STD
165
166namespace rel_ops
167{
168
169template<class _Tp>
170inline _LIBCPP_INLINE_VISIBILITY
171bool
172operator!=(const _Tp& __x, const _Tp& __y)
173{
174 return !(__x == __y);
175}
176
177template<class _Tp>
178inline _LIBCPP_INLINE_VISIBILITY
179bool
180operator> (const _Tp& __x, const _Tp& __y)
181{
182 return __y < __x;
183}
184
185template<class _Tp>
186inline _LIBCPP_INLINE_VISIBILITY
187bool
188operator<=(const _Tp& __x, const _Tp& __y)
189{
190 return !(__y < __x);
191}
192
193template<class _Tp>
194inline _LIBCPP_INLINE_VISIBILITY
195bool
196operator>=(const _Tp& __x, const _Tp& __y)
197{
198 return !(__x < __y);
199}
200
201} // rel_ops
202
203// swap_ranges
204
Marshall Clowfd8ed7f2015-01-06 19:20:49 +0000205// forward
206template<class _Tp, size_t _Np>
Marshall Clowfec08372015-02-24 12:46:39 +0000207inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowfd8ed7f2015-01-06 19:20:49 +0000208void swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value);
209
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000210template <class _ForwardIterator1, class _ForwardIterator2>
211inline _LIBCPP_INLINE_VISIBILITY
212_ForwardIterator2
213swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
214{
Eric Fiselierb9919752014-10-27 19:28:20 +0000215 for(; __first1 != __last1; ++__first1, (void) ++__first2)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000216 swap(*__first1, *__first2);
217 return __first2;
218}
219
Howard Hinnant99968442011-11-29 18:15:50 +0000220template<class _Tp, size_t _Np>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000221inline _LIBCPP_INLINE_VISIBILITY
222void
Howard Hinnant99968442011-11-29 18:15:50 +0000223swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000224{
Howard Hinnant99968442011-11-29 18:15:50 +0000225 _VSTD::swap_ranges(__a, __a + _Np, __b);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000226}
227
228template <class _Tp>
Marshall Clow01a0e902013-07-15 20:46:11 +0000229inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant73d21a42010-09-04 23:28:19 +0000230#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000231typename conditional
232<
Howard Hinnant1468b662010-11-19 22:17:28 +0000233 !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000234 const _Tp&,
235 _Tp&&
236>::type
Howard Hinnant73d21a42010-09-04 23:28:19 +0000237#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000238const _Tp&
239#endif
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000240move_if_noexcept(_Tp& __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000241{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000242 return _VSTD::move(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000243}
244
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000245struct _LIBCPP_TYPE_VIS_ONLY piecewise_construct_t { };
Howard Hinnant616e92d2012-04-03 23:45:46 +0000246#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_UTILITY)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000247extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
Howard Hinnant2a5349b2012-04-03 21:09:48 +0000248#else
249constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
250#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000251
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000252template <class _T1, class _T2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000253struct _LIBCPP_TYPE_VIS_ONLY pair
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000254{
255 typedef _T1 first_type;
256 typedef _T2 second_type;
257
258 _T1 first;
259 _T2 second;
260
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000261 // pair(const pair&) = default;
262 // pair(pair&&) = default;
263
Howard Hinnant2a5349b2012-04-03 21:09:48 +0000264 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000265
Marshall Clow206f6cd2013-07-16 17:45:44 +0000266 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
267 pair(const _T1& __x, const _T2& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000268 : first(__x), second(__y) {}
269
Howard Hinnant469d4192011-04-29 18:10:55 +0000270 template<class _U1, class _U2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000271 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant9c59d382011-07-27 19:25:28 +0000272 pair(const pair<_U1, _U2>& __p
273#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantfe592762012-06-09 20:01:23 +0000274 ,typename enable_if<is_convertible<const _U1&, _T1>::value &&
275 is_convertible<const _U2&, _T2>::value>::type* = 0
Howard Hinnant9c59d382011-07-27 19:25:28 +0000276#endif
277 )
Howard Hinnant469d4192011-04-29 18:10:55 +0000278 : first(__p.first), second(__p.second) {}
279
Howard Hinnant65173fe2013-11-14 22:52:25 +0000280#if !defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && _LIBCPP_TRIVIAL_PAIR_COPY_CTOR
Marshall Clow206f6cd2013-07-16 17:45:44 +0000281 _LIBCPP_INLINE_VISIBILITY
282 pair(const pair& __p) = default;
Howard Hinnant65173fe2013-11-14 22:52:25 +0000283#elif !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) || !_LIBCPP_TRIVIAL_PAIR_COPY_CTOR
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000284 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant61aa6012011-07-01 19:24:36 +0000285 pair(const pair& __p)
286 _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
287 is_nothrow_copy_constructible<second_type>::value)
288 : first(__p.first),
289 second(__p.second)
290 {
291 }
Marshall Clow206f6cd2013-07-16 17:45:44 +0000292#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +0000293
294 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000295 pair& operator=(const pair& __p)
Howard Hinnant61aa6012011-07-01 19:24:36 +0000296 _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value &&
297 is_nothrow_copy_assignable<second_type>::value)
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000298 {
299 first = __p.first;
300 second = __p.second;
301 return *this;
302 }
303
Howard Hinnant73d21a42010-09-04 23:28:19 +0000304#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000305
306 template <class _U1, class _U2,
Howard Hinnantfe592762012-06-09 20:01:23 +0000307 class = typename enable_if<is_convertible<_U1, first_type>::value &&
308 is_convertible<_U2, second_type>::value>::type>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000309 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000310 pair(_U1&& __u1, _U2&& __u2)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000311 : first(_VSTD::forward<_U1>(__u1)),
312 second(_VSTD::forward<_U2>(__u2))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000313 {}
314
Howard Hinnant469d4192011-04-29 18:10:55 +0000315 template<class _U1, class _U2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000316 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant469d4192011-04-29 18:10:55 +0000317 pair(pair<_U1, _U2>&& __p,
Howard Hinnantfe592762012-06-09 20:01:23 +0000318 typename enable_if<is_convertible<_U1, _T1>::value &&
319 is_convertible<_U2, _T2>::value>::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000320 : first(_VSTD::forward<_U1>(__p.first)),
321 second(_VSTD::forward<_U2>(__p.second)) {}
Howard Hinnant469d4192011-04-29 18:10:55 +0000322
Marshall Clow206f6cd2013-07-16 17:45:44 +0000323#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
324 _LIBCPP_INLINE_VISIBILITY
325 pair(pair&& __p) = default;
326#else
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000327 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant61aa6012011-07-01 19:24:36 +0000328 pair(pair&& __p) _NOEXCEPT_(is_nothrow_move_constructible<first_type>::value &&
329 is_nothrow_move_constructible<second_type>::value)
330 : first(_VSTD::forward<first_type>(__p.first)),
331 second(_VSTD::forward<second_type>(__p.second))
332 {
333 }
Marshall Clow206f6cd2013-07-16 17:45:44 +0000334#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +0000335
336 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000337 pair&
338 operator=(pair&& __p) _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value &&
339 is_nothrow_move_assignable<second_type>::value)
340 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000341 first = _VSTD::forward<first_type>(__p.first);
342 second = _VSTD::forward<second_type>(__p.second);
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000343 return *this;
344 }
345
Michael J. Spencer626916f2010-12-10 19:47:54 +0000346#ifndef _LIBCPP_HAS_NO_VARIADICS
347
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000348 template<class _Tuple,
349 class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000350 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000351 pair(_Tuple&& __p)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000352 : first(_VSTD::forward<typename tuple_element<0,
Marshall Clowba6dbf42014-06-24 00:46:19 +0000353 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<0>(__p))),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000354 second(_VSTD::forward<typename tuple_element<1,
Marshall Clowba6dbf42014-06-24 00:46:19 +0000355 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<1>(__p)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000356 {}
357
Michael J. Spencer626916f2010-12-10 19:47:54 +0000358
Howard Hinnant726a76f2010-11-16 21:10:23 +0000359
Howard Hinnant6cc99fa2011-12-19 17:58:44 +0000360 template <class... _Args1, class... _Args2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000361 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000362 pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
363 tuple<_Args2...> __second_args)
Howard Hinnant324bb032010-08-22 00:02:43 +0000364 : pair(__pc, __first_args, __second_args,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
366 typename __make_tuple_indices<sizeof...(_Args2) >::type())
367 {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000368
369 template <class _Tuple,
370 class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000371 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372 pair&
373 operator=(_Tuple&& __p)
374 {
375 typedef typename __make_tuple_types<_Tuple>::type _TupleRef;
376 typedef typename tuple_element<0, _TupleRef>::type _U0;
377 typedef typename tuple_element<1, _TupleRef>::type _U1;
Howard Hinnant0949eed2011-06-30 21:18:19 +0000378 first = _VSTD::forward<_U0>(_VSTD::get<0>(__p));
379 second = _VSTD::forward<_U1>(_VSTD::get<1>(__p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000380 return *this;
381 }
382
Michael J. Spencer626916f2010-12-10 19:47:54 +0000383#endif // _LIBCPP_HAS_NO_VARIADICS
384
Howard Hinnant73d21a42010-09-04 23:28:19 +0000385#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000386 _LIBCPP_INLINE_VISIBILITY
387 void
Howard Hinnanta5e01212011-05-27 19:08:18 +0000388 swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value &&
389 __is_nothrow_swappable<second_type>::value)
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000390 {
Marshall Clow6b0e4192015-09-22 17:50:11 +0000391 using _VSTD::swap;
392 swap(first, __p.first);
393 swap(second, __p.second);
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000394 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000395private:
Howard Hinnant324bb032010-08-22 00:02:43 +0000396
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397#ifndef _LIBCPP_HAS_NO_VARIADICS
398 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
Howard Hinnant5f5859c2011-01-13 20:05:05 +0000399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000400 pair(piecewise_construct_t,
401 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
402 __tuple_indices<_I1...>, __tuple_indices<_I2...>);
Howard Hinnant324bb032010-08-22 00:02:43 +0000403#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000404};
405
406template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000407inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000408bool
409operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
410{
411 return __x.first == __y.first && __x.second == __y.second;
412}
413
414template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000415inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416bool
417operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
418{
419 return !(__x == __y);
420}
421
422template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000423inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000424bool
425operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
426{
427 return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);
428}
429
430template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000431inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000432bool
433operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
434{
435 return __y < __x;
436}
437
438template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000439inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000440bool
441operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
442{
443 return !(__x < __y);
444}
445
446template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000447inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448bool
449operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
450{
451 return !(__y < __x);
452}
453
454template <class _T1, class _T2>
455inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000456typename enable_if
457<
458 __is_swappable<_T1>::value &&
459 __is_swappable<_T2>::value,
460 void
461>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000463 _NOEXCEPT_((__is_nothrow_swappable<_T1>::value &&
464 __is_nothrow_swappable<_T2>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000465{
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000466 __x.swap(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000467}
468
Howard Hinnant73d21a42010-09-04 23:28:19 +0000469#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000471template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY reference_wrapper;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000472
473template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +0000474struct __make_pair_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000475{
476 typedef _Tp type;
477};
478
479template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +0000480struct __make_pair_return_impl<reference_wrapper<_Tp>>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000481{
482 typedef _Tp& type;
483};
484
485template <class _Tp>
486struct __make_pair_return
487{
Marshall Clowa71f9562014-01-03 22:55:49 +0000488 typedef typename __make_pair_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000489};
490
491template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000492inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000493pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
494make_pair(_T1&& __t1, _T2&& __t2)
495{
496 return pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
Howard Hinnant0949eed2011-06-30 21:18:19 +0000497 (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000498}
499
Howard Hinnant73d21a42010-09-04 23:28:19 +0000500#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501
502template <class _T1, class _T2>
503inline _LIBCPP_INLINE_VISIBILITY
504pair<_T1,_T2>
505make_pair(_T1 __x, _T2 __y)
506{
507 return pair<_T1, _T2>(__x, __y);
508}
509
Howard Hinnant73d21a42010-09-04 23:28:19 +0000510#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000511
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000512template <class _T1, class _T2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000513 class _LIBCPP_TYPE_VIS_ONLY tuple_size<pair<_T1, _T2> >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000514 : public integral_constant<size_t, 2> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000515
516template <class _T1, class _T2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000517class _LIBCPP_TYPE_VIS_ONLY tuple_element<0, pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000518{
519public:
520 typedef _T1 type;
521};
522
523template <class _T1, class _T2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000524class _LIBCPP_TYPE_VIS_ONLY tuple_element<1, pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000525{
526public:
527 typedef _T2 type;
528};
529
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000530template <size_t _Ip> struct __get_pair;
531
532template <>
533struct __get_pair<0>
534{
535 template <class _T1, class _T2>
536 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000537 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000538 _T1&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000539 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540
541 template <class _T1, class _T2>
542 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000543 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000544 const _T1&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000545 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000546
547#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
548
549 template <class _T1, class _T2>
550 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000551 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000552 _T1&&
Howard Hinnant0949eed2011-06-30 21:18:19 +0000553 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000554
555#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000556};
557
558template <>
559struct __get_pair<1>
560{
561 template <class _T1, class _T2>
562 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000563 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000564 _T2&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000565 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000566
567 template <class _T1, class _T2>
568 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000569 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000570 const _T2&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000571 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000572
573#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
574
575 template <class _T1, class _T2>
576 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000577 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000578 _T2&&
Howard Hinnant0949eed2011-06-30 21:18:19 +0000579 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000580
581#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000582};
583
584template <size_t _Ip, class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000585inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000586typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000587get(pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000588{
589 return __get_pair<_Ip>::get(__p);
590}
591
592template <size_t _Ip, class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000593inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000594const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000595get(const pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000596{
597 return __get_pair<_Ip>::get(__p);
598}
599
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000600#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
601
602template <size_t _Ip, class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000603inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000604typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000605get(pair<_T1, _T2>&& __p) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000606{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000607 return __get_pair<_Ip>::get(_VSTD::move(__p));
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000608}
609
610#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
611
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000612#if _LIBCPP_STD_VER > 11
Marshall Clowe8029e52013-07-13 02:54:05 +0000613template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000614inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000615constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT
616{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000617 return __get_pair<0>::get(__p);
Marshall Clowe8029e52013-07-13 02:54:05 +0000618}
619
620template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000621inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000622constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT
623{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000624 return __get_pair<0>::get(__p);
Marshall Clowe8029e52013-07-13 02:54:05 +0000625}
626
627template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000628inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000629constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT
630{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000631 return __get_pair<0>::get(_VSTD::move(__p));
Marshall Clowe8029e52013-07-13 02:54:05 +0000632}
633
634template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000635inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000636constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT
637{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000638 return __get_pair<1>::get(__p);
Marshall Clowe8029e52013-07-13 02:54:05 +0000639}
640
641template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000642inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000643constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT
644{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000645 return __get_pair<1>::get(__p);
Marshall Clowe8029e52013-07-13 02:54:05 +0000646}
647
648template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000649inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000650constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT
651{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000652 return __get_pair<1>::get(_VSTD::move(__p));
Marshall Clowe8029e52013-07-13 02:54:05 +0000653}
654
655#endif
656
657#if _LIBCPP_STD_VER > 11
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000658
659template<class _Tp, _Tp... _Ip>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000660struct _LIBCPP_TYPE_VIS_ONLY integer_sequence
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000661{
662 typedef _Tp value_type;
663 static_assert( is_integral<_Tp>::value,
664 "std::integer_sequence can only be instantiated with an integral type" );
665 static
666 _LIBCPP_INLINE_VISIBILITY
667 constexpr
668 size_t
669 size() noexcept { return sizeof...(_Ip); }
670};
671
672template<size_t... _Ip>
673 using index_sequence = integer_sequence<size_t, _Ip...>;
674
Marshall Clow42e55e92013-07-03 19:20:30 +0000675namespace __detail {
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000676
Marshall Clow42e55e92013-07-03 19:20:30 +0000677template<typename _Tp, size_t ..._Extra> struct __repeat;
678template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<integer_sequence<_Tp, _Np...>, _Extra...> {
679 typedef integer_sequence<_Tp,
680 _Np...,
681 sizeof...(_Np) + _Np...,
682 2 * sizeof...(_Np) + _Np...,
683 3 * sizeof...(_Np) + _Np...,
684 4 * sizeof...(_Np) + _Np...,
685 5 * sizeof...(_Np) + _Np...,
686 6 * sizeof...(_Np) + _Np...,
687 7 * sizeof...(_Np) + _Np...,
688 _Extra...> type;
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000689};
690
Marshall Clow42e55e92013-07-03 19:20:30 +0000691template<size_t _Np> struct __parity;
692template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {};
693
694template<> struct __make<0> { typedef integer_sequence<size_t> type; };
695template<> struct __make<1> { typedef integer_sequence<size_t, 0> type; };
696template<> struct __make<2> { typedef integer_sequence<size_t, 0, 1> type; };
697template<> struct __make<3> { typedef integer_sequence<size_t, 0, 1, 2> type; };
698template<> struct __make<4> { typedef integer_sequence<size_t, 0, 1, 2, 3> type; };
699template<> struct __make<5> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4> type; };
700template<> struct __make<6> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4, 5> type; };
701template<> struct __make<7> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4, 5, 6> type; };
702
703template<> struct __parity<0> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type> {}; };
704template<> struct __parity<1> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 1> {}; };
705template<> struct __parity<2> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 2, _Np - 1> {}; };
706template<> struct __parity<3> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 3, _Np - 2, _Np - 1> {}; };
707template<> struct __parity<4> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
708template<> struct __parity<5> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
709template<> struct __parity<6> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
710template<> struct __parity<7> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 7, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
711
712template<typename _Tp, typename _Up> struct __convert {
713 template<typename> struct __result;
714 template<_Tp ..._Np> struct __result<integer_sequence<_Tp, _Np...> > { typedef integer_sequence<_Up, _Np...> type; };
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000715};
Marshall Clow42e55e92013-07-03 19:20:30 +0000716template<typename _Tp> struct __convert<_Tp, _Tp> { template<typename _Up> struct __result { typedef _Up type; }; };
717
718}
719
720template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked =
721 typename __detail::__convert<size_t, _Tp>::template __result<typename __detail::__make<_Np>::type>::type;
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000722
723template <class _Tp, _Tp _Ep>
724struct __make_integer_sequence
725{
726 static_assert(is_integral<_Tp>::value,
727 "std::make_integer_sequence can only be instantiated with an integral type" );
728 static_assert(0 <= _Ep, "std::make_integer_sequence input shall not be negative");
Marshall Clow42e55e92013-07-03 19:20:30 +0000729 typedef __make_integer_sequence_unchecked<_Tp, _Ep> type;
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000730};
731
732template<class _Tp, _Tp _Np>
733 using make_integer_sequence = typename __make_integer_sequence<_Tp, _Np>::type;
734
735template<size_t _Np>
736 using make_index_sequence = make_integer_sequence<size_t, _Np>;
737
738template<class... _Tp>
739 using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;
740
741#endif // _LIBCPP_STD_VER > 11
742
Marshall Clowe2735d12013-07-08 20:54:40 +0000743#if _LIBCPP_STD_VER > 11
744template<class _T1, class _T2 = _T1>
Howard Hinnant1e564242013-10-04 22:09:00 +0000745inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe2735d12013-07-08 20:54:40 +0000746_T1 exchange(_T1& __obj, _T2 && __new_value)
747{
Howard Hinnant171771a2013-07-08 21:06:38 +0000748 _T1 __old_value = _VSTD::move(__obj);
749 __obj = _VSTD::forward<_T2>(__new_value);
750 return __old_value;
751}
Marshall Clowe2735d12013-07-08 20:54:40 +0000752#endif // _LIBCPP_STD_VER > 11
753
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000754_LIBCPP_END_NAMESPACE_STD
755
756#endif // _LIBCPP_UTILITY