blob: 9a155a00fb40b539b28f7581edac45890460cdf3 [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
Marshall Clowf60d0922015-11-17 00:08:08 +000055template <class T> constexpr add_const<T>_t& as_const(T& t) noexcept; // C++17
56template <class T> void as_const(const T&&) = delete; // C++17
57
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000058template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
59
60template <class T1, class T2>
61struct pair
62{
63 typedef T1 first_type;
64 typedef T2 second_type;
65
66 T1 first;
67 T2 second;
68
69 pair(const pair&) = default;
Howard Hinnante9b2c2d2011-05-27 15:04:19 +000070 pair(pair&&) = default;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000071 constexpr pair();
Marshall Clow206f6cd2013-07-16 17:45:44 +000072 pair(const T1& x, const T2& y); // constexpr in C++14
73 template <class U, class V> pair(U&& x, V&& y); // constexpr in C++14
74 template <class U, class V> pair(const pair<U, V>& p); // constexpr in C++14
75 template <class U, class V> pair(pair<U, V>&& p); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000076 template <class... Args1, class... Args2>
77 pair(piecewise_construct_t, tuple<Args1...> first_args,
78 tuple<Args2...> second_args);
79
80 template <class U, class V> pair& operator=(const pair<U, V>& p);
Howard Hinnante9b2c2d2011-05-27 15:04:19 +000081 pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value &&
82 is_nothrow_move_assignable<T2>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000083 template <class U, class V> pair& operator=(pair<U, V>&& p);
84
Eric Fiselier8f1e73d2016-04-21 23:38:59 +000085 void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> &&
86 is_nothrow_swappable_v<T2>);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000087};
88
Marshall Clow206f6cd2013-07-16 17:45:44 +000089template <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
92template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
93template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
94template <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 +000095
Marshall Clow206f6cd2013-07-16 17:45:44 +000096template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14
Howard Hinnante9b2c2d2011-05-27 15:04:19 +000097template <class T1, class T2>
98void
99swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000100
101struct piecewise_construct_t { };
102constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
103
104template <class T> class tuple_size;
105template <size_t I, class T> class tuple_element;
106
Marshall Clow50fe0c72014-03-03 06:18:11 +0000107template <class T1, class T2> struct tuple_size<pair<T1, T2> >;
108template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >;
109template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000110
111template<size_t I, class T1, class T2>
Marshall Clow50fe0c72014-03-03 06:18:11 +0000112 typename tuple_element<I, pair<T1, T2> >::type&
113 get(pair<T1, T2>&) noexcept; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000114
115template<size_t I, class T1, class T2>
Marshall Clowa6607572015-11-19 19:45:29 +0000116 const typename tuple_element<I, pair<T1, T2> >::type&
Marshall Clow50fe0c72014-03-03 06:18:11 +0000117 get(const pair<T1, T2>&) noexcept; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000118
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000119template<size_t I, class T1, class T2>
Marshall Clow50fe0c72014-03-03 06:18:11 +0000120 typename tuple_element<I, pair<T1, T2> >::type&&
121 get(pair<T1, T2>&&) noexcept; // constexpr in C++14
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000122
Eric Fiselier199bee02015-12-18 00:36:55 +0000123template<size_t I, class T1, class T2>
124 const typename tuple_element<I, pair<T1, T2> >::type&&
125 get(const pair<T1, T2>&&) noexcept; // constexpr in C++14
126
Marshall Clowe8029e52013-07-13 02:54:05 +0000127template<class T1, class T2>
Marshall Clow50fe0c72014-03-03 06:18:11 +0000128 constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
Marshall Clowe8029e52013-07-13 02:54:05 +0000129
Eric Fiselier199bee02015-12-18 00:36:55 +0000130template<class T1, class T2>
Marshall Clowa6607572015-11-19 19:45:29 +0000131 constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14
Marshall Clowe8029e52013-07-13 02:54:05 +0000132
Eric Fiselier199bee02015-12-18 00:36:55 +0000133template<class T1, class T2>
Marshall Clow50fe0c72014-03-03 06:18:11 +0000134 constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14
Marshall Clowe8029e52013-07-13 02:54:05 +0000135
Eric Fiselier199bee02015-12-18 00:36:55 +0000136template<class T1, class T2>
137 constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14
138
139template<class T1, class T2>
140 constexpr T1& get(pair<T2, T1>&) noexcept; // C++14
141
142template<class T1, class T2>
143 constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14
144
145template<class T1, class T2>
146 constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14
147
148template<class T1, class T2>
149 constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14
150
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000151// C++14
152
153template<class T, T... I>
154struct integer_sequence
155{
156 typedef T value_type;
157
158 static constexpr size_t size() noexcept;
159};
160
161template<size_t... I>
162 using index_sequence = integer_sequence<size_t, I...>;
163
164template<class T, T N>
165 using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
166template<size_t N>
167 using make_index_sequence = make_integer_sequence<size_t, N>;
168
169template<class... T>
170 using index_sequence_for = make_index_sequence<sizeof...(T)>;
171
Marshall Clow5270a842016-06-19 19:29:52 +0000172template<class T, class U=T>
Marshall Clowe2735d12013-07-08 20:54:40 +0000173 T exchange(T& obj, U&& new_value);
Eric Fiseliereef85d92016-07-23 22:19:19 +0000174
175// 20.2.7, in-place construction // C++17
176struct in_place_tag { in_place_tag() = delete; }; // C++17
177using in_place_t = in_place_tag(&)(unspecified );
178template <class T>
179 using in_place_type_t = in_place_tag(&)(unspecified <T>);
180template <size_t I>
181 using in_place_index_t = in_place_tag(&)(unspecified <I>);
182in_place_tag in_place(unspecified );
183template <class T>
184 in_place_tag in_place(unspecified <T>);
185template <size_t I>
186 in_place_tag in_place(unspecified <I>);
187
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000188} // std
189
190*/
191
192#include <__config>
193#include <__tuple>
194#include <type_traits>
Ben Craigd59d4162016-04-19 20:13:55 +0000195#include <initializer_list>
Eric Fiseliereef85d92016-07-23 22:19:19 +0000196#include <__debug>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000197
Howard Hinnant08e17472011-10-17 20:05:10 +0000198#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000199#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000200#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000201
202_LIBCPP_BEGIN_NAMESPACE_STD
203
204namespace rel_ops
205{
206
207template<class _Tp>
208inline _LIBCPP_INLINE_VISIBILITY
209bool
210operator!=(const _Tp& __x, const _Tp& __y)
211{
212 return !(__x == __y);
213}
214
215template<class _Tp>
216inline _LIBCPP_INLINE_VISIBILITY
217bool
218operator> (const _Tp& __x, const _Tp& __y)
219{
220 return __y < __x;
221}
222
223template<class _Tp>
224inline _LIBCPP_INLINE_VISIBILITY
225bool
226operator<=(const _Tp& __x, const _Tp& __y)
227{
228 return !(__y < __x);
229}
230
231template<class _Tp>
232inline _LIBCPP_INLINE_VISIBILITY
233bool
234operator>=(const _Tp& __x, const _Tp& __y)
235{
236 return !(__x < __y);
237}
238
239} // rel_ops
240
241// swap_ranges
242
Marshall Clowfd8ed7f2015-01-06 19:20:49 +0000243
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000244template <class _ForwardIterator1, class _ForwardIterator2>
245inline _LIBCPP_INLINE_VISIBILITY
246_ForwardIterator2
247swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
248{
Eric Fiselierb9919752014-10-27 19:28:20 +0000249 for(; __first1 != __last1; ++__first1, (void) ++__first2)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000250 swap(*__first1, *__first2);
251 return __first2;
252}
253
Eric Fiselier8f1e73d2016-04-21 23:38:59 +0000254// forward declared in <type_traits>
Howard Hinnant99968442011-11-29 18:15:50 +0000255template<class _Tp, size_t _Np>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000256inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8f1e73d2016-04-21 23:38:59 +0000257typename enable_if<
258 __is_swappable<_Tp>::value
259>::type
Howard Hinnant99968442011-11-29 18:15:50 +0000260swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000261{
Howard Hinnant99968442011-11-29 18:15:50 +0000262 _VSTD::swap_ranges(__a, __a + _Np, __b);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000263}
264
265template <class _Tp>
Marshall Clow01a0e902013-07-15 20:46:11 +0000266inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant73d21a42010-09-04 23:28:19 +0000267#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000268typename conditional
269<
Howard Hinnant1468b662010-11-19 22:17:28 +0000270 !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000271 const _Tp&,
272 _Tp&&
273>::type
Howard Hinnant73d21a42010-09-04 23:28:19 +0000274#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000275const _Tp&
276#endif
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000277move_if_noexcept(_Tp& __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000278{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000279 return _VSTD::move(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000280}
281
Marshall Clowf60d0922015-11-17 00:08:08 +0000282#if _LIBCPP_STD_VER > 14
283template <class _Tp> constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; }
284template <class _Tp> void as_const(const _Tp&&) = delete;
285#endif
286
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000287struct _LIBCPP_TYPE_VIS_ONLY piecewise_construct_t { };
Howard Hinnant616e92d2012-04-03 23:45:46 +0000288#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_UTILITY)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000289extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
Howard Hinnant2a5349b2012-04-03 21:09:48 +0000290#else
291constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
292#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000293
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000294template <class _T1, class _T2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000295struct _LIBCPP_TYPE_VIS_ONLY pair
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296{
297 typedef _T1 first_type;
298 typedef _T2 second_type;
299
300 _T1 first;
301 _T2 second;
302
Eric Fiselier9bef1ff2015-12-23 08:20:26 +0000303#ifndef _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS
304 template <bool _Dummy = true, class = typename enable_if<
305 __dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
306 __dependent_type<is_default_constructible<_T2>, _Dummy>::value
307 >::type>
308#endif
Howard Hinnant2a5349b2012-04-03 21:09:48 +0000309 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000310
Marshall Clow206f6cd2013-07-16 17:45:44 +0000311 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
312 pair(const _T1& __x, const _T2& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000313 : first(__x), second(__y) {}
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 Hinnant9c59d382011-07-27 19:25:28 +0000317 pair(const pair<_U1, _U2>& __p
318#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantfe592762012-06-09 20:01:23 +0000319 ,typename enable_if<is_convertible<const _U1&, _T1>::value &&
320 is_convertible<const _U2&, _T2>::value>::type* = 0
Howard Hinnant9c59d382011-07-27 19:25:28 +0000321#endif
322 )
Howard Hinnant469d4192011-04-29 18:10:55 +0000323 : first(__p.first), second(__p.second) {}
324
Eric Fiselierc71c3042016-07-18 01:58:37 +0000325#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
Eric Fiselierd9e18192016-06-14 14:34:19 +0000326 _LIBCPP_INLINE_VISIBILITY
327 pair(const pair& __p)
328 _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
329 is_nothrow_copy_constructible<second_type>::value)
330 : first(__p.first),
331 second(__p.second)
332 {
333 }
Eric Fiselierc71c3042016-07-18 01:58:37 +0000334
335# ifndef _LIBCPP_CXX03_LANG
336 _LIBCPP_INLINE_VISIBILITY
337 pair(pair&& __p) _NOEXCEPT_(is_nothrow_move_constructible<first_type>::value &&
338 is_nothrow_move_constructible<second_type>::value)
339 : first(_VSTD::forward<first_type>(__p.first)),
340 second(_VSTD::forward<second_type>(__p.second))
341 {
342 }
343# endif
344#elif !defined(_LIBCPP_CXX03_LANG)
345 pair(pair const&) = default;
346 pair(pair&&) = default;
347#else
348 // Use the implicitly declared copy constructor in C++03
Marshall Clow206f6cd2013-07-16 17:45:44 +0000349#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +0000350
Eric Fiselier8b5233f2016-07-24 05:51:11 +0000351 typedef typename remove_reference<_T1>::type _T1Unref;
352 typedef typename remove_reference<_T2>::type _T2Unref;
353
Eric Fiselier932604f2016-07-25 00:48:36 +0000354#if !defined(_LIBCPP_CXX03_LANG)
Eric Fiselier8b5233f2016-07-24 05:51:11 +0000355 typedef integral_constant<bool,
356 is_copy_assignable<_T1>::value
357 && is_copy_assignable<_T2>::value> _CanCopyAssign;
Eric Fiselier932604f2016-07-25 00:48:36 +0000358#else
359 typedef true_type _CanCopyAssign;
360#endif
Eric Fiselier8b5233f2016-07-24 05:51:11 +0000361
Howard Hinnant61aa6012011-07-01 19:24:36 +0000362 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8b5233f2016-07-24 05:51:11 +0000363 pair& operator=(typename conditional<_CanCopyAssign::value, pair, __nat>::type const& __p)
Howard Hinnant61aa6012011-07-01 19:24:36 +0000364 _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value &&
365 is_nothrow_copy_assignable<second_type>::value)
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000366 {
367 first = __p.first;
368 second = __p.second;
369 return *this;
370 }
371
Howard Hinnant73d21a42010-09-04 23:28:19 +0000372#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000373
374 template <class _U1, class _U2,
Howard Hinnantfe592762012-06-09 20:01:23 +0000375 class = typename enable_if<is_convertible<_U1, first_type>::value &&
376 is_convertible<_U2, second_type>::value>::type>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000377 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378 pair(_U1&& __u1, _U2&& __u2)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000379 : first(_VSTD::forward<_U1>(__u1)),
380 second(_VSTD::forward<_U2>(__u2))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381 {}
382
Howard Hinnant469d4192011-04-29 18:10:55 +0000383 template<class _U1, class _U2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000384 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant469d4192011-04-29 18:10:55 +0000385 pair(pair<_U1, _U2>&& __p,
Howard Hinnantfe592762012-06-09 20:01:23 +0000386 typename enable_if<is_convertible<_U1, _T1>::value &&
387 is_convertible<_U2, _T2>::value>::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000388 : first(_VSTD::forward<_U1>(__p.first)),
389 second(_VSTD::forward<_U2>(__p.second)) {}
Howard Hinnant469d4192011-04-29 18:10:55 +0000390
Eric Fiselier8b5233f2016-07-24 05:51:11 +0000391 typedef integral_constant<bool,
392 is_move_assignable<_T1>::value
393 && is_move_assignable<_T2>::value> _CanMoveAssign;
394
Howard Hinnant61aa6012011-07-01 19:24:36 +0000395 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000396 pair&
Eric Fiselier8b5233f2016-07-24 05:51:11 +0000397 operator=(typename conditional<_CanMoveAssign::value, pair, __nat>::type&& __p)
398 _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value &&
399 is_nothrow_move_assignable<second_type>::value)
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000400 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000401 first = _VSTD::forward<first_type>(__p.first);
402 second = _VSTD::forward<second_type>(__p.second);
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000403 return *this;
404 }
405
Michael J. Spencer626916f2010-12-10 19:47:54 +0000406#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000407 template<class _Tuple,
408 class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000409 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000410 pair(_Tuple&& __p)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000411 : first(_VSTD::forward<typename tuple_element<0,
Marshall Clowba6dbf42014-06-24 00:46:19 +0000412 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<0>(__p))),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000413 second(_VSTD::forward<typename tuple_element<1,
Marshall Clowba6dbf42014-06-24 00:46:19 +0000414 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<1>(__p)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415 {}
416
Michael J. Spencer626916f2010-12-10 19:47:54 +0000417
Howard Hinnant726a76f2010-11-16 21:10:23 +0000418
Howard Hinnant6cc99fa2011-12-19 17:58:44 +0000419 template <class... _Args1, class... _Args2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000421 pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
422 tuple<_Args2...> __second_args)
Howard Hinnant324bb032010-08-22 00:02:43 +0000423 : pair(__pc, __first_args, __second_args,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000424 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
425 typename __make_tuple_indices<sizeof...(_Args2) >::type())
426 {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427
428 template <class _Tuple,
Eric Fiselier8b5233f2016-07-24 05:51:11 +0000429 class = typename enable_if<!is_same<typename decay<_Tuple>::type, pair>::value && __tuple_assignable<_Tuple, pair>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000430 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000431 pair&
432 operator=(_Tuple&& __p)
433 {
434 typedef typename __make_tuple_types<_Tuple>::type _TupleRef;
435 typedef typename tuple_element<0, _TupleRef>::type _U0;
436 typedef typename tuple_element<1, _TupleRef>::type _U1;
Howard Hinnant0949eed2011-06-30 21:18:19 +0000437 first = _VSTD::forward<_U0>(_VSTD::get<0>(__p));
438 second = _VSTD::forward<_U1>(_VSTD::get<1>(__p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439 return *this;
440 }
441
Michael J. Spencer626916f2010-12-10 19:47:54 +0000442#endif // _LIBCPP_HAS_NO_VARIADICS
443
Howard Hinnant73d21a42010-09-04 23:28:19 +0000444#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000445 _LIBCPP_INLINE_VISIBILITY
446 void
Howard Hinnanta5e01212011-05-27 19:08:18 +0000447 swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value &&
448 __is_nothrow_swappable<second_type>::value)
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000449 {
Marshall Clow6b0e4192015-09-22 17:50:11 +0000450 using _VSTD::swap;
451 swap(first, __p.first);
452 swap(second, __p.second);
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000453 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000454private:
Howard Hinnant324bb032010-08-22 00:02:43 +0000455
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000456#ifndef _LIBCPP_HAS_NO_VARIADICS
457 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
Howard Hinnant5f5859c2011-01-13 20:05:05 +0000458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459 pair(piecewise_construct_t,
460 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
461 __tuple_indices<_I1...>, __tuple_indices<_I2...>);
Howard Hinnant324bb032010-08-22 00:02:43 +0000462#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000463};
464
465template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000466inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000467bool
468operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
469{
470 return __x.first == __y.first && __x.second == __y.second;
471}
472
473template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000474inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000475bool
476operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
477{
478 return !(__x == __y);
479}
480
481template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000482inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000483bool
484operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
485{
486 return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);
487}
488
489template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000490inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000491bool
492operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
493{
494 return __y < __x;
495}
496
497template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000498inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000499bool
500operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
501{
502 return !(__x < __y);
503}
504
505template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000506inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000507bool
508operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
509{
510 return !(__y < __x);
511}
512
513template <class _T1, class _T2>
514inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000515typename enable_if
516<
517 __is_swappable<_T1>::value &&
518 __is_swappable<_T2>::value,
519 void
520>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000522 _NOEXCEPT_((__is_nothrow_swappable<_T1>::value &&
523 __is_nothrow_swappable<_T2>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524{
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000525 __x.swap(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000526}
527
Howard Hinnant73d21a42010-09-04 23:28:19 +0000528#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000530
531template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +0000532struct __make_pair_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533{
534 typedef _Tp type;
535};
536
537template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +0000538struct __make_pair_return_impl<reference_wrapper<_Tp>>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000539{
540 typedef _Tp& type;
541};
542
543template <class _Tp>
544struct __make_pair_return
545{
Marshall Clowa71f9562014-01-03 22:55:49 +0000546 typedef typename __make_pair_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000547};
548
549template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000550inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000551pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
552make_pair(_T1&& __t1, _T2&& __t2)
553{
554 return pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
Howard Hinnant0949eed2011-06-30 21:18:19 +0000555 (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000556}
557
Howard Hinnant73d21a42010-09-04 23:28:19 +0000558#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000559
560template <class _T1, class _T2>
561inline _LIBCPP_INLINE_VISIBILITY
562pair<_T1,_T2>
563make_pair(_T1 __x, _T2 __y)
564{
565 return pair<_T1, _T2>(__x, __y);
566}
567
Howard Hinnant73d21a42010-09-04 23:28:19 +0000568#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000569
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000570template <class _T1, class _T2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000571 class _LIBCPP_TYPE_VIS_ONLY tuple_size<pair<_T1, _T2> >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000572 : public integral_constant<size_t, 2> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000573
574template <class _T1, class _T2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000575class _LIBCPP_TYPE_VIS_ONLY tuple_element<0, pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000576{
577public:
578 typedef _T1 type;
579};
580
581template <class _T1, class _T2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000582class _LIBCPP_TYPE_VIS_ONLY tuple_element<1, pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000583{
584public:
585 typedef _T2 type;
586};
587
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000588template <size_t _Ip> struct __get_pair;
589
590template <>
591struct __get_pair<0>
592{
593 template <class _T1, class _T2>
594 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000595 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000596 _T1&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000597 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000598
599 template <class _T1, class _T2>
600 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000601 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000602 const _T1&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000603 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000604
605#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
606
607 template <class _T1, class _T2>
608 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000609 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000610 _T1&&
Howard Hinnant0949eed2011-06-30 21:18:19 +0000611 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000612
Eric Fiselier199bee02015-12-18 00:36:55 +0000613 template <class _T1, class _T2>
614 static
615 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
616 const _T1&&
617 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);}
618
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000619#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000620};
621
622template <>
623struct __get_pair<1>
624{
625 template <class _T1, class _T2>
626 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000627 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000628 _T2&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000629 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000630
631 template <class _T1, class _T2>
632 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000633 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000634 const _T2&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000635 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000636
637#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
638
639 template <class _T1, class _T2>
640 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000641 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000642 _T2&&
Howard Hinnant0949eed2011-06-30 21:18:19 +0000643 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000644
Eric Fiselier199bee02015-12-18 00:36:55 +0000645 template <class _T1, class _T2>
646 static
647 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
648 const _T2&&
649 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);}
650
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000651#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000652};
653
654template <size_t _Ip, class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000655inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000657get(pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000658{
659 return __get_pair<_Ip>::get(__p);
660}
661
662template <size_t _Ip, class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000663inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000664const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000665get(const pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000666{
667 return __get_pair<_Ip>::get(__p);
668}
669
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000670#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
671
672template <size_t _Ip, class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000673inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000674typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000675get(pair<_T1, _T2>&& __p) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000676{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000677 return __get_pair<_Ip>::get(_VSTD::move(__p));
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000678}
679
Eric Fiselier199bee02015-12-18 00:36:55 +0000680template <size_t _Ip, class _T1, class _T2>
681inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
682const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
683get(const pair<_T1, _T2>&& __p) _NOEXCEPT
684{
685 return __get_pair<_Ip>::get(_VSTD::move(__p));
686}
687
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000688#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
689
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000690#if _LIBCPP_STD_VER > 11
Marshall Clowe8029e52013-07-13 02:54:05 +0000691template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000692inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000693constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT
694{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000695 return __get_pair<0>::get(__p);
Marshall Clowe8029e52013-07-13 02:54:05 +0000696}
697
698template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000699inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000700constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT
701{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000702 return __get_pair<0>::get(__p);
Marshall Clowe8029e52013-07-13 02:54:05 +0000703}
704
705template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000706inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000707constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT
708{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000709 return __get_pair<0>::get(_VSTD::move(__p));
Marshall Clowe8029e52013-07-13 02:54:05 +0000710}
711
712template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000713inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier199bee02015-12-18 00:36:55 +0000714constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT
715{
716 return __get_pair<0>::get(_VSTD::move(__p));
717}
718
719template <class _T1, class _T2>
720inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000721constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT
722{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000723 return __get_pair<1>::get(__p);
Marshall Clowe8029e52013-07-13 02:54:05 +0000724}
725
726template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000727inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000728constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT
729{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000730 return __get_pair<1>::get(__p);
Marshall Clowe8029e52013-07-13 02:54:05 +0000731}
732
733template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000734inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000735constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT
736{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000737 return __get_pair<1>::get(_VSTD::move(__p));
Marshall Clowe8029e52013-07-13 02:54:05 +0000738}
739
Eric Fiselier199bee02015-12-18 00:36:55 +0000740template <class _T1, class _T2>
741inline _LIBCPP_INLINE_VISIBILITY
742constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT
743{
744 return __get_pair<1>::get(_VSTD::move(__p));
745}
746
Marshall Clowe8029e52013-07-13 02:54:05 +0000747#endif
748
749#if _LIBCPP_STD_VER > 11
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000750
751template<class _Tp, _Tp... _Ip>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000752struct _LIBCPP_TYPE_VIS_ONLY integer_sequence
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000753{
754 typedef _Tp value_type;
755 static_assert( is_integral<_Tp>::value,
756 "std::integer_sequence can only be instantiated with an integral type" );
757 static
758 _LIBCPP_INLINE_VISIBILITY
759 constexpr
760 size_t
761 size() noexcept { return sizeof...(_Ip); }
762};
763
764template<size_t... _Ip>
765 using index_sequence = integer_sequence<size_t, _Ip...>;
766
Eric Fiselier76d24462015-12-09 22:03:06 +0000767#if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
768
769template <class _Tp, _Tp _Ep>
Eric Fiseliera3ccd962016-06-30 22:34:43 +0000770using __make_integer_sequence = __make_integer_seq<integer_sequence, _Tp, _Ep>;
Eric Fiselier76d24462015-12-09 22:03:06 +0000771
772#else
773
Marshall Clow42e55e92013-07-03 19:20:30 +0000774template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked =
Eric Fiseliera3ccd962016-06-30 22:34:43 +0000775 typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>;
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000776
777template <class _Tp, _Tp _Ep>
Eric Fiseliera3ccd962016-06-30 22:34:43 +0000778struct __make_integer_sequence_checked
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000779{
780 static_assert(is_integral<_Tp>::value,
781 "std::make_integer_sequence can only be instantiated with an integral type" );
Eric Fiselier76d24462015-12-09 22:03:06 +0000782 static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length");
Eric Fiselierd6a12b32015-12-16 00:35:45 +0000783 // Workaround GCC bug by preventing bad installations when 0 <= _Ep
784 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929
785 typedef __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type;
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000786};
787
Eric Fiseliera3ccd962016-06-30 22:34:43 +0000788template <class _Tp, _Tp _Ep>
789using __make_integer_sequence = typename __make_integer_sequence_checked<_Tp, _Ep>::type;
790
Eric Fiselier76d24462015-12-09 22:03:06 +0000791#endif
792
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000793template<class _Tp, _Tp _Np>
Eric Fiseliera3ccd962016-06-30 22:34:43 +0000794 using make_integer_sequence = __make_integer_sequence<_Tp, _Np>;
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000795
796template<size_t _Np>
797 using make_index_sequence = make_integer_sequence<size_t, _Np>;
798
799template<class... _Tp>
800 using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;
Marshall Clow5270a842016-06-19 19:29:52 +0000801
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000802#endif // _LIBCPP_STD_VER > 11
803
Marshall Clowe2735d12013-07-08 20:54:40 +0000804#if _LIBCPP_STD_VER > 11
805template<class _T1, class _T2 = _T1>
Howard Hinnant1e564242013-10-04 22:09:00 +0000806inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe2735d12013-07-08 20:54:40 +0000807_T1 exchange(_T1& __obj, _T2 && __new_value)
808{
Howard Hinnant171771a2013-07-08 21:06:38 +0000809 _T1 __old_value = _VSTD::move(__obj);
810 __obj = _VSTD::forward<_T2>(__new_value);
811 return __old_value;
Marshall Clow5270a842016-06-19 19:29:52 +0000812}
Marshall Clowe2735d12013-07-08 20:54:40 +0000813#endif // _LIBCPP_STD_VER > 11
814
Eric Fiseliereef85d92016-07-23 22:19:19 +0000815#if _LIBCPP_STD_VER > 14
816
817struct _LIBCPP_TYPE_VIS_ONLY __in_place_tag {};
818template <class> struct _LIBCPP_TYPE_VIS_ONLY __in_place_type_tag {};
819template <size_t> struct _LIBCPP_TYPE_VIS_ONLY __in_place_index_tag {};
820
821struct _LIBCPP_TYPE_VIS_ONLY in_place_tag;
822
823using in_place_t = in_place_tag(&)(__in_place_tag);
824template <class _Tp>
825using in_place_type_t = in_place_tag(&)(__in_place_type_tag<_Tp>);
826template <size_t _Nx>
827using in_place_index_t = in_place_tag(&)(__in_place_index_tag<_Nx>);
828
829struct in_place_tag {
830 in_place_tag() = delete;
831private:
832 explicit in_place_tag(__in_place_tag) {}
833
834 friend inline in_place_tag in_place(__in_place_tag __t);
835 template <class _Tp>
836 friend inline in_place_tag in_place(__in_place_type_tag<_Tp>);
837 template <size_t _Nx>
838 friend inline in_place_tag in_place(__in_place_index_tag<_Nx>);
839};
840
841inline in_place_tag in_place(__in_place_tag __t) {
842 _LIBCPP_ASSERT(false, "The in_place function cannot be invoked");
843 return in_place_tag(__t);
844}
845template <class _Tp>
846inline in_place_tag in_place(__in_place_type_tag<_Tp>) {
847 _LIBCPP_ASSERT(false, "The in_place function cannot be invoked");
848 return in_place_tag(__in_place_tag{});
849}
850template <size_t _Nx>
851inline in_place_tag in_place(__in_place_index_tag<_Nx>) {
852 _LIBCPP_ASSERT(false, "The in_place function cannot be invoked");
853 return in_place_tag(__in_place_tag{});
854}
855
Eric Fiselier15d8a562016-07-24 07:42:13 +0000856template <class _Tp> struct __is_inplace_type : false_type {};
857template <> struct __is_inplace_type<in_place_t> : true_type {};
858template <class _Tp> struct __is_inplace_type<in_place_type_t<_Tp>> : true_type {};
859template <size_t _Idx> struct __is_inplace_type<in_place_index_t<_Idx>> : true_type {};
860
Eric Fiseliereef85d92016-07-23 22:19:19 +0000861#endif // _LIBCPP_STD_VER > 14
862
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000863_LIBCPP_END_NAMESPACE_STD
864
865#endif // _LIBCPP_UTILITY