blob: 364221433a8aee08b189d8e0f43d73abda87baca [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
Eric Fiselier8d335262016-11-17 19:24:04 +0000176struct in_place_t {
177 explicit in_place_t() = default;
178};
179inline constexpr in_place_t in_place{};
Eric Fiseliereef85d92016-07-23 22:19:19 +0000180template <class T>
Eric Fiselier8d335262016-11-17 19:24:04 +0000181 struct in_place_type_t {
182 explicit in_place_type_t() = default;
183 };
Eric Fiseliereef85d92016-07-23 22:19:19 +0000184template <class T>
Eric Fiselier8d335262016-11-17 19:24:04 +0000185 inline constexpr in_place_type_t<T> in_place_type{};
Eric Fiseliereef85d92016-07-23 22:19:19 +0000186template <size_t I>
Eric Fiselier8d335262016-11-17 19:24:04 +0000187 struct in_place_index_t {
188 explicit in_place_index_t() = default;
189 };
190template <size_t I>
191 inline constexpr in_place_index_t<I> in_place_index{};
Eric Fiseliereef85d92016-07-23 22:19:19 +0000192
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000193} // std
194
195*/
196
197#include <__config>
198#include <__tuple>
199#include <type_traits>
Ben Craigd59d4162016-04-19 20:13:55 +0000200#include <initializer_list>
Eric Fiseliereef85d92016-07-23 22:19:19 +0000201#include <__debug>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000202
Howard Hinnant08e17472011-10-17 20:05:10 +0000203#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000204#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000205#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000206
207_LIBCPP_BEGIN_NAMESPACE_STD
208
209namespace rel_ops
210{
211
212template<class _Tp>
213inline _LIBCPP_INLINE_VISIBILITY
214bool
215operator!=(const _Tp& __x, const _Tp& __y)
216{
217 return !(__x == __y);
218}
219
220template<class _Tp>
221inline _LIBCPP_INLINE_VISIBILITY
222bool
223operator> (const _Tp& __x, const _Tp& __y)
224{
225 return __y < __x;
226}
227
228template<class _Tp>
229inline _LIBCPP_INLINE_VISIBILITY
230bool
231operator<=(const _Tp& __x, const _Tp& __y)
232{
233 return !(__y < __x);
234}
235
236template<class _Tp>
237inline _LIBCPP_INLINE_VISIBILITY
238bool
239operator>=(const _Tp& __x, const _Tp& __y)
240{
241 return !(__x < __y);
242}
243
244} // rel_ops
245
246// swap_ranges
247
Marshall Clowfd8ed7f2015-01-06 19:20:49 +0000248
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000249template <class _ForwardIterator1, class _ForwardIterator2>
250inline _LIBCPP_INLINE_VISIBILITY
251_ForwardIterator2
252swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
253{
Eric Fiselierb9919752014-10-27 19:28:20 +0000254 for(; __first1 != __last1; ++__first1, (void) ++__first2)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000255 swap(*__first1, *__first2);
256 return __first2;
257}
258
Eric Fiselier8f1e73d2016-04-21 23:38:59 +0000259// forward declared in <type_traits>
Howard Hinnant99968442011-11-29 18:15:50 +0000260template<class _Tp, size_t _Np>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000261inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8f1e73d2016-04-21 23:38:59 +0000262typename enable_if<
263 __is_swappable<_Tp>::value
264>::type
Howard Hinnant99968442011-11-29 18:15:50 +0000265swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000266{
Howard Hinnant99968442011-11-29 18:15:50 +0000267 _VSTD::swap_ranges(__a, __a + _Np, __b);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000268}
269
270template <class _Tp>
Marshall Clow01a0e902013-07-15 20:46:11 +0000271inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant73d21a42010-09-04 23:28:19 +0000272#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000273typename conditional
274<
Howard Hinnant1468b662010-11-19 22:17:28 +0000275 !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276 const _Tp&,
277 _Tp&&
278>::type
Howard Hinnant73d21a42010-09-04 23:28:19 +0000279#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000280const _Tp&
281#endif
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000282move_if_noexcept(_Tp& __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000283{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000284 return _VSTD::move(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000285}
286
Marshall Clowf60d0922015-11-17 00:08:08 +0000287#if _LIBCPP_STD_VER > 14
288template <class _Tp> constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; }
289template <class _Tp> void as_const(const _Tp&&) = delete;
290#endif
291
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000292struct _LIBCPP_TYPE_VIS_ONLY piecewise_construct_t { };
Howard Hinnant616e92d2012-04-03 23:45:46 +0000293#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_UTILITY)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000294extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
Howard Hinnant2a5349b2012-04-03 21:09:48 +0000295#else
296constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
297#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000298
Eric Fiseliere2bd16c2016-10-11 21:22:21 +0000299#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
300struct __non_trivially_copyable_base {
301 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
302 __non_trivially_copyable_base() _NOEXCEPT {}
303 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
304 __non_trivially_copyable_base(__non_trivially_copyable_base const&) _NOEXCEPT {}
305};
306#endif
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000307
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000308template <class _T1, class _T2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000309struct _LIBCPP_TYPE_VIS_ONLY pair
Eric Fiseliere2bd16c2016-10-11 21:22:21 +0000310#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
311: private __non_trivially_copyable_base
312#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000313{
314 typedef _T1 first_type;
315 typedef _T2 second_type;
316
317 _T1 first;
318 _T2 second;
319
Eric Fiseliere2bd16c2016-10-11 21:22:21 +0000320#if !defined(_LIBCPP_CXX03_LANG)
Eric Fiselierc71c3042016-07-18 01:58:37 +0000321 pair(pair const&) = default;
322 pair(pair&&) = default;
323#else
324 // Use the implicitly declared copy constructor in C++03
Marshall Clow206f6cd2013-07-16 17:45:44 +0000325#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +0000326
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000327#ifdef _LIBCPP_CXX03_LANG
328 _LIBCPP_INLINE_VISIBILITY
329 pair() : first(), second() {}
Eric Fiselier4be71c62016-07-25 02:36:42 +0000330
Howard Hinnant61aa6012011-07-01 19:24:36 +0000331 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000332 pair(_T1 const& __t1, _T2 const& __t2) : first(__t1), second(__t2) {}
333
334 template <class _U1, class _U2>
335 _LIBCPP_INLINE_VISIBILITY
336 pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
337
338 _LIBCPP_INLINE_VISIBILITY
339 pair& operator=(pair const& __p) {
340 first = __p.first;
341 second = __p.second;
342 return *this;
343 }
344#else
345 template <bool _Val>
346 using _EnableB = typename enable_if<_Val, bool>::type;
347
348 struct _CheckArgs {
349 template <class _U1, class _U2>
350 static constexpr bool __enable_default() {
351 return is_default_constructible<_U1>::value
352 && is_default_constructible<_U2>::value;
353 }
354
355 template <class _U1, class _U2>
356 static constexpr bool __enable_explicit() {
357 return is_constructible<first_type, _U1>::value
358 && is_constructible<second_type, _U2>::value
359 && (!is_convertible<_U1, first_type>::value
360 || !is_convertible<_U2, second_type>::value);
361 }
362
363 template <class _U1, class _U2>
364 static constexpr bool __enable_implicit() {
365 return is_constructible<first_type, _U1>::value
366 && is_constructible<second_type, _U2>::value
367 && is_convertible<_U1, first_type>::value
368 && is_convertible<_U2, second_type>::value;
369 }
370 };
371
372 template <bool _MaybeEnable>
373 using _CheckArgsDep = typename conditional<
374 _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type;
375
376 struct _CheckTupleLikeConstructor {
377 template <class _Tuple>
378 static constexpr bool __enable_implicit() {
379 return __tuple_convertible<_Tuple, pair>::value;
380 }
381
382 template <class _Tuple>
383 static constexpr bool __enable_explicit() {
384 return __tuple_constructible<_Tuple, pair>::value
385 && !__tuple_convertible<_Tuple, pair>::value;
386 }
387
388 template <class _Tuple>
389 static constexpr bool __enable_assign() {
390 return __tuple_assignable<_Tuple, pair>::value;
391 }
392 };
393
394 template <class _Tuple>
395 using _CheckTLC = typename conditional<
396 __tuple_like_with_size<_Tuple, 2>::value
397 && !is_same<typename decay<_Tuple>::type, pair>::value,
398 _CheckTupleLikeConstructor,
399 __check_tuple_constructor_fail
400 >::type;
401
402 template<bool _Dummy = true, _EnableB<
403 _CheckArgsDep<_Dummy>::template __enable_default<_T1, _T2>()
404 > = false>
405 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
406 pair() : first(), second() {}
407
408 template <bool _Dummy = true, _EnableB<
409 _CheckArgsDep<_Dummy>::template __enable_explicit<_T1 const&, _T2 const&>()
410 > = false>
411 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
412 explicit pair(_T1 const& __t1, _T2 const& __t2)
413 : first(__t1), second(__t2) {}
414
415 template<bool _Dummy = true, _EnableB<
416 _CheckArgsDep<_Dummy>::template __enable_implicit<_T1 const&, _T2 const&>()
417 > = false>
418 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
419 pair(_T1 const& __t1, _T2 const& __t2)
420 : first(__t1), second(__t2) {}
421
422 template<class _U1, class _U2, _EnableB<
423 _CheckArgs::template __enable_explicit<_U1, _U2>()
424 > = false>
425 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
426 explicit pair(_U1&& __u1, _U2&& __u2)
427 : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
428
429 template<class _U1, class _U2, _EnableB<
430 _CheckArgs::template __enable_implicit<_U1, _U2>()
431 > = false>
432 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
433 pair(_U1&& __u1, _U2&& __u2)
434 : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
435
436 template<class _U1, class _U2, _EnableB<
437 _CheckArgs::template __enable_explicit<_U1 const&, _U2 const&>()
438 > = false>
439 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
440 explicit pair(pair<_U1, _U2> const& __p)
441 : first(__p.first), second(__p.second) {}
442
443 template<class _U1, class _U2, _EnableB<
444 _CheckArgs::template __enable_implicit<_U1 const&, _U2 const&>()
445 > = false>
446 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
447 pair(pair<_U1, _U2> const& __p)
448 : first(__p.first), second(__p.second) {}
449
450 template<class _U1, class _U2, _EnableB<
451 _CheckArgs::template __enable_explicit<_U1, _U2>()
452 > = false>
453 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
454 explicit pair(pair<_U1, _U2>&&__p)
455 : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
456
457 template<class _U1, class _U2, _EnableB<
458 _CheckArgs::template __enable_implicit<_U1, _U2>()
459 > = false>
460 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
461 pair(pair<_U1, _U2>&& __p)
462 : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
463
464 template<class _Tuple, _EnableB<
465 _CheckTLC<_Tuple>::template __enable_explicit<_Tuple>()
466 > = false>
467 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
468 explicit pair(_Tuple&& __p)
469 : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
470 second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {}
471
472 template<class _Tuple, _EnableB<
473 _CheckTLC<_Tuple>::template __enable_implicit<_Tuple>()
474 > = false>
475 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
476 pair(_Tuple&& __p)
477 : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
478 second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {}
479
480 template <class... _Args1, class... _Args2>
481 _LIBCPP_INLINE_VISIBILITY
482 pair(piecewise_construct_t __pc,
483 tuple<_Args1...> __first_args, tuple<_Args2...> __second_args)
484 : pair(__pc, __first_args, __second_args,
485 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
486 typename __make_tuple_indices<sizeof...(_Args2) >::type()) {}
487
488 _LIBCPP_INLINE_VISIBILITY
489 pair& operator=(typename conditional<
490 is_copy_assignable<first_type>::value &&
491 is_copy_assignable<second_type>::value,
492 pair, __nat>::type const& __p)
Howard Hinnant61aa6012011-07-01 19:24:36 +0000493 _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value &&
494 is_nothrow_copy_assignable<second_type>::value)
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000495 {
496 first = __p.first;
497 second = __p.second;
498 return *this;
499 }
500
Eric Fiselier4be71c62016-07-25 02:36:42 +0000501 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000502 pair& operator=(typename conditional<
503 is_move_assignable<first_type>::value &&
504 is_move_assignable<second_type>::value,
505 pair, __nat>::type&& __p)
Eric Fiselier4be71c62016-07-25 02:36:42 +0000506 _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value &&
507 is_nothrow_move_assignable<second_type>::value)
508 {
509 first = _VSTD::forward<first_type>(__p.first);
510 second = _VSTD::forward<second_type>(__p.second);
511 return *this;
512 }
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000513
514 template <class _Tuple, _EnableB<
Eric Fiselier235d71f2016-08-29 01:43:41 +0000515 _CheckTLC<_Tuple>::template __enable_assign<_Tuple>()
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000516 > = false>
517 _LIBCPP_INLINE_VISIBILITY
518 pair& operator=(_Tuple&& __p) {
519 first = _VSTD::get<0>(_VSTD::forward<_Tuple>(__p));
520 second = _VSTD::get<1>(_VSTD::forward<_Tuple>(__p));
521 return *this;
522 }
Eric Fiselier4be71c62016-07-25 02:36:42 +0000523#endif
524
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000525 _LIBCPP_INLINE_VISIBILITY
526 void
Howard Hinnanta5e01212011-05-27 19:08:18 +0000527 swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value &&
528 __is_nothrow_swappable<second_type>::value)
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000529 {
Marshall Clow6b0e4192015-09-22 17:50:11 +0000530 using _VSTD::swap;
531 swap(first, __p.first);
532 swap(second, __p.second);
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000533 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000534private:
Howard Hinnant324bb032010-08-22 00:02:43 +0000535
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000536#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000537 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
Howard Hinnant5f5859c2011-01-13 20:05:05 +0000538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000539 pair(piecewise_construct_t,
540 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
541 __tuple_indices<_I1...>, __tuple_indices<_I2...>);
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000542#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000543};
544
545template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000546inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000547bool
548operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
549{
550 return __x.first == __y.first && __x.second == __y.second;
551}
552
553template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000554inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000555bool
556operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
557{
558 return !(__x == __y);
559}
560
561template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000562inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000563bool
564operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
565{
566 return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);
567}
568
569template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000570inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000571bool
572operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
573{
574 return __y < __x;
575}
576
577template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000578inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000579bool
580operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
581{
582 return !(__x < __y);
583}
584
585template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000586inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000587bool
588operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
589{
590 return !(__y < __x);
591}
592
593template <class _T1, class _T2>
594inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000595typename enable_if
596<
597 __is_swappable<_T1>::value &&
598 __is_swappable<_T2>::value,
599 void
600>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000601swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
Howard Hinnanta5e01212011-05-27 19:08:18 +0000602 _NOEXCEPT_((__is_nothrow_swappable<_T1>::value &&
603 __is_nothrow_swappable<_T2>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000604{
Howard Hinnante9b2c2d2011-05-27 15:04:19 +0000605 __x.swap(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000606}
607
Howard Hinnant73d21a42010-09-04 23:28:19 +0000608#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000609
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000610
611template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +0000612struct __make_pair_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000613{
614 typedef _Tp type;
615};
616
617template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:49 +0000618struct __make_pair_return_impl<reference_wrapper<_Tp>>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619{
620 typedef _Tp& type;
621};
622
623template <class _Tp>
624struct __make_pair_return
625{
Marshall Clowa71f9562014-01-03 22:55:49 +0000626 typedef typename __make_pair_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000627};
628
629template <class _T1, class _T2>
Marshall Clow206f6cd2013-07-16 17:45:44 +0000630inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000631pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
632make_pair(_T1&& __t1, _T2&& __t2)
633{
634 return pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
Howard Hinnant0949eed2011-06-30 21:18:19 +0000635 (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000636}
637
Howard Hinnant73d21a42010-09-04 23:28:19 +0000638#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000639
640template <class _T1, class _T2>
641inline _LIBCPP_INLINE_VISIBILITY
642pair<_T1,_T2>
643make_pair(_T1 __x, _T2 __y)
644{
645 return pair<_T1, _T2>(__x, __y);
646}
647
Howard Hinnant73d21a42010-09-04 23:28:19 +0000648#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000649
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000650template <class _T1, class _T2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000651 class _LIBCPP_TYPE_VIS_ONLY tuple_size<pair<_T1, _T2> >
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000652 : public integral_constant<size_t, 2> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000653
654template <class _T1, class _T2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000655class _LIBCPP_TYPE_VIS_ONLY tuple_element<0, pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656{
657public:
658 typedef _T1 type;
659};
660
661template <class _T1, class _T2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000662class _LIBCPP_TYPE_VIS_ONLY tuple_element<1, pair<_T1, _T2> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000663{
664public:
665 typedef _T2 type;
666};
667
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668template <size_t _Ip> struct __get_pair;
669
670template <>
671struct __get_pair<0>
672{
673 template <class _T1, class _T2>
674 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000675 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676 _T1&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000677 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000678
679 template <class _T1, class _T2>
680 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000681 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000682 const _T1&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000683 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000684
685#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
686
687 template <class _T1, class _T2>
688 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000689 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000690 _T1&&
Howard Hinnant0949eed2011-06-30 21:18:19 +0000691 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000692
Eric Fiselier199bee02015-12-18 00:36:55 +0000693 template <class _T1, class _T2>
694 static
695 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
696 const _T1&&
697 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);}
698
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000699#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000700};
701
702template <>
703struct __get_pair<1>
704{
705 template <class _T1, class _T2>
706 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000707 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708 _T2&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000709 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000710
711 template <class _T1, class _T2>
712 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000713 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714 const _T2&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000715 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000716
717#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
718
719 template <class _T1, class _T2>
720 static
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000721 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000722 _T2&&
Howard Hinnant0949eed2011-06-30 21:18:19 +0000723 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);}
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000724
Eric Fiselier199bee02015-12-18 00:36:55 +0000725 template <class _T1, class _T2>
726 static
727 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
728 const _T2&&
729 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);}
730
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000731#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000732};
733
734template <size_t _Ip, class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000735inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000736typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000737get(pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738{
739 return __get_pair<_Ip>::get(__p);
740}
741
742template <size_t _Ip, class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000743inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000744const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000745get(const pair<_T1, _T2>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000746{
747 return __get_pair<_Ip>::get(__p);
748}
749
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000750#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
751
752template <size_t _Ip, class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000753inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000754typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000755get(pair<_T1, _T2>&& __p) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000756{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000757 return __get_pair<_Ip>::get(_VSTD::move(__p));
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000758}
759
Eric Fiselier199bee02015-12-18 00:36:55 +0000760template <size_t _Ip, class _T1, class _T2>
761inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
762const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
763get(const pair<_T1, _T2>&& __p) _NOEXCEPT
764{
765 return __get_pair<_Ip>::get(_VSTD::move(__p));
766}
767
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000768#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
769
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000770#if _LIBCPP_STD_VER > 11
Marshall Clowe8029e52013-07-13 02:54:05 +0000771template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000772inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000773constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT
774{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000775 return __get_pair<0>::get(__p);
Marshall Clowe8029e52013-07-13 02:54:05 +0000776}
777
778template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000779inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000780constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT
781{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000782 return __get_pair<0>::get(__p);
Marshall Clowe8029e52013-07-13 02:54:05 +0000783}
784
785template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000786inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000787constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT
788{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000789 return __get_pair<0>::get(_VSTD::move(__p));
Marshall Clowe8029e52013-07-13 02:54:05 +0000790}
791
792template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000793inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier199bee02015-12-18 00:36:55 +0000794constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT
795{
796 return __get_pair<0>::get(_VSTD::move(__p));
797}
798
799template <class _T1, class _T2>
800inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000801constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT
802{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000803 return __get_pair<1>::get(__p);
Marshall Clowe8029e52013-07-13 02:54:05 +0000804}
805
806template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000807inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000808constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT
809{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000810 return __get_pair<1>::get(__p);
Marshall Clowe8029e52013-07-13 02:54:05 +0000811}
812
813template <class _T1, class _T2>
Howard Hinnant1e564242013-10-04 22:09:00 +0000814inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe8029e52013-07-13 02:54:05 +0000815constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT
816{
Marshall Clow206f6cd2013-07-16 17:45:44 +0000817 return __get_pair<1>::get(_VSTD::move(__p));
Marshall Clowe8029e52013-07-13 02:54:05 +0000818}
819
Eric Fiselier199bee02015-12-18 00:36:55 +0000820template <class _T1, class _T2>
821inline _LIBCPP_INLINE_VISIBILITY
822constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT
823{
824 return __get_pair<1>::get(_VSTD::move(__p));
825}
826
Marshall Clowe8029e52013-07-13 02:54:05 +0000827#endif
828
829#if _LIBCPP_STD_VER > 11
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000830
831template<class _Tp, _Tp... _Ip>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000832struct _LIBCPP_TYPE_VIS_ONLY integer_sequence
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000833{
834 typedef _Tp value_type;
835 static_assert( is_integral<_Tp>::value,
836 "std::integer_sequence can only be instantiated with an integral type" );
837 static
838 _LIBCPP_INLINE_VISIBILITY
839 constexpr
840 size_t
841 size() noexcept { return sizeof...(_Ip); }
842};
843
844template<size_t... _Ip>
845 using index_sequence = integer_sequence<size_t, _Ip...>;
846
Eric Fiselier76d24462015-12-09 22:03:06 +0000847#if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
848
849template <class _Tp, _Tp _Ep>
Eric Fiseliera3ccd962016-06-30 22:34:43 +0000850using __make_integer_sequence = __make_integer_seq<integer_sequence, _Tp, _Ep>;
Eric Fiselier76d24462015-12-09 22:03:06 +0000851
852#else
853
Marshall Clow42e55e92013-07-03 19:20:30 +0000854template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked =
Eric Fiseliera3ccd962016-06-30 22:34:43 +0000855 typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>;
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000856
857template <class _Tp, _Tp _Ep>
Eric Fiseliera3ccd962016-06-30 22:34:43 +0000858struct __make_integer_sequence_checked
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000859{
860 static_assert(is_integral<_Tp>::value,
861 "std::make_integer_sequence can only be instantiated with an integral type" );
Eric Fiselier76d24462015-12-09 22:03:06 +0000862 static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length");
Eric Fiselierd6a12b32015-12-16 00:35:45 +0000863 // Workaround GCC bug by preventing bad installations when 0 <= _Ep
864 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929
865 typedef __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type;
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000866};
867
Eric Fiseliera3ccd962016-06-30 22:34:43 +0000868template <class _Tp, _Tp _Ep>
869using __make_integer_sequence = typename __make_integer_sequence_checked<_Tp, _Ep>::type;
870
Eric Fiselier76d24462015-12-09 22:03:06 +0000871#endif
872
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000873template<class _Tp, _Tp _Np>
Eric Fiseliera3ccd962016-06-30 22:34:43 +0000874 using make_integer_sequence = __make_integer_sequence<_Tp, _Np>;
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000875
876template<size_t _Np>
877 using make_index_sequence = make_integer_sequence<size_t, _Np>;
878
879template<class... _Tp>
880 using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;
Marshall Clow5270a842016-06-19 19:29:52 +0000881
Marshall Clow7ec46bc2013-07-01 16:26:55 +0000882#endif // _LIBCPP_STD_VER > 11
883
Marshall Clowe2735d12013-07-08 20:54:40 +0000884#if _LIBCPP_STD_VER > 11
885template<class _T1, class _T2 = _T1>
Howard Hinnant1e564242013-10-04 22:09:00 +0000886inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe2735d12013-07-08 20:54:40 +0000887_T1 exchange(_T1& __obj, _T2 && __new_value)
888{
Howard Hinnant171771a2013-07-08 21:06:38 +0000889 _T1 __old_value = _VSTD::move(__obj);
890 __obj = _VSTD::forward<_T2>(__new_value);
891 return __old_value;
Marshall Clow5270a842016-06-19 19:29:52 +0000892}
Marshall Clowe2735d12013-07-08 20:54:40 +0000893#endif // _LIBCPP_STD_VER > 11
894
Eric Fiseliereef85d92016-07-23 22:19:19 +0000895#if _LIBCPP_STD_VER > 14
896
Eric Fiselier8d335262016-11-17 19:24:04 +0000897struct _LIBCPP_TYPE_VIS in_place_t {
898 explicit in_place_t() = default;
Eric Fiseliereef85d92016-07-23 22:19:19 +0000899};
Eric Fiseliera93ebec2016-11-17 20:08:43 +0000900#ifndef _LIBCPP_HAS_NO_INLINE_VARIABLES
901inline
902#endif
903constexpr in_place_t in_place{};
Eric Fiselier846edfb2016-10-16 02:51:50 +0000904
905template <class _Tp>
Eric Fiselier8d335262016-11-17 19:24:04 +0000906struct _LIBCPP_TYPE_VIS in_place_type_t {
907 explicit in_place_type_t() = default;
908};
909template <class _Tp>
Eric Fiseliera93ebec2016-11-17 20:08:43 +0000910#ifndef _LIBCPP_HAS_NO_INLINE_VARIABLES
911inline
912#endif
913constexpr in_place_type_t<_Tp> in_place_type{};
Eric Fiselier846edfb2016-10-16 02:51:50 +0000914
Eric Fiselier8d335262016-11-17 19:24:04 +0000915template <size_t _Idx>
916struct _LIBCPP_TYPE_VIS in_place_index_t {
917 explicit in_place_index_t() = default;
918};
919template <size_t _Idx>
Eric Fiseliera93ebec2016-11-17 20:08:43 +0000920#ifndef _LIBCPP_HAS_NO_INLINE_VARIABLES
921inline
922#endif
923constexpr in_place_index_t<_Idx> in_place_index{};
Eric Fiselier8d335262016-11-17 19:24:04 +0000924
925template <class _Tp> struct __is_inplace_type_imp : false_type {};
926template <class _Tp> struct __is_inplace_type_imp<in_place_type_t<_Tp>> : true_type {};
Eric Fiselier846edfb2016-10-16 02:51:50 +0000927
928template <class _Tp>
Eric Fiselier8d335262016-11-17 19:24:04 +0000929using __is_inplace_type = __is_inplace_type_imp<__uncvref_t<_Tp>>;
Eric Fiselier15d8a562016-07-24 07:42:13 +0000930
Eric Fiseliereef85d92016-07-23 22:19:19 +0000931#endif // _LIBCPP_STD_VER > 14
932
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000933_LIBCPP_END_NAMESPACE_STD
934
935#endif // _LIBCPP_UTILITY