2 //===-------------------------- utility -----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_UTILITY
12 #define _LIBCPP_UTILITY
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&);
34 swap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value &&
35 is_nothrow_move_assignable<T>::value);
37 template <class T, size_t N>
39 swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)));
41 template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; // constexpr in C++14
42 template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++14
44 template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14
49 !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
53 move_if_noexcept(T& x) noexcept; // constexpr in C++14
55 template <class T> constexpr add_const<T>_t& as_const(T& t) noexcept; // C++17
56 template <class T> void as_const(const T&&) = delete; // C++17
58 template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
60 template <class T1, class T2>
63 typedef T1 first_type;
64 typedef T2 second_type;
69 pair(const pair&) = default;
70 pair(pair&&) = default;
72 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
76 template <class... Args1, class... Args2>
77 pair(piecewise_construct_t, tuple<Args1...> first_args,
78 tuple<Args2...> second_args);
80 template <class U, class V> pair& operator=(const pair<U, V>& p);
81 pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value &&
82 is_nothrow_move_assignable<T2>::value);
83 template <class U, class V> pair& operator=(pair<U, V>&& p);
85 void swap(pair& p) noexcept(noexcept(swap(first, p.first)) &&
86 noexcept(swap(second, p.second)));
89 template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
90 template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
91 template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
92 template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
93 template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
94 template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
96 template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14
97 template <class T1, class T2>
99 swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));
101 struct piecewise_construct_t { };
102 constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
104 template <class T> class tuple_size;
105 template <size_t I, class T> class tuple_element;
107 template <class T1, class T2> struct tuple_size<pair<T1, T2> >;
108 template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >;
109 template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >;
111 template<size_t I, class T1, class T2>
112 typename tuple_element<I, pair<T1, T2> >::type&
113 get(pair<T1, T2>&) noexcept; // constexpr in C++14
115 template<size_t I, class T1, class T2>
116 const typename tuple_element<I, pair<T1, T2> >::type&
117 get(const pair<T1, T2>&) noexcept; // constexpr in C++14
119 template<size_t I, class T1, class T2>
120 typename tuple_element<I, pair<T1, T2> >::type&&
121 get(pair<T1, T2>&&) noexcept; // constexpr in C++14
123 template<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
127 template<class T1, class T2>
128 constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
130 template<class T1, class T2>
131 constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14
133 template<class T1, class T2>
134 constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14
136 template<class T1, class T2>
137 constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14
139 template<class T1, class T2>
140 constexpr T1& get(pair<T2, T1>&) noexcept; // C++14
142 template<class T1, class T2>
143 constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14
145 template<class T1, class T2>
146 constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14
148 template<class T1, class T2>
149 constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14
153 template<class T, T... I>
154 struct integer_sequence
156 typedef T value_type;
158 static constexpr size_t size() noexcept;
161 template<size_t... I>
162 using index_sequence = integer_sequence<size_t, I...>;
164 template<class T, T N>
165 using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
167 using make_index_sequence = make_integer_sequence<size_t, N>;
170 using index_sequence_for = make_index_sequence<sizeof...(T)>;
172 template<class T, class U=T>
173 T exchange(T& obj, U&& new_value);
180 #include <type_traits>
182 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
183 #pragma GCC system_header
186 _LIBCPP_BEGIN_NAMESPACE_STD
192 inline _LIBCPP_INLINE_VISIBILITY
194 operator!=(const _Tp& __x, const _Tp& __y)
196 return !(__x == __y);
200 inline _LIBCPP_INLINE_VISIBILITY
202 operator> (const _Tp& __x, const _Tp& __y)
208 inline _LIBCPP_INLINE_VISIBILITY
210 operator<=(const _Tp& __x, const _Tp& __y)
216 inline _LIBCPP_INLINE_VISIBILITY
218 operator>=(const _Tp& __x, const _Tp& __y)
228 template<class _Tp, size_t _Np>
229 inline _LIBCPP_INLINE_VISIBILITY
230 void swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value);
232 template <class _ForwardIterator1, class _ForwardIterator2>
233 inline _LIBCPP_INLINE_VISIBILITY
235 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
237 for(; __first1 != __last1; ++__first1, (void) ++__first2)
238 swap(*__first1, *__first2);
242 template<class _Tp, size_t _Np>
243 inline _LIBCPP_INLINE_VISIBILITY
245 swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
247 _VSTD::swap_ranges(__a, __a + _Np, __b);
251 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
252 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
255 !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value,
259 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
262 move_if_noexcept(_Tp& __x) _NOEXCEPT
264 return _VSTD::move(__x);
267 #if _LIBCPP_STD_VER > 14
268 template <class _Tp> constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; }
269 template <class _Tp> void as_const(const _Tp&&) = delete;
272 struct _LIBCPP_TYPE_VIS_ONLY piecewise_construct_t { };
273 #if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_UTILITY)
274 extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
276 constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
279 template <class _T1, class _T2>
280 struct _LIBCPP_TYPE_VIS_ONLY pair
282 typedef _T1 first_type;
283 typedef _T2 second_type;
288 // pair(const pair&) = default;
289 // pair(pair&&) = default;
291 #ifndef _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS
292 template <bool _Dummy = true, class = typename enable_if<
293 __dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
294 __dependent_type<is_default_constructible<_T2>, _Dummy>::value
297 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {}
299 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
300 pair(const _T1& __x, const _T2& __y)
301 : first(__x), second(__y) {}
303 template<class _U1, class _U2>
304 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
305 pair(const pair<_U1, _U2>& __p
306 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
307 ,typename enable_if<is_convertible<const _U1&, _T1>::value &&
308 is_convertible<const _U2&, _T2>::value>::type* = 0
311 : first(__p.first), second(__p.second) {}
313 #if !defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && _LIBCPP_TRIVIAL_PAIR_COPY_CTOR
314 _LIBCPP_INLINE_VISIBILITY
315 pair(const pair& __p) = default;
316 #elif !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) || !_LIBCPP_TRIVIAL_PAIR_COPY_CTOR
317 _LIBCPP_INLINE_VISIBILITY
318 pair(const pair& __p)
319 _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
320 is_nothrow_copy_constructible<second_type>::value)
327 _LIBCPP_INLINE_VISIBILITY
328 pair& operator=(const pair& __p)
329 _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value &&
330 is_nothrow_copy_assignable<second_type>::value)
337 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
339 template <class _U1, class _U2,
340 class = typename enable_if<is_convertible<_U1, first_type>::value &&
341 is_convertible<_U2, second_type>::value>::type>
342 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
343 pair(_U1&& __u1, _U2&& __u2)
344 : first(_VSTD::forward<_U1>(__u1)),
345 second(_VSTD::forward<_U2>(__u2))
348 template<class _U1, class _U2>
349 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
350 pair(pair<_U1, _U2>&& __p,
351 typename enable_if<is_convertible<_U1, _T1>::value &&
352 is_convertible<_U2, _T2>::value>::type* = 0)
353 : first(_VSTD::forward<_U1>(__p.first)),
354 second(_VSTD::forward<_U2>(__p.second)) {}
356 #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
357 _LIBCPP_INLINE_VISIBILITY
358 pair(pair&& __p) = default;
360 _LIBCPP_INLINE_VISIBILITY
361 pair(pair&& __p) _NOEXCEPT_(is_nothrow_move_constructible<first_type>::value &&
362 is_nothrow_move_constructible<second_type>::value)
363 : first(_VSTD::forward<first_type>(__p.first)),
364 second(_VSTD::forward<second_type>(__p.second))
369 _LIBCPP_INLINE_VISIBILITY
371 operator=(pair&& __p) _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value &&
372 is_nothrow_move_assignable<second_type>::value)
374 first = _VSTD::forward<first_type>(__p.first);
375 second = _VSTD::forward<second_type>(__p.second);
379 #ifndef _LIBCPP_HAS_NO_VARIADICS
381 template<class _Tuple,
382 class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type>
383 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
385 : first(_VSTD::forward<typename tuple_element<0,
386 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<0>(__p))),
387 second(_VSTD::forward<typename tuple_element<1,
388 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<1>(__p)))
393 template <class... _Args1, class... _Args2>
394 _LIBCPP_INLINE_VISIBILITY
395 pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
396 tuple<_Args2...> __second_args)
397 : pair(__pc, __first_args, __second_args,
398 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
399 typename __make_tuple_indices<sizeof...(_Args2) >::type())
402 template <class _Tuple,
403 class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type>
404 _LIBCPP_INLINE_VISIBILITY
406 operator=(_Tuple&& __p)
408 typedef typename __make_tuple_types<_Tuple>::type _TupleRef;
409 typedef typename tuple_element<0, _TupleRef>::type _U0;
410 typedef typename tuple_element<1, _TupleRef>::type _U1;
411 first = _VSTD::forward<_U0>(_VSTD::get<0>(__p));
412 second = _VSTD::forward<_U1>(_VSTD::get<1>(__p));
416 #endif // _LIBCPP_HAS_NO_VARIADICS
418 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
419 _LIBCPP_INLINE_VISIBILITY
421 swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value &&
422 __is_nothrow_swappable<second_type>::value)
425 swap(first, __p.first);
426 swap(second, __p.second);
430 #ifndef _LIBCPP_HAS_NO_VARIADICS
431 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
432 _LIBCPP_INLINE_VISIBILITY
433 pair(piecewise_construct_t,
434 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
435 __tuple_indices<_I1...>, __tuple_indices<_I2...>);
436 #endif // _LIBCPP_HAS_NO_VARIADICS
439 template <class _T1, class _T2>
440 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
442 operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
444 return __x.first == __y.first && __x.second == __y.second;
447 template <class _T1, class _T2>
448 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
450 operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
452 return !(__x == __y);
455 template <class _T1, class _T2>
456 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
458 operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
460 return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);
463 template <class _T1, class _T2>
464 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
466 operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
471 template <class _T1, class _T2>
472 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
474 operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
479 template <class _T1, class _T2>
480 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
482 operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
487 template <class _T1, class _T2>
488 inline _LIBCPP_INLINE_VISIBILITY
491 __is_swappable<_T1>::value &&
492 __is_swappable<_T2>::value,
495 swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
496 _NOEXCEPT_((__is_nothrow_swappable<_T1>::value &&
497 __is_nothrow_swappable<_T2>::value))
502 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
504 template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY reference_wrapper;
507 struct __make_pair_return_impl
513 struct __make_pair_return_impl<reference_wrapper<_Tp>>
519 struct __make_pair_return
521 typedef typename __make_pair_return_impl<typename decay<_Tp>::type>::type type;
524 template <class _T1, class _T2>
525 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
526 pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
527 make_pair(_T1&& __t1, _T2&& __t2)
529 return pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
530 (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2));
533 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
535 template <class _T1, class _T2>
536 inline _LIBCPP_INLINE_VISIBILITY
538 make_pair(_T1 __x, _T2 __y)
540 return pair<_T1, _T2>(__x, __y);
543 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
545 template <class _T1, class _T2>
546 class _LIBCPP_TYPE_VIS_ONLY tuple_size<pair<_T1, _T2> >
547 : public integral_constant<size_t, 2> {};
549 template <class _T1, class _T2>
550 class _LIBCPP_TYPE_VIS_ONLY tuple_element<0, pair<_T1, _T2> >
556 template <class _T1, class _T2>
557 class _LIBCPP_TYPE_VIS_ONLY tuple_element<1, pair<_T1, _T2> >
563 template <size_t _Ip> struct __get_pair;
568 template <class _T1, class _T2>
570 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
572 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
574 template <class _T1, class _T2>
576 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
578 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
580 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
582 template <class _T1, class _T2>
584 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
586 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);}
588 template <class _T1, class _T2>
590 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
592 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);}
594 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
600 template <class _T1, class _T2>
602 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
604 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
606 template <class _T1, class _T2>
608 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
610 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
612 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
614 template <class _T1, class _T2>
616 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
618 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);}
620 template <class _T1, class _T2>
622 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
624 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);}
626 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
629 template <size_t _Ip, class _T1, class _T2>
630 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
631 typename tuple_element<_Ip, pair<_T1, _T2> >::type&
632 get(pair<_T1, _T2>& __p) _NOEXCEPT
634 return __get_pair<_Ip>::get(__p);
637 template <size_t _Ip, class _T1, class _T2>
638 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
639 const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
640 get(const pair<_T1, _T2>& __p) _NOEXCEPT
642 return __get_pair<_Ip>::get(__p);
645 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
647 template <size_t _Ip, class _T1, class _T2>
648 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
649 typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
650 get(pair<_T1, _T2>&& __p) _NOEXCEPT
652 return __get_pair<_Ip>::get(_VSTD::move(__p));
655 template <size_t _Ip, class _T1, class _T2>
656 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
657 const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
658 get(const pair<_T1, _T2>&& __p) _NOEXCEPT
660 return __get_pair<_Ip>::get(_VSTD::move(__p));
663 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
665 #if _LIBCPP_STD_VER > 11
666 template <class _T1, class _T2>
667 inline _LIBCPP_INLINE_VISIBILITY
668 constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT
670 return __get_pair<0>::get(__p);
673 template <class _T1, class _T2>
674 inline _LIBCPP_INLINE_VISIBILITY
675 constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT
677 return __get_pair<0>::get(__p);
680 template <class _T1, class _T2>
681 inline _LIBCPP_INLINE_VISIBILITY
682 constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT
684 return __get_pair<0>::get(_VSTD::move(__p));
687 template <class _T1, class _T2>
688 inline _LIBCPP_INLINE_VISIBILITY
689 constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT
691 return __get_pair<0>::get(_VSTD::move(__p));
694 template <class _T1, class _T2>
695 inline _LIBCPP_INLINE_VISIBILITY
696 constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT
698 return __get_pair<1>::get(__p);
701 template <class _T1, class _T2>
702 inline _LIBCPP_INLINE_VISIBILITY
703 constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT
705 return __get_pair<1>::get(__p);
708 template <class _T1, class _T2>
709 inline _LIBCPP_INLINE_VISIBILITY
710 constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT
712 return __get_pair<1>::get(_VSTD::move(__p));
715 template <class _T1, class _T2>
716 inline _LIBCPP_INLINE_VISIBILITY
717 constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT
719 return __get_pair<1>::get(_VSTD::move(__p));
724 #if _LIBCPP_STD_VER > 11
726 template<class _Tp, _Tp... _Ip>
727 struct _LIBCPP_TYPE_VIS_ONLY integer_sequence
729 typedef _Tp value_type;
730 static_assert( is_integral<_Tp>::value,
731 "std::integer_sequence can only be instantiated with an integral type" );
733 _LIBCPP_INLINE_VISIBILITY
736 size() noexcept { return sizeof...(_Ip); }
739 template<size_t... _Ip>
740 using index_sequence = integer_sequence<size_t, _Ip...>;
742 #if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
744 template <class _Tp, _Tp _Ep>
745 struct __make_integer_sequence
747 typedef __make_integer_seq<integer_sequence, _Tp, _Ep> type;
754 template<typename _Tp, size_t ..._Extra> struct __repeat;
755 template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<integer_sequence<_Tp, _Np...>, _Extra...> {
756 typedef integer_sequence<_Tp,
758 sizeof...(_Np) + _Np...,
759 2 * sizeof...(_Np) + _Np...,
760 3 * sizeof...(_Np) + _Np...,
761 4 * sizeof...(_Np) + _Np...,
762 5 * sizeof...(_Np) + _Np...,
763 6 * sizeof...(_Np) + _Np...,
764 7 * sizeof...(_Np) + _Np...,
768 template<size_t _Np> struct __parity;
769 template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {};
771 template<> struct __make<0> { typedef integer_sequence<size_t> type; };
772 template<> struct __make<1> { typedef integer_sequence<size_t, 0> type; };
773 template<> struct __make<2> { typedef integer_sequence<size_t, 0, 1> type; };
774 template<> struct __make<3> { typedef integer_sequence<size_t, 0, 1, 2> type; };
775 template<> struct __make<4> { typedef integer_sequence<size_t, 0, 1, 2, 3> type; };
776 template<> struct __make<5> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4> type; };
777 template<> struct __make<6> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4, 5> type; };
778 template<> struct __make<7> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4, 5, 6> type; };
780 template<> struct __parity<0> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type> {}; };
781 template<> struct __parity<1> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 1> {}; };
782 template<> struct __parity<2> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 2, _Np - 1> {}; };
783 template<> struct __parity<3> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 3, _Np - 2, _Np - 1> {}; };
784 template<> struct __parity<4> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
785 template<> struct __parity<5> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
786 template<> struct __parity<6> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
787 template<> struct __parity<7> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 7, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
789 template<typename _Tp, typename _Up> struct __convert {
790 template<typename> struct __result;
791 template<_Tp ..._Np> struct __result<integer_sequence<_Tp, _Np...> > { typedef integer_sequence<_Up, _Np...> type; };
793 template<typename _Tp> struct __convert<_Tp, _Tp> { template<typename _Up> struct __result { typedef _Up type; }; };
797 template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked =
798 typename __detail::__convert<size_t, _Tp>::template __result<typename __detail::__make<_Np>::type>::type;
800 template <class _Tp, _Tp _Ep>
801 struct __make_integer_sequence
803 static_assert(is_integral<_Tp>::value,
804 "std::make_integer_sequence can only be instantiated with an integral type" );
805 static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length");
806 // Workaround GCC bug by preventing bad installations when 0 <= _Ep
807 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929
808 typedef __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type;
813 template<class _Tp, _Tp _Np>
814 using make_integer_sequence = typename __make_integer_sequence<_Tp, _Np>::type;
817 using make_index_sequence = make_integer_sequence<size_t, _Np>;
819 template<class... _Tp>
820 using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;
822 #endif // _LIBCPP_STD_VER > 11
824 #if _LIBCPP_STD_VER > 11
825 template<class _T1, class _T2 = _T1>
826 inline _LIBCPP_INLINE_VISIBILITY
827 _T1 exchange(_T1& __obj, _T2 && __new_value)
829 _T1 __old_value = _VSTD::move(__obj);
830 __obj = _VSTD::forward<_T2>(__new_value);
833 #endif // _LIBCPP_STD_VER > 11
835 _LIBCPP_END_NAMESPACE_STD
837 #endif // _LIBCPP_UTILITY