utility revision 315915
1// -*- C++ -*-
2//===-------------------------- utility -----------------------------------===//
3//
4//                     The LLVM Compiler Infrastructure
5//
6// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
8//
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
32template<class T>
33void
34swap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value &&
35                          is_nothrow_move_assignable<T>::value);
36
37template <class T, size_t N>
38void
39swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)));
40
41template <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
43
44template <class T> typename remove_reference<T>::type&& move(T&&) noexcept;      // constexpr in C++14
45
46template <class T>
47    typename conditional
48    <
49        !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
50        const T&,
51        T&&
52    >::type
53    move_if_noexcept(T& x) noexcept; // constexpr in C++14
54
55template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
56
57template <class T1, class T2>
58struct pair
59{
60    typedef T1 first_type;
61    typedef T2 second_type;
62
63    T1 first;
64    T2 second;
65
66    pair(const pair&) = default;
67    pair(pair&&) = default;
68    constexpr pair();
69    pair(const T1& x, const T2& y);                          // constexpr in C++14
70    template <class U, class V> pair(U&& x, V&& y);          // constexpr in C++14
71    template <class U, class V> pair(const pair<U, V>& p);   // constexpr in C++14
72    template <class U, class V> pair(pair<U, V>&& p);        // constexpr in C++14
73    template <class... Args1, class... Args2>
74        pair(piecewise_construct_t, tuple<Args1...> first_args,
75             tuple<Args2...> second_args);
76
77    template <class U, class V> pair& operator=(const pair<U, V>& p);
78    pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value &&
79                                       is_nothrow_move_assignable<T2>::value);
80    template <class U, class V> pair& operator=(pair<U, V>&& p);
81
82    void swap(pair& p) noexcept(noexcept(swap(first, p.first)) &&
83                                noexcept(swap(second, p.second)));
84};
85
86template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
87template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
88template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
89template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
90template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
91template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
92
93template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&);   // constexpr in C++14
94template <class T1, class T2>
95void
96swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));
97
98struct piecewise_construct_t { };
99constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
100
101template <class T> class tuple_size;
102template <size_t I, class T> class tuple_element;
103
104template <class T1, class T2> struct tuple_size<pair<T1, T2> >;
105template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >;
106template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >;
107
108template<size_t I, class T1, class T2>
109    typename tuple_element<I, pair<T1, T2> >::type&
110    get(pair<T1, T2>&) noexcept; // constexpr in C++14
111
112template<size_t I, class T1, class T2>
113    const typename const tuple_element<I, pair<T1, T2> >::type&
114    get(const pair<T1, T2>&) noexcept; // constexpr in C++14
115
116template<size_t I, class T1, class T2>
117    typename tuple_element<I, pair<T1, T2> >::type&&
118    get(pair<T1, T2>&&) noexcept; // constexpr in C++14
119
120template<class T1, class T2>
121    constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
122
123template<size_t I, class T1, class T2>
124    constexpr T1 const& get(pair<T1, T2> const &) noexcept; // C++14
125
126template<size_t I, class T1, class T2>
127    constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14
128
129// C++14
130
131template<class T, T... I>
132struct integer_sequence
133{
134    typedef T value_type;
135
136    static constexpr size_t size() noexcept;
137};
138
139template<size_t... I>
140  using index_sequence = integer_sequence<size_t, I...>;
141
142template<class T, T N>
143  using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
144template<size_t N>
145  using make_index_sequence = make_integer_sequence<size_t, N>;
146
147template<class... T>
148  using index_sequence_for = make_index_sequence<sizeof...(T)>;
149
150template<class T, class U=T> 
151    T exchange(T& obj, U&& new_value);
152}  // std
153
154*/
155
156#include <__config>
157#include <__tuple>
158#include <type_traits>
159
160#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
161#pragma GCC system_header
162#endif
163
164_LIBCPP_BEGIN_NAMESPACE_STD
165
166namespace rel_ops
167{
168
169template<class _Tp>
170inline _LIBCPP_INLINE_VISIBILITY
171bool
172operator!=(const _Tp& __x, const _Tp& __y)
173{
174    return !(__x == __y);
175}
176
177template<class _Tp>
178inline _LIBCPP_INLINE_VISIBILITY
179bool
180operator> (const _Tp& __x, const _Tp& __y)
181{
182    return __y < __x;
183}
184
185template<class _Tp>
186inline _LIBCPP_INLINE_VISIBILITY
187bool
188operator<=(const _Tp& __x, const _Tp& __y)
189{
190    return !(__y < __x);
191}
192
193template<class _Tp>
194inline _LIBCPP_INLINE_VISIBILITY
195bool
196operator>=(const _Tp& __x, const _Tp& __y)
197{
198    return !(__x < __y);
199}
200
201}  // rel_ops
202
203// swap_ranges
204
205template <class _ForwardIterator1, class _ForwardIterator2>
206inline _LIBCPP_INLINE_VISIBILITY
207_ForwardIterator2
208swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
209{
210    for(; __first1 != __last1; ++__first1, (void) ++__first2)
211        swap(*__first1, *__first2);
212    return __first2;
213}
214
215template<class _Tp, size_t _Np>
216inline _LIBCPP_INLINE_VISIBILITY
217void
218swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
219{
220    _VSTD::swap_ranges(__a, __a + _Np, __b);
221}
222
223template <class _Tp>
224inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
225#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
226typename conditional
227<
228    !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value,
229    const _Tp&,
230    _Tp&&
231>::type
232#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
233const _Tp&
234#endif
235move_if_noexcept(_Tp& __x) _NOEXCEPT
236{
237    return _VSTD::move(__x);
238}
239
240struct _LIBCPP_TYPE_VIS_ONLY piecewise_construct_t { };
241#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_UTILITY)
242extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
243#else
244constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
245#endif
246
247#if !_LIBCPP_TRIVIAL_PAIR_COPY_CTOR
248struct __non_trivially_copyable_base {
249  _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
250  __non_trivially_copyable_base() _NOEXCEPT {}
251  _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
252  __non_trivially_copyable_base(__non_trivially_copyable_base const&) _NOEXCEPT {}
253};
254#endif
255
256template <class _T1, class _T2>
257struct _LIBCPP_TYPE_VIS_ONLY pair
258#if !_LIBCPP_TRIVIAL_PAIR_COPY_CTOR
259: private __non_trivially_copyable_base
260#endif
261{
262    typedef _T1 first_type;
263    typedef _T2 second_type;
264
265    _T1 first;
266    _T2 second;
267
268    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {}
269
270    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
271    pair(const _T1& __x, const _T2& __y)
272        : first(__x), second(__y) {}
273
274    template<class _U1, class _U2>
275        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
276        pair(const pair<_U1, _U2>& __p
277#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
278                 ,typename enable_if<is_convertible<const _U1&, _T1>::value &&
279                                    is_convertible<const _U2&, _T2>::value>::type* = 0
280#endif
281                                      )
282            : first(__p.first), second(__p.second) {}
283
284#if !defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS)
285    pair(pair const&) = default;
286    pair(pair&&) = default;
287#else
288  // Use the implicitly declared copy constructor in C++03
289#endif
290
291    _LIBCPP_INLINE_VISIBILITY
292    pair& operator=(const pair& __p)
293        _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value &&
294                   is_nothrow_copy_assignable<second_type>::value)
295    {
296        first = __p.first;
297        second = __p.second;
298        return *this;
299    }
300
301#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
302
303    template <class _U1, class _U2,
304              class = typename enable_if<is_convertible<_U1, first_type>::value &&
305                                         is_convertible<_U2, second_type>::value>::type>
306        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
307        pair(_U1&& __u1, _U2&& __u2)
308            : first(_VSTD::forward<_U1>(__u1)),
309              second(_VSTD::forward<_U2>(__u2))
310            {}
311
312    template<class _U1, class _U2>
313        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
314        pair(pair<_U1, _U2>&& __p,
315                 typename enable_if<is_convertible<_U1, _T1>::value &&
316                                    is_convertible<_U2, _T2>::value>::type* = 0)
317            : first(_VSTD::forward<_U1>(__p.first)),
318              second(_VSTD::forward<_U2>(__p.second)) {}
319
320    _LIBCPP_INLINE_VISIBILITY
321    pair&
322    operator=(pair&& __p) _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value &&
323                                     is_nothrow_move_assignable<second_type>::value)
324    {
325        first = _VSTD::forward<first_type>(__p.first);
326        second = _VSTD::forward<second_type>(__p.second);
327        return *this;
328    }
329
330#ifndef _LIBCPP_HAS_NO_VARIADICS
331
332    template<class _Tuple,
333             class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type>
334        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
335        pair(_Tuple&& __p)
336            : first(_VSTD::forward<typename tuple_element<0,
337                                  typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<0>(__p))),
338              second(_VSTD::forward<typename tuple_element<1,
339                                   typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<1>(__p)))
340            {}
341
342
343
344    template <class... _Args1, class... _Args2>
345        _LIBCPP_INLINE_VISIBILITY
346        pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
347                                    tuple<_Args2...> __second_args)
348            : pair(__pc, __first_args, __second_args,
349                   typename __make_tuple_indices<sizeof...(_Args1)>::type(),
350                   typename __make_tuple_indices<sizeof...(_Args2) >::type())
351            {}
352
353    template <class _Tuple,
354              class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type>
355        _LIBCPP_INLINE_VISIBILITY
356        pair&
357        operator=(_Tuple&& __p)
358        {
359            typedef typename __make_tuple_types<_Tuple>::type _TupleRef;
360            typedef typename tuple_element<0, _TupleRef>::type _U0;
361            typedef typename tuple_element<1, _TupleRef>::type _U1;
362            first  = _VSTD::forward<_U0>(_VSTD::get<0>(__p));
363            second = _VSTD::forward<_U1>(_VSTD::get<1>(__p));
364            return *this;
365        }
366
367#endif  // _LIBCPP_HAS_NO_VARIADICS
368
369#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
370    _LIBCPP_INLINE_VISIBILITY
371    void
372    swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value &&
373                               __is_nothrow_swappable<second_type>::value)
374    {
375        _VSTD::iter_swap(&first, &__p.first);
376        _VSTD::iter_swap(&second, &__p.second);
377    }
378private:
379
380#ifndef _LIBCPP_HAS_NO_VARIADICS
381    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
382        _LIBCPP_INLINE_VISIBILITY
383        pair(piecewise_construct_t,
384             tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
385             __tuple_indices<_I1...>, __tuple_indices<_I2...>);
386#endif  // _LIBCPP_HAS_NO_VARIADICS
387};
388
389template <class _T1, class _T2>
390inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
391bool
392operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
393{
394    return __x.first == __y.first && __x.second == __y.second;
395}
396
397template <class _T1, class _T2>
398inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
399bool
400operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
401{
402    return !(__x == __y);
403}
404
405template <class _T1, class _T2>
406inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
407bool
408operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
409{
410    return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);
411}
412
413template <class _T1, class _T2>
414inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
415bool
416operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
417{
418    return __y < __x;
419}
420
421template <class _T1, class _T2>
422inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
423bool
424operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
425{
426    return !(__x < __y);
427}
428
429template <class _T1, class _T2>
430inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
431bool
432operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
433{
434    return !(__y < __x);
435}
436
437template <class _T1, class _T2>
438inline _LIBCPP_INLINE_VISIBILITY
439typename enable_if
440<
441    __is_swappable<_T1>::value &&
442    __is_swappable<_T2>::value,
443    void
444>::type
445swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
446                     _NOEXCEPT_((__is_nothrow_swappable<_T1>::value &&
447                                 __is_nothrow_swappable<_T2>::value))
448{
449    __x.swap(__y);
450}
451
452#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
453
454template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY reference_wrapper;
455
456template <class _Tp>
457struct __make_pair_return_impl
458{
459    typedef _Tp type;
460};
461
462template <class _Tp>
463struct __make_pair_return_impl<reference_wrapper<_Tp>>
464{
465    typedef _Tp& type;
466};
467
468template <class _Tp>
469struct __make_pair_return
470{
471    typedef typename __make_pair_return_impl<typename decay<_Tp>::type>::type type;
472};
473
474template <class _T1, class _T2>
475inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
476pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
477make_pair(_T1&& __t1, _T2&& __t2)
478{
479    return pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
480               (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2));
481}
482
483#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
484
485template <class _T1, class _T2>
486inline _LIBCPP_INLINE_VISIBILITY
487pair<_T1,_T2>
488make_pair(_T1 __x, _T2 __y)
489{
490    return pair<_T1, _T2>(__x, __y);
491}
492
493#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
494
495template <class _T1, class _T2>
496  class _LIBCPP_TYPE_VIS_ONLY tuple_size<pair<_T1, _T2> >
497    : public integral_constant<size_t, 2> {};
498
499template <class _T1, class _T2>
500  class _LIBCPP_TYPE_VIS_ONLY tuple_size<const pair<_T1, _T2> >
501    : public integral_constant<size_t, 2> {};
502
503template <class _T1, class _T2>
504class _LIBCPP_TYPE_VIS_ONLY tuple_element<0, pair<_T1, _T2> >
505{
506public:
507    typedef _T1 type;
508};
509
510template <class _T1, class _T2>
511class _LIBCPP_TYPE_VIS_ONLY tuple_element<1, pair<_T1, _T2> >
512{
513public:
514    typedef _T2 type;
515};
516
517template <class _T1, class _T2>
518class _LIBCPP_TYPE_VIS_ONLY tuple_element<0, const pair<_T1, _T2> >
519{
520public:
521    typedef const _T1 type;
522};
523
524template <class _T1, class _T2>
525class _LIBCPP_TYPE_VIS_ONLY tuple_element<1, const pair<_T1, _T2> >
526{
527public:
528    typedef const _T2 type;
529};
530
531template <size_t _Ip> struct __get_pair;
532
533template <>
534struct __get_pair<0>
535{
536    template <class _T1, class _T2>
537    static
538    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
539    _T1&
540    get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
541
542    template <class _T1, class _T2>
543    static
544    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
545    const _T1&
546    get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
547
548#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
549
550    template <class _T1, class _T2>
551    static
552    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
553    _T1&&
554    get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);}
555
556#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
557};
558
559template <>
560struct __get_pair<1>
561{
562    template <class _T1, class _T2>
563    static
564    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
565    _T2&
566    get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
567
568    template <class _T1, class _T2>
569    static
570    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
571    const _T2&
572    get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
573
574#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
575
576    template <class _T1, class _T2>
577    static
578    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
579    _T2&&
580    get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);}
581
582#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
583};
584
585template <size_t _Ip, class _T1, class _T2>
586inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
587typename tuple_element<_Ip, pair<_T1, _T2> >::type&
588get(pair<_T1, _T2>& __p) _NOEXCEPT
589{
590    return __get_pair<_Ip>::get(__p);
591}
592
593template <size_t _Ip, class _T1, class _T2>
594inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
595const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
596get(const pair<_T1, _T2>& __p) _NOEXCEPT
597{
598    return __get_pair<_Ip>::get(__p);
599}
600
601#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
602
603template <size_t _Ip, class _T1, class _T2>
604inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
605typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
606get(pair<_T1, _T2>&& __p) _NOEXCEPT
607{
608    return __get_pair<_Ip>::get(_VSTD::move(__p));
609}
610
611#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
612
613#if _LIBCPP_STD_VER > 11
614template <class _T1, class _T2>
615inline _LIBCPP_INLINE_VISIBILITY
616constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT
617{
618    return __get_pair<0>::get(__p);
619}
620
621template <class _T1, class _T2>
622inline _LIBCPP_INLINE_VISIBILITY
623constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT
624{
625    return __get_pair<0>::get(__p);
626}
627
628template <class _T1, class _T2>
629inline _LIBCPP_INLINE_VISIBILITY
630constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT
631{
632    return __get_pair<0>::get(_VSTD::move(__p));
633}
634
635template <class _T1, class _T2>
636inline _LIBCPP_INLINE_VISIBILITY
637constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT
638{
639    return __get_pair<1>::get(__p);
640}
641
642template <class _T1, class _T2>
643inline _LIBCPP_INLINE_VISIBILITY
644constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT
645{
646    return __get_pair<1>::get(__p);
647}
648
649template <class _T1, class _T2>
650inline _LIBCPP_INLINE_VISIBILITY
651constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT
652{
653    return __get_pair<1>::get(_VSTD::move(__p));
654}
655
656#endif
657
658#if _LIBCPP_STD_VER > 11
659
660template<class _Tp, _Tp... _Ip>
661struct _LIBCPP_TYPE_VIS_ONLY integer_sequence
662{
663    typedef _Tp value_type;
664    static_assert( is_integral<_Tp>::value,
665                  "std::integer_sequence can only be instantiated with an integral type" );
666    static
667    _LIBCPP_INLINE_VISIBILITY
668    constexpr
669    size_t
670    size() noexcept { return sizeof...(_Ip); }
671};
672
673template<size_t... _Ip>
674    using index_sequence = integer_sequence<size_t, _Ip...>;
675
676namespace __detail {
677
678template<typename _Tp, size_t ..._Extra> struct __repeat;
679template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<integer_sequence<_Tp, _Np...>, _Extra...> {
680  typedef integer_sequence<_Tp,
681                           _Np...,
682                           sizeof...(_Np) + _Np...,
683                           2 * sizeof...(_Np) + _Np...,
684                           3 * sizeof...(_Np) + _Np...,
685                           4 * sizeof...(_Np) + _Np...,
686                           5 * sizeof...(_Np) + _Np...,
687                           6 * sizeof...(_Np) + _Np...,
688                           7 * sizeof...(_Np) + _Np...,
689                           _Extra...> type;
690};
691
692template<size_t _Np> struct __parity;
693template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {};
694
695template<> struct __make<0> { typedef integer_sequence<size_t> type; };
696template<> struct __make<1> { typedef integer_sequence<size_t, 0> type; };
697template<> struct __make<2> { typedef integer_sequence<size_t, 0, 1> type; };
698template<> struct __make<3> { typedef integer_sequence<size_t, 0, 1, 2> type; };
699template<> struct __make<4> { typedef integer_sequence<size_t, 0, 1, 2, 3> type; };
700template<> struct __make<5> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4> type; };
701template<> struct __make<6> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4, 5> type; };
702template<> struct __make<7> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4, 5, 6> type; };
703
704template<> struct __parity<0> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type> {}; };
705template<> struct __parity<1> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 1> {}; };
706template<> struct __parity<2> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 2, _Np - 1> {}; };
707template<> struct __parity<3> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 3, _Np - 2, _Np - 1> {}; };
708template<> struct __parity<4> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
709template<> 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> {}; };
710template<> 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> {}; };
711template<> 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> {}; };
712
713template<typename _Tp, typename _Up> struct __convert {
714  template<typename> struct __result;
715  template<_Tp ..._Np> struct __result<integer_sequence<_Tp, _Np...> > { typedef integer_sequence<_Up, _Np...> type; };
716};
717template<typename _Tp> struct __convert<_Tp, _Tp> { template<typename _Up> struct __result { typedef _Up type; }; };
718
719}
720
721template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked =
722  typename __detail::__convert<size_t, _Tp>::template __result<typename __detail::__make<_Np>::type>::type;
723
724template <class _Tp, _Tp _Ep>
725struct __make_integer_sequence
726{
727    static_assert(is_integral<_Tp>::value,
728                  "std::make_integer_sequence can only be instantiated with an integral type" );
729    static_assert(0 <= _Ep, "std::make_integer_sequence input shall not be negative");
730    typedef __make_integer_sequence_unchecked<_Tp, _Ep> type;
731};
732
733template<class _Tp, _Tp _Np>
734    using make_integer_sequence = typename __make_integer_sequence<_Tp, _Np>::type;
735
736template<size_t _Np>
737    using make_index_sequence = make_integer_sequence<size_t, _Np>;
738
739template<class... _Tp>
740    using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;
741  
742#endif  // _LIBCPP_STD_VER > 11
743
744#if _LIBCPP_STD_VER > 11
745template<class _T1, class _T2 = _T1>
746inline _LIBCPP_INLINE_VISIBILITY
747_T1 exchange(_T1& __obj, _T2 && __new_value)
748{
749    _T1 __old_value = _VSTD::move(__obj);
750    __obj = _VSTD::forward<_T2>(__new_value);
751    return __old_value;
752}    
753#endif  // _LIBCPP_STD_VER > 11
754
755_LIBCPP_END_NAMESPACE_STD
756
757#endif  // _LIBCPP_UTILITY
758