blob: 095748d861b502f13dcc69ff8020cd04da53085b [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
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000294
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000295template <class _T1, class _T2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000296struct _LIBCPP_TYPE_VIS_ONLY pair
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000297{
298 typedef _T1 first_type;
299 typedef _T2 second_type;
300
301 _T1 first;
302 _T2 second;
303
Eric Fiselierc71c3042016-07-18 01:58:37 +0000304#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
Eric Fiselierd9e18192016-06-14 14:34:19 +0000305 _LIBCPP_INLINE_VISIBILITY
306 pair(const pair& __p)
307 _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
308 is_nothrow_copy_constructible<second_type>::value)
309 : first(__p.first),
310 second(__p.second)
311 {
312 }
Eric Fiselierc71c3042016-07-18 01:58:37 +0000313
314# ifndef _LIBCPP_CXX03_LANG
315 _LIBCPP_INLINE_VISIBILITY
316 pair(pair&& __p) _NOEXCEPT_(is_nothrow_move_constructible<first_type>::value &&
317 is_nothrow_move_constructible<second_type>::value)
318 : first(_VSTD::forward<first_type>(__p.first)),
319 second(_VSTD::forward<second_type>(__p.second))
320 {
321 }
322# endif
323#elif !defined(_LIBCPP_CXX03_LANG)
324 pair(pair const&) = default;
325 pair(pair&&) = default;
326#else
327 // Use the implicitly declared copy constructor in C++03
Marshall Clow206f6cd2013-07-16 17:45:44 +0000328#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +0000329
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000330#ifdef _LIBCPP_CXX03_LANG
331 _LIBCPP_INLINE_VISIBILITY
332 pair() : first(), second() {}
Eric Fiselier4be71c62016-07-25 02:36:42 +0000333
Howard Hinnant61aa6012011-07-01 19:24:36 +0000334 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000335 pair(_T1 const& __t1, _T2 const& __t2) : first(__t1), second(__t2) {}
336
337 template <class _U1, class _U2>
338 _LIBCPP_INLINE_VISIBILITY
339 pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
340
341 _LIBCPP_INLINE_VISIBILITY
342 pair& operator=(pair const& __p) {
343 first = __p.first;
344 second = __p.second;
345 return *this;
346 }
347#else
348 template <bool _Val>
349 using _EnableB = typename enable_if<_Val, bool>::type;
350
351 struct _CheckArgs {
352 template <class _U1, class _U2>
353 static constexpr bool __enable_default() {
354 return is_default_constructible<_U1>::value
355 && is_default_constructible<_U2>::value;
356 }
357
358 template <class _U1, class _U2>
359 static constexpr bool __enable_explicit() {
360 return is_constructible<first_type, _U1>::value
361 && is_constructible<second_type, _U2>::value
362 && (!is_convertible<_U1, first_type>::value
363 || !is_convertible<_U2, second_type>::value);
364 }
365
366 template <class _U1, class _U2>
367 static constexpr bool __enable_implicit() {
368 return is_constructible<first_type, _U1>::value
369 && is_constructible<second_type, _U2>::value
370 && is_convertible<_U1, first_type>::value
371 && is_convertible<_U2, second_type>::value;
372 }
373 };
374
375 template <bool _MaybeEnable>
376 using _CheckArgsDep = typename conditional<
377 _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type;
378
379 struct _CheckTupleLikeConstructor {
380 template <class _Tuple>
381 static constexpr bool __enable_implicit() {
382 return __tuple_convertible<_Tuple, pair>::value;
383 }
384
385 template <class _Tuple>
386 static constexpr bool __enable_explicit() {
387 return __tuple_constructible<_Tuple, pair>::value
388 && !__tuple_convertible<_Tuple, pair>::value;
389 }
390
391 template <class _Tuple>
392 static constexpr bool __enable_assign() {
393 return __tuple_assignable<_Tuple, pair>::value;
394 }
395 };
396
397 template <class _Tuple>
398 using _CheckTLC = typename conditional<
399 __tuple_like_with_size<_Tuple, 2>::value
400 && !is_same<typename decay<_Tuple>::type, pair>::value,
401 _CheckTupleLikeConstructor,
402 __check_tuple_constructor_fail
403 >::type;
404
405 template<bool _Dummy = true, _EnableB<
406 _CheckArgsDep<_Dummy>::template __enable_default<_T1, _T2>()
407 > = false>
408 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
409 pair() : first(), second() {}
410
411 template <bool _Dummy = true, _EnableB<
412 _CheckArgsDep<_Dummy>::template __enable_explicit<_T1 const&, _T2 const&>()
413 > = false>
414 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
415 explicit pair(_T1 const& __t1, _T2 const& __t2)
416 : first(__t1), second(__t2) {}
417
418 template<bool _Dummy = true, _EnableB<
419 _CheckArgsDep<_Dummy>::template __enable_implicit<_T1 const&, _T2 const&>()
420 > = false>
421 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
422 pair(_T1 const& __t1, _T2 const& __t2)
423 : first(__t1), second(__t2) {}
424
425 template<class _U1, class _U2, _EnableB<
426 _CheckArgs::template __enable_explicit<_U1, _U2>()
427 > = false>
428 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
429 explicit pair(_U1&& __u1, _U2&& __u2)
430 : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
431
432 template<class _U1, class _U2, _EnableB<
433 _CheckArgs::template __enable_implicit<_U1, _U2>()
434 > = false>
435 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
436 pair(_U1&& __u1, _U2&& __u2)
437 : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
438
439 template<class _U1, class _U2, _EnableB<
440 _CheckArgs::template __enable_explicit<_U1 const&, _U2 const&>()
441 > = false>
442 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
443 explicit pair(pair<_U1, _U2> const& __p)
444 : first(__p.first), second(__p.second) {}
445
446 template<class _U1, class _U2, _EnableB<
447 _CheckArgs::template __enable_implicit<_U1 const&, _U2 const&>()
448 > = false>
449 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
450 pair(pair<_U1, _U2> const& __p)
451 : first(__p.first), second(__p.second) {}
452
453 template<class _U1, class _U2, _EnableB<
454 _CheckArgs::template __enable_explicit<_U1, _U2>()
455 > = false>
456 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
457 explicit pair(pair<_U1, _U2>&&__p)
458 : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
459
460 template<class _U1, class _U2, _EnableB<
461 _CheckArgs::template __enable_implicit<_U1, _U2>()
462 > = false>
463 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
464 pair(pair<_U1, _U2>&& __p)
465 : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
466
467 template<class _Tuple, _EnableB<
468 _CheckTLC<_Tuple>::template __enable_explicit<_Tuple>()
469 > = false>
470 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
471 explicit pair(_Tuple&& __p)
472 : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
473 second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {}
474
475 template<class _Tuple, _EnableB<
476 _CheckTLC<_Tuple>::template __enable_implicit<_Tuple>()
477 > = false>
478 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
479 pair(_Tuple&& __p)
480 : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
481 second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {}
482
483 template <class... _Args1, class... _Args2>
484 _LIBCPP_INLINE_VISIBILITY
485 pair(piecewise_construct_t __pc,
486 tuple<_Args1...> __first_args, tuple<_Args2...> __second_args)
487 : pair(__pc, __first_args, __second_args,
488 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
489 typename __make_tuple_indices<sizeof...(_Args2) >::type()) {}
490
491 _LIBCPP_INLINE_VISIBILITY
492 pair& operator=(typename conditional<
493 is_copy_assignable<first_type>::value &&
494 is_copy_assignable<second_type>::value,
495 pair, __nat>::type const& __p)
Howard Hinnant61aa6012011-07-01 19:24:36 +0000496 _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value &&
497 is_nothrow_copy_assignable<second_type>::value)
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000498 {
499 first = __p.first;
500 second = __p.second;
501 return *this;
502 }
503
Eric Fiselier4be71c62016-07-25 02:36:42 +0000504 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000505 pair& operator=(typename conditional<
506 is_move_assignable<first_type>::value &&
507 is_move_assignable<second_type>::value,
508 pair, __nat>::type&& __p)
Eric Fiselier4be71c62016-07-25 02:36:42 +0000509 _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value &&
510 is_nothrow_move_assignable<second_type>::value)
511 {
512 first = _VSTD::forward<first_type>(__p.first);
513 second = _VSTD::forward<second_type>(__p.second);
514 return *this;
515 }
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000516
517 template <class _Tuple, _EnableB<
Eric Fiselier235d71f2016-08-29 01:43:41 +0000518 _CheckTLC<_Tuple>::template __enable_assign<_Tuple>()
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000519 > = false>
520 _LIBCPP_INLINE_VISIBILITY
521 pair& operator=(_Tuple&& __p) {
522 first = _VSTD::get<0>(_VSTD::forward<_Tuple>(__p));
523 second = _VSTD::get<1>(_VSTD::forward<_Tuple>(__p));
524 return *this;
525 }
Eric Fiselier4be71c62016-07-25 02:36:42 +0000526#endif
527
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000528 _LIBCPP_INLINE_VISIBILITY
529 void
Howard Hinnanta5e01212011-05-27 19:08:18 +0000530 swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value &&
531 __is_nothrow_swappable<second_type>::value)
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000532 {
Marshall Clow6b0e4192015-09-22 17:50:11 +0000533 using _VSTD::swap;
534 swap(first, __p.first);
535 swap(second, __p.second);
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000536 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000537private:
Howard Hinnant324bb032010-08-22 00:02:43 +0000538
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000539#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
Howard Hinnant5f5859c2011-01-13 20:05:05 +0000541 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000542 pair(piecewise_construct_t,
543 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
544 __tuple_indices<_I1...>, __tuple_indices<_I2...>);
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000545#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000546};
547
548template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000549inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000550bool
551operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
552{
553 return __x.first == __y.first && __x.second == __y.second;
554}
555
556template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000557inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000558bool
559operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
560{
561 return !(__x == __y);
562}
563
564template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000565inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000566bool
567operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
568{
569 return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);
570}
571
572template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000573inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000574bool
575operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
576{
577 return __y < __x;
578}
579
580template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000581inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000582bool
583operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
584{
585 return !(__x < __y);
586}
587
588template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000589inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000590bool
591operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
592{
593 return !(__y < __x);
594}
595
596template <class _T1, class _T2>
597inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000598typename enable_if
599<
600 __is_swappable<_T1>::value &&
601 __is_swappable<_T2>::value,
602 void
603>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000604swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000605 _NOEXCEPT_((__is_nothrow_swappable<_T1>::value &&
606 __is_nothrow_swappable<_T2>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000607{
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000608 __x.swap(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000609}
610
Howard Hinnant73d21a42010-09-04 23:28:19 +0000611#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000612
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000613
614template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +0000615struct __make_pair_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000616{
617 typedef _Tp type;
618};
619
620template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +0000621struct __make_pair_return_impl<reference_wrapper<_Tp>>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000622{
623 typedef _Tp& type;
624};
625
626template <class _Tp>
627struct __make_pair_return
628{
Marshall Clowa71f9562014-01-03 22:55:49 +0000629 typedef typename __make_pair_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000630};
631
632template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000633inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000634pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
635make_pair(_T1&& __t1, _T2&& __t2)
636{
637 return pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
Howard Hinnant0949eed2011-06-30 21:18:19 +0000638 (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000639}
640
Howard Hinnant73d21a42010-09-04 23:28:19 +0000641#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000642
643template <class _T1, class _T2>
644inline _LIBCPP_INLINE_VISIBILITY
645pair<_T1,_T2>
646make_pair(_T1 __x, _T2 __y)
647{
648 return pair<_T1, _T2>(__x, __y);
649}
650
Howard Hinnant73d21a42010-09-04 23:28:19 +0000651#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000652
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000653template <class _T1, class _T2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000654 class _LIBCPP_TYPE_VIS_ONLY tuple_size<pair<_T1, _T2> >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000655 : public integral_constant<size_t, 2> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656
657template <class _T1, class _T2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000658class _LIBCPP_TYPE_VIS_ONLY tuple_element<0, pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659{
660public:
661 typedef _T1 type;
662};
663
664template <class _T1, class _T2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000665class _LIBCPP_TYPE_VIS_ONLY tuple_element<1, pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000666{
667public:
668 typedef _T2 type;
669};
670
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000671template <size_t _Ip> struct __get_pair;
672
673template <>
674struct __get_pair<0>
675{
676 template <class _T1, class _T2>
677 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000678 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679 _T1&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000680 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000681
682 template <class _T1, class _T2>
683 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000684 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000685 const _T1&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000686 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000687
688#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
689
690 template <class _T1, class _T2>
691 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000692 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000693 _T1&&
Howard Hinnant0949eed2011-06-30 21:18:19 +0000694 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000695
Eric Fiselier199bee02015-12-18 00:36:55 +0000696 template <class _T1, class _T2>
697 static
698 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
699 const _T1&&
700 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);}
701
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000702#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000703};
704
705template <>
706struct __get_pair<1>
707{
708 template <class _T1, class _T2>
709 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000710 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711 _T2&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000712 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713
714 template <class _T1, class _T2>
715 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000716 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000717 const _T2&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000718 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000719
720#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
721
722 template <class _T1, class _T2>
723 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000724 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000725 _T2&&
Howard Hinnant0949eed2011-06-30 21:18:19 +0000726 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000727
Eric Fiselier199bee02015-12-18 00:36:55 +0000728 template <class _T1, class _T2>
729 static
730 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
731 const _T2&&
732 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);}
733
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000734#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000735};
736
737template <size_t _Ip, class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000738inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000739typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000740get(pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000741{
742 return __get_pair<_Ip>::get(__p);
743}
744
745template <size_t _Ip, class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000746inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000748get(const pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000749{
750 return __get_pair<_Ip>::get(__p);
751}
752
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000753#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
754
755template <size_t _Ip, class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000756inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000757typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000758get(pair<_T1, _T2>&& __p) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000759{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000760 return __get_pair<_Ip>::get(_VSTD::move(__p));
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000761}
762
Eric Fiselier199bee02015-12-18 00:36:55 +0000763template <size_t _Ip, class _T1, class _T2>
764inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
765const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
766get(const pair<_T1, _T2>&& __p) _NOEXCEPT
767{
768 return __get_pair<_Ip>::get(_VSTD::move(__p));
769}
770
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000771#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
772
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000773#if _LIBCPP_STD_VER > 11
Marshall Clowe8029e52013-07-13 02:54:05 +0000774template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000775inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000776constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT
777{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000778 return __get_pair<0>::get(__p);
Marshall Clowe8029e52013-07-13 02:54:05 +0000779}
780
781template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000782inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000783constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT
784{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000785 return __get_pair<0>::get(__p);
Marshall Clowe8029e52013-07-13 02:54:05 +0000786}
787
788template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000789inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000790constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT
791{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000792 return __get_pair<0>::get(_VSTD::move(__p));
Marshall Clowe8029e52013-07-13 02:54:05 +0000793}
794
795template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000796inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier199bee02015-12-18 00:36:55 +0000797constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT
798{
799 return __get_pair<0>::get(_VSTD::move(__p));
800}
801
802template <class _T1, class _T2>
803inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000804constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT
805{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000806 return __get_pair<1>::get(__p);
Marshall Clowe8029e52013-07-13 02:54:05 +0000807}
808
809template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000810inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000811constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT
812{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000813 return __get_pair<1>::get(__p);
Marshall Clowe8029e52013-07-13 02:54:05 +0000814}
815
816template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000817inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000818constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT
819{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000820 return __get_pair<1>::get(_VSTD::move(__p));
Marshall Clowe8029e52013-07-13 02:54:05 +0000821}
822
Eric Fiselier199bee02015-12-18 00:36:55 +0000823template <class _T1, class _T2>
824inline _LIBCPP_INLINE_VISIBILITY
825constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT
826{
827 return __get_pair<1>::get(_VSTD::move(__p));
828}
829
Marshall Clowe8029e52013-07-13 02:54:05 +0000830#endif
831
832#if _LIBCPP_STD_VER > 11
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000833
834template<class _Tp, _Tp... _Ip>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000835struct _LIBCPP_TYPE_VIS_ONLY integer_sequence
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000836{
837 typedef _Tp value_type;
838 static_assert( is_integral<_Tp>::value,
839 "std::integer_sequence can only be instantiated with an integral type" );
840 static
841 _LIBCPP_INLINE_VISIBILITY
842 constexpr
843 size_t
844 size() noexcept { return sizeof...(_Ip); }
845};
846
847template<size_t... _Ip>
848 using index_sequence = integer_sequence<size_t, _Ip...>;
849
Eric Fiselier76d24462015-12-09 22:03:06 +0000850#if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
851
852template <class _Tp, _Tp _Ep>
Eric Fiseliera3ccd962016-06-30 22:34:43 +0000853using __make_integer_sequence = __make_integer_seq<integer_sequence, _Tp, _Ep>;
Eric Fiselier76d24462015-12-09 22:03:06 +0000854
855#else
856
Marshall Clow42e55e92013-07-03 19:20:30 +0000857template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked =
Eric Fiseliera3ccd962016-06-30 22:34:43 +0000858 typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>;
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000859
860template <class _Tp, _Tp _Ep>
Eric Fiseliera3ccd962016-06-30 22:34:43 +0000861struct __make_integer_sequence_checked
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000862{
863 static_assert(is_integral<_Tp>::value,
864 "std::make_integer_sequence can only be instantiated with an integral type" );
Eric Fiselier76d24462015-12-09 22:03:06 +0000865 static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length");
Eric Fiselierd6a12b32015-12-16 00:35:45 +0000866 // Workaround GCC bug by preventing bad installations when 0 <= _Ep
867 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929
868 typedef __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type;
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000869};
870
Eric Fiseliera3ccd962016-06-30 22:34:43 +0000871template <class _Tp, _Tp _Ep>
872using __make_integer_sequence = typename __make_integer_sequence_checked<_Tp, _Ep>::type;
873
Eric Fiselier76d24462015-12-09 22:03:06 +0000874#endif
875
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000876template<class _Tp, _Tp _Np>
Eric Fiseliera3ccd962016-06-30 22:34:43 +0000877 using make_integer_sequence = __make_integer_sequence<_Tp, _Np>;
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000878
879template<size_t _Np>
880 using make_index_sequence = make_integer_sequence<size_t, _Np>;
881
882template<class... _Tp>
883 using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;
Marshall Clow5270a842016-06-19 19:29:52 +0000884
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000885#endif // _LIBCPP_STD_VER > 11
886
Marshall Clowe2735d12013-07-08 20:54:40 +0000887#if _LIBCPP_STD_VER > 11
888template<class _T1, class _T2 = _T1>
Howard Hinnant1e564242013-10-04 22:09:00 +0000889inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe2735d12013-07-08 20:54:40 +0000890_T1 exchange(_T1& __obj, _T2 && __new_value)
891{
Howard Hinnant171771a2013-07-08 21:06:38 +0000892 _T1 __old_value = _VSTD::move(__obj);
893 __obj = _VSTD::forward<_T2>(__new_value);
894 return __old_value;
Marshall Clow5270a842016-06-19 19:29:52 +0000895}
Marshall Clowe2735d12013-07-08 20:54:40 +0000896#endif // _LIBCPP_STD_VER > 11
897
Eric Fiseliereef85d92016-07-23 22:19:19 +0000898#if _LIBCPP_STD_VER > 14
899
900struct _LIBCPP_TYPE_VIS_ONLY __in_place_tag {};
901template <class> struct _LIBCPP_TYPE_VIS_ONLY __in_place_type_tag {};
902template <size_t> struct _LIBCPP_TYPE_VIS_ONLY __in_place_index_tag {};
903
904struct _LIBCPP_TYPE_VIS_ONLY in_place_tag;
905
906using in_place_t = in_place_tag(&)(__in_place_tag);
907template <class _Tp>
908using in_place_type_t = in_place_tag(&)(__in_place_type_tag<_Tp>);
909template <size_t _Nx>
910using in_place_index_t = in_place_tag(&)(__in_place_index_tag<_Nx>);
911
912struct in_place_tag {
913 in_place_tag() = delete;
914private:
915 explicit in_place_tag(__in_place_tag) {}
916
917 friend inline in_place_tag in_place(__in_place_tag __t);
918 template <class _Tp>
919 friend inline in_place_tag in_place(__in_place_type_tag<_Tp>);
920 template <size_t _Nx>
921 friend inline in_place_tag in_place(__in_place_index_tag<_Nx>);
922};
923
924inline in_place_tag in_place(__in_place_tag __t) {
925 _LIBCPP_ASSERT(false, "The in_place function cannot be invoked");
926 return in_place_tag(__t);
927}
928template <class _Tp>
929inline in_place_tag in_place(__in_place_type_tag<_Tp>) {
930 _LIBCPP_ASSERT(false, "The in_place function cannot be invoked");
931 return in_place_tag(__in_place_tag{});
932}
933template <size_t _Nx>
934inline in_place_tag in_place(__in_place_index_tag<_Nx>) {
935 _LIBCPP_ASSERT(false, "The in_place function cannot be invoked");
936 return in_place_tag(__in_place_tag{});
937}
938
Eric Fiselier15d8a562016-07-24 07:42:13 +0000939template <class _Tp> struct __is_inplace_type : false_type {};
940template <> struct __is_inplace_type<in_place_t> : true_type {};
941template <class _Tp> struct __is_inplace_type<in_place_type_t<_Tp>> : true_type {};
942template <size_t _Idx> struct __is_inplace_type<in_place_index_t<_Idx>> : true_type {};
943
Eric Fiseliereef85d92016-07-23 22:19:19 +0000944#endif // _LIBCPP_STD_VER > 14
945
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000946_LIBCPP_END_NAMESPACE_STD
947
948#endif // _LIBCPP_UTILITY