xref: /freebsd/contrib/llvm-project/libcxx/include/tuple (revision 480093f4440d54b30b3025afeac24b48f2ba7a2e)
10b57cec5SDimitry Andric// -*- C++ -*-
20b57cec5SDimitry Andric//===--------------------------- tuple ------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_TUPLE
110b57cec5SDimitry Andric#define _LIBCPP_TUPLE
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric    tuple synopsis
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricnamespace std
170b57cec5SDimitry Andric{
180b57cec5SDimitry Andric
190b57cec5SDimitry Andrictemplate <class... T>
200b57cec5SDimitry Andricclass tuple {
210b57cec5SDimitry Andricpublic:
22e40139ffSDimitry Andric    explicit(see-below) constexpr tuple();
23e40139ffSDimitry Andric    explicit(see-below) tuple(const T&...);  // constexpr in C++14
240b57cec5SDimitry Andric    template <class... U>
25e40139ffSDimitry Andric        explicit(see-below) tuple(U&&...);  // constexpr in C++14
260b57cec5SDimitry Andric    tuple(const tuple&) = default;
270b57cec5SDimitry Andric    tuple(tuple&&) = default;
280b57cec5SDimitry Andric    template <class... U>
29e40139ffSDimitry Andric        explicit(see-below) tuple(const tuple<U...>&);  // constexpr in C++14
300b57cec5SDimitry Andric    template <class... U>
31e40139ffSDimitry Andric        explicit(see-below) tuple(tuple<U...>&&);  // constexpr in C++14
320b57cec5SDimitry Andric    template <class U1, class U2>
33e40139ffSDimitry Andric        explicit(see-below) tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
340b57cec5SDimitry Andric    template <class U1, class U2>
35e40139ffSDimitry Andric        explicit(see-below) tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2  // constexpr in C++14
360b57cec5SDimitry Andric
370b57cec5SDimitry Andric    // allocator-extended constructors
380b57cec5SDimitry Andric    template <class Alloc>
390b57cec5SDimitry Andric        tuple(allocator_arg_t, const Alloc& a);
400b57cec5SDimitry Andric    template <class Alloc>
41e40139ffSDimitry Andric        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const T&...);
420b57cec5SDimitry Andric    template <class Alloc, class... U>
43e40139ffSDimitry Andric        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, U&&...);
440b57cec5SDimitry Andric    template <class Alloc>
450b57cec5SDimitry Andric        tuple(allocator_arg_t, const Alloc& a, const tuple&);
460b57cec5SDimitry Andric    template <class Alloc>
470b57cec5SDimitry Andric        tuple(allocator_arg_t, const Alloc& a, tuple&&);
480b57cec5SDimitry Andric    template <class Alloc, class... U>
49e40139ffSDimitry Andric        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&);
500b57cec5SDimitry Andric    template <class Alloc, class... U>
51e40139ffSDimitry Andric        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&);
520b57cec5SDimitry Andric    template <class Alloc, class U1, class U2>
53e40139ffSDimitry Andric        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
540b57cec5SDimitry Andric    template <class Alloc, class U1, class U2>
55e40139ffSDimitry Andric        explicit(see-below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
560b57cec5SDimitry Andric
570b57cec5SDimitry Andric    tuple& operator=(const tuple&);
580b57cec5SDimitry Andric    tuple&
590b57cec5SDimitry Andric        operator=(tuple&&) noexcept(AND(is_nothrow_move_assignable<T>::value ...));
600b57cec5SDimitry Andric    template <class... U>
610b57cec5SDimitry Andric        tuple& operator=(const tuple<U...>&);
620b57cec5SDimitry Andric    template <class... U>
630b57cec5SDimitry Andric        tuple& operator=(tuple<U...>&&);
640b57cec5SDimitry Andric    template <class U1, class U2>
650b57cec5SDimitry Andric        tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2
660b57cec5SDimitry Andric    template <class U1, class U2>
670b57cec5SDimitry Andric        tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2
680b57cec5SDimitry Andric
690b57cec5SDimitry Andric    void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...));
700b57cec5SDimitry Andric};
710b57cec5SDimitry Andric
72e40139ffSDimitry Andrictemplate <class ...T>
73e40139ffSDimitry Andrictuple(T...) -> tuple<T...>;                                         // since C++17
74e40139ffSDimitry Andrictemplate <class T1, class T2>
75e40139ffSDimitry Andrictuple(pair<T1, T2>) -> tuple<T1, T2>;                               // since C++17
76e40139ffSDimitry Andrictemplate <class Alloc, class ...T>
77e40139ffSDimitry Andrictuple(allocator_arg_t, Alloc, T...) -> tuple<T...>;                 // since C++17
78e40139ffSDimitry Andrictemplate <class Alloc, class T1, class T2>
79e40139ffSDimitry Andrictuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>;       // since C++17
80e40139ffSDimitry Andrictemplate <class Alloc, class ...T>
81e40139ffSDimitry Andrictuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>;          // since C++17
82e40139ffSDimitry Andric
830b57cec5SDimitry Andricinline constexpr unspecified ignore;
840b57cec5SDimitry Andric
850b57cec5SDimitry Andrictemplate <class... T> tuple<V...>  make_tuple(T&&...); // constexpr in C++14
860b57cec5SDimitry Andrictemplate <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
870b57cec5SDimitry Andrictemplate <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
880b57cec5SDimitry Andrictemplate <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
890b57cec5SDimitry Andric
900b57cec5SDimitry Andric// [tuple.apply], calling a function with a tuple of arguments:
910b57cec5SDimitry Andrictemplate <class F, class Tuple>
920b57cec5SDimitry Andric  constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
930b57cec5SDimitry Andrictemplate <class T, class Tuple>
940b57cec5SDimitry Andric  constexpr T make_from_tuple(Tuple&& t); // C++17
950b57cec5SDimitry Andric
960b57cec5SDimitry Andric// 20.4.1.4, tuple helper classes:
970b57cec5SDimitry Andrictemplate <class T> struct tuple_size; // undefined
980b57cec5SDimitry Andrictemplate <class... T> struct tuple_size<tuple<T...>>;
990b57cec5SDimitry Andrictemplate <class T>
1000b57cec5SDimitry Andric inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
1010b57cec5SDimitry Andrictemplate <size_t I, class T> struct tuple_element; // undefined
1020b57cec5SDimitry Andrictemplate <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
1030b57cec5SDimitry Andrictemplate <size_t I, class T>
1040b57cec5SDimitry Andric  using tuple_element_t = typename tuple_element <I, T>::type; // C++14
1050b57cec5SDimitry Andric
1060b57cec5SDimitry Andric// 20.4.1.5, element access:
1070b57cec5SDimitry Andrictemplate <size_t I, class... T>
1080b57cec5SDimitry Andric    typename tuple_element<I, tuple<T...>>::type&
1090b57cec5SDimitry Andric    get(tuple<T...>&) noexcept; // constexpr in C++14
1100b57cec5SDimitry Andrictemplate <size_t I, class... T>
1110b57cec5SDimitry Andric    const typename tuple_element<I, tuple<T...>>::type&
1120b57cec5SDimitry Andric    get(const tuple<T...>&) noexcept; // constexpr in C++14
1130b57cec5SDimitry Andrictemplate <size_t I, class... T>
1140b57cec5SDimitry Andric    typename tuple_element<I, tuple<T...>>::type&&
1150b57cec5SDimitry Andric    get(tuple<T...>&&) noexcept; // constexpr in C++14
1160b57cec5SDimitry Andrictemplate <size_t I, class... T>
1170b57cec5SDimitry Andric    const typename tuple_element<I, tuple<T...>>::type&&
1180b57cec5SDimitry Andric    get(const tuple<T...>&&) noexcept; // constexpr in C++14
1190b57cec5SDimitry Andric
1200b57cec5SDimitry Andrictemplate <class T1, class... T>
1210b57cec5SDimitry Andric    constexpr T1& get(tuple<T...>&) noexcept;  // C++14
1220b57cec5SDimitry Andrictemplate <class T1, class... T>
1230b57cec5SDimitry Andric    constexpr const T1& get(const tuple<T...>&) noexcept;   // C++14
1240b57cec5SDimitry Andrictemplate <class T1, class... T>
1250b57cec5SDimitry Andric    constexpr T1&& get(tuple<T...>&&) noexcept;   // C++14
1260b57cec5SDimitry Andrictemplate <class T1, class... T>
1270b57cec5SDimitry Andric    constexpr const T1&& get(const tuple<T...>&&) noexcept;   // C++14
1280b57cec5SDimitry Andric
1290b57cec5SDimitry Andric// 20.4.1.6, relational operators:
1300b57cec5SDimitry Andrictemplate<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
1310b57cec5SDimitry Andrictemplate<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14
1320b57cec5SDimitry Andrictemplate<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
1330b57cec5SDimitry Andrictemplate<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14
1340b57cec5SDimitry Andrictemplate<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
1350b57cec5SDimitry Andrictemplate<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
1360b57cec5SDimitry Andric
1370b57cec5SDimitry Andrictemplate <class... Types, class Alloc>
1380b57cec5SDimitry Andric  struct uses_allocator<tuple<Types...>, Alloc>;
1390b57cec5SDimitry Andric
1400b57cec5SDimitry Andrictemplate <class... Types>
1410b57cec5SDimitry Andric  void
1420b57cec5SDimitry Andric  swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
1430b57cec5SDimitry Andric
1440b57cec5SDimitry Andric}  // std
1450b57cec5SDimitry Andric
1460b57cec5SDimitry Andric*/
1470b57cec5SDimitry Andric
1480b57cec5SDimitry Andric#include <__config>
1490b57cec5SDimitry Andric#include <__tuple>
1500b57cec5SDimitry Andric#include <cstddef>
1510b57cec5SDimitry Andric#include <type_traits>
1520b57cec5SDimitry Andric#include <__functional_base>
1530b57cec5SDimitry Andric#include <utility>
1540b57cec5SDimitry Andric#include <version>
1550b57cec5SDimitry Andric
1560b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1570b57cec5SDimitry Andric#pragma GCC system_header
1580b57cec5SDimitry Andric#endif
1590b57cec5SDimitry Andric
1600b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
1610b57cec5SDimitry Andric
1620b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1630b57cec5SDimitry Andric
1640b57cec5SDimitry Andric
1650b57cec5SDimitry Andric// __tuple_leaf
1660b57cec5SDimitry Andric
1670b57cec5SDimitry Andrictemplate <size_t _Ip, class _Hp,
1680b57cec5SDimitry Andric          bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
1690b57cec5SDimitry Andric         >
1700b57cec5SDimitry Andricclass __tuple_leaf;
1710b57cec5SDimitry Andric
1720b57cec5SDimitry Andrictemplate <size_t _Ip, class _Hp, bool _Ep>
1730b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
1740b57cec5SDimitry Andricvoid swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
1750b57cec5SDimitry Andric    _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
1760b57cec5SDimitry Andric{
1770b57cec5SDimitry Andric    swap(__x.get(), __y.get());
1780b57cec5SDimitry Andric}
1790b57cec5SDimitry Andric
1800b57cec5SDimitry Andrictemplate <size_t _Ip, class _Hp, bool>
1810b57cec5SDimitry Andricclass __tuple_leaf
1820b57cec5SDimitry Andric{
1830b57cec5SDimitry Andric    _Hp __value_;
1840b57cec5SDimitry Andric
1850b57cec5SDimitry Andric    template <class _Tp>
1860b57cec5SDimitry Andric    static constexpr bool __can_bind_reference() {
1870b57cec5SDimitry Andric#if __has_keyword(__reference_binds_to_temporary)
1880b57cec5SDimitry Andric      return !__reference_binds_to_temporary(_Hp, _Tp);
1890b57cec5SDimitry Andric#else
1900b57cec5SDimitry Andric      return true;
1910b57cec5SDimitry Andric#endif
1920b57cec5SDimitry Andric    }
1930b57cec5SDimitry Andric
1940b57cec5SDimitry Andric    __tuple_leaf& operator=(const __tuple_leaf&);
1950b57cec5SDimitry Andricpublic:
1960b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
1970b57cec5SDimitry Andric             _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
1980b57cec5SDimitry Andric       {static_assert(!is_reference<_Hp>::value,
1990b57cec5SDimitry Andric              "Attempted to default construct a reference element in a tuple");}
2000b57cec5SDimitry Andric
2010b57cec5SDimitry Andric    template <class _Alloc>
2020b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
2030b57cec5SDimitry Andric        __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
2040b57cec5SDimitry Andric            : __value_()
2050b57cec5SDimitry Andric        {static_assert(!is_reference<_Hp>::value,
2060b57cec5SDimitry Andric              "Attempted to default construct a reference element in a tuple");}
2070b57cec5SDimitry Andric
2080b57cec5SDimitry Andric    template <class _Alloc>
2090b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
2100b57cec5SDimitry Andric        __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
2110b57cec5SDimitry Andric            : __value_(allocator_arg_t(), __a)
2120b57cec5SDimitry Andric        {static_assert(!is_reference<_Hp>::value,
2130b57cec5SDimitry Andric              "Attempted to default construct a reference element in a tuple");}
2140b57cec5SDimitry Andric
2150b57cec5SDimitry Andric    template <class _Alloc>
2160b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
2170b57cec5SDimitry Andric        __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
2180b57cec5SDimitry Andric            : __value_(__a)
2190b57cec5SDimitry Andric        {static_assert(!is_reference<_Hp>::value,
2200b57cec5SDimitry Andric              "Attempted to default construct a reference element in a tuple");}
2210b57cec5SDimitry Andric
2220b57cec5SDimitry Andric    template <class _Tp,
2230b57cec5SDimitry Andric              class = _EnableIf<
2240b57cec5SDimitry Andric                  _And<
2250b57cec5SDimitry Andric                      _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
2260b57cec5SDimitry Andric                      is_constructible<_Hp, _Tp>
2270b57cec5SDimitry Andric                    >::value
2280b57cec5SDimitry Andric                >
2290b57cec5SDimitry Andric            >
2300b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
2310b57cec5SDimitry Andric        explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
2320b57cec5SDimitry Andric            : __value_(_VSTD::forward<_Tp>(__t))
2330b57cec5SDimitry Andric        {static_assert(__can_bind_reference<_Tp&&>(),
2340b57cec5SDimitry Andric       "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
2350b57cec5SDimitry Andric
2360b57cec5SDimitry Andric    template <class _Tp, class _Alloc>
2370b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
2380b57cec5SDimitry Andric        explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
2390b57cec5SDimitry Andric            : __value_(_VSTD::forward<_Tp>(__t))
2400b57cec5SDimitry Andric        {static_assert(__can_bind_reference<_Tp&&>(),
2410b57cec5SDimitry Andric       "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
2420b57cec5SDimitry Andric
2430b57cec5SDimitry Andric    template <class _Tp, class _Alloc>
2440b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
2450b57cec5SDimitry Andric        explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
2460b57cec5SDimitry Andric            : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
2470b57cec5SDimitry Andric        {static_assert(!is_reference<_Hp>::value,
2480b57cec5SDimitry Andric            "Attempted to uses-allocator construct a reference element in a tuple");}
2490b57cec5SDimitry Andric
2500b57cec5SDimitry Andric    template <class _Tp, class _Alloc>
2510b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
2520b57cec5SDimitry Andric        explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
2530b57cec5SDimitry Andric            : __value_(_VSTD::forward<_Tp>(__t), __a)
2540b57cec5SDimitry Andric        {static_assert(!is_reference<_Hp>::value,
2550b57cec5SDimitry Andric           "Attempted to uses-allocator construct a reference element in a tuple");}
2560b57cec5SDimitry Andric
2570b57cec5SDimitry Andric    __tuple_leaf(const __tuple_leaf& __t) = default;
2580b57cec5SDimitry Andric    __tuple_leaf(__tuple_leaf&& __t) = default;
2590b57cec5SDimitry Andric
2600b57cec5SDimitry Andric    template <class _Tp>
2610b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
2620b57cec5SDimitry Andric        __tuple_leaf&
2630b57cec5SDimitry Andric        operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
2640b57cec5SDimitry Andric        {
2650b57cec5SDimitry Andric            __value_ = _VSTD::forward<_Tp>(__t);
2660b57cec5SDimitry Andric            return *this;
2670b57cec5SDimitry Andric        }
2680b57cec5SDimitry Andric
2690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2700b57cec5SDimitry Andric    int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
2710b57cec5SDimitry Andric    {
2720b57cec5SDimitry Andric        _VSTD::swap(*this, __t);
2730b57cec5SDimitry Andric        return 0;
2740b57cec5SDimitry Andric    }
2750b57cec5SDimitry Andric
2760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11       _Hp& get()       _NOEXCEPT {return __value_;}
2770b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
2780b57cec5SDimitry Andric};
2790b57cec5SDimitry Andric
2800b57cec5SDimitry Andrictemplate <size_t _Ip, class _Hp>
2810b57cec5SDimitry Andricclass __tuple_leaf<_Ip, _Hp, true>
2820b57cec5SDimitry Andric    : private _Hp
2830b57cec5SDimitry Andric{
2840b57cec5SDimitry Andric
2850b57cec5SDimitry Andric    __tuple_leaf& operator=(const __tuple_leaf&);
2860b57cec5SDimitry Andricpublic:
2870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
2880b57cec5SDimitry Andric             _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
2890b57cec5SDimitry Andric
2900b57cec5SDimitry Andric    template <class _Alloc>
2910b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
2920b57cec5SDimitry Andric        __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
2930b57cec5SDimitry Andric
2940b57cec5SDimitry Andric    template <class _Alloc>
2950b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
2960b57cec5SDimitry Andric        __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
2970b57cec5SDimitry Andric            : _Hp(allocator_arg_t(), __a) {}
2980b57cec5SDimitry Andric
2990b57cec5SDimitry Andric    template <class _Alloc>
3000b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
3010b57cec5SDimitry Andric        __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
3020b57cec5SDimitry Andric            : _Hp(__a) {}
3030b57cec5SDimitry Andric
3040b57cec5SDimitry Andric    template <class _Tp,
3050b57cec5SDimitry Andric              class = _EnableIf<
3060b57cec5SDimitry Andric                  _And<
3070b57cec5SDimitry Andric                    _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
3080b57cec5SDimitry Andric                    is_constructible<_Hp, _Tp>
3090b57cec5SDimitry Andric                  >::value
3100b57cec5SDimitry Andric                >
3110b57cec5SDimitry Andric            >
3120b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
3130b57cec5SDimitry Andric        explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
3140b57cec5SDimitry Andric            : _Hp(_VSTD::forward<_Tp>(__t)) {}
3150b57cec5SDimitry Andric
3160b57cec5SDimitry Andric    template <class _Tp, class _Alloc>
3170b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
3180b57cec5SDimitry Andric        explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
3190b57cec5SDimitry Andric            : _Hp(_VSTD::forward<_Tp>(__t)) {}
3200b57cec5SDimitry Andric
3210b57cec5SDimitry Andric    template <class _Tp, class _Alloc>
3220b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
3230b57cec5SDimitry Andric        explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
3240b57cec5SDimitry Andric            : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
3250b57cec5SDimitry Andric
3260b57cec5SDimitry Andric    template <class _Tp, class _Alloc>
3270b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
3280b57cec5SDimitry Andric        explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
3290b57cec5SDimitry Andric            : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
3300b57cec5SDimitry Andric
3310b57cec5SDimitry Andric    __tuple_leaf(__tuple_leaf const &) = default;
3320b57cec5SDimitry Andric    __tuple_leaf(__tuple_leaf &&) = default;
3330b57cec5SDimitry Andric
3340b57cec5SDimitry Andric    template <class _Tp>
3350b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
3360b57cec5SDimitry Andric        __tuple_leaf&
3370b57cec5SDimitry Andric        operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
3380b57cec5SDimitry Andric        {
3390b57cec5SDimitry Andric            _Hp::operator=(_VSTD::forward<_Tp>(__t));
3400b57cec5SDimitry Andric            return *this;
3410b57cec5SDimitry Andric        }
3420b57cec5SDimitry Andric
3430b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3440b57cec5SDimitry Andric    int
3450b57cec5SDimitry Andric    swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
3460b57cec5SDimitry Andric    {
3470b57cec5SDimitry Andric        _VSTD::swap(*this, __t);
3480b57cec5SDimitry Andric        return 0;
3490b57cec5SDimitry Andric    }
3500b57cec5SDimitry Andric
3510b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11       _Hp& get()       _NOEXCEPT {return static_cast<_Hp&>(*this);}
3520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);}
3530b57cec5SDimitry Andric};
3540b57cec5SDimitry Andric
3550b57cec5SDimitry Andrictemplate <class ..._Tp>
3560b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
3570b57cec5SDimitry Andricvoid __swallow(_Tp&&...) _NOEXCEPT {}
3580b57cec5SDimitry Andric
3590b57cec5SDimitry Andrictemplate <class _Tp>
3600b57cec5SDimitry Andricstruct __all_default_constructible;
3610b57cec5SDimitry Andric
3620b57cec5SDimitry Andrictemplate <class ..._Tp>
3630b57cec5SDimitry Andricstruct __all_default_constructible<__tuple_types<_Tp...>>
3640b57cec5SDimitry Andric    : __all<is_default_constructible<_Tp>::value...>
3650b57cec5SDimitry Andric{ };
3660b57cec5SDimitry Andric
3670b57cec5SDimitry Andric// __tuple_impl
3680b57cec5SDimitry Andric
3690b57cec5SDimitry Andrictemplate<class _Indx, class ..._Tp> struct __tuple_impl;
3700b57cec5SDimitry Andric
3710b57cec5SDimitry Andrictemplate<size_t ..._Indx, class ..._Tp>
3720b57cec5SDimitry Andricstruct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
3730b57cec5SDimitry Andric    : public __tuple_leaf<_Indx, _Tp>...
3740b57cec5SDimitry Andric{
3750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3760b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR __tuple_impl()
3770b57cec5SDimitry Andric        _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
3780b57cec5SDimitry Andric
3790b57cec5SDimitry Andric    template <size_t ..._Uf, class ..._Tf,
3800b57cec5SDimitry Andric              size_t ..._Ul, class ..._Tl, class ..._Up>
3810b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
3820b57cec5SDimitry Andric        explicit
3830b57cec5SDimitry Andric        __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
3840b57cec5SDimitry Andric                     __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
3850b57cec5SDimitry Andric                     _Up&&... __u)
3860b57cec5SDimitry Andric                     _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
3870b57cec5SDimitry Andric                                 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
3880b57cec5SDimitry Andric            __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
3890b57cec5SDimitry Andric            __tuple_leaf<_Ul, _Tl>()...
3900b57cec5SDimitry Andric            {}
3910b57cec5SDimitry Andric
3920b57cec5SDimitry Andric    template <class _Alloc, size_t ..._Uf, class ..._Tf,
3930b57cec5SDimitry Andric              size_t ..._Ul, class ..._Tl, class ..._Up>
3940b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
3950b57cec5SDimitry Andric        explicit
3960b57cec5SDimitry Andric        __tuple_impl(allocator_arg_t, const _Alloc& __a,
3970b57cec5SDimitry Andric                     __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
3980b57cec5SDimitry Andric                     __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
3990b57cec5SDimitry Andric                     _Up&&... __u) :
4000b57cec5SDimitry Andric            __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
4010b57cec5SDimitry Andric            _VSTD::forward<_Up>(__u))...,
4020b57cec5SDimitry Andric            __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
4030b57cec5SDimitry Andric            {}
4040b57cec5SDimitry Andric
4050b57cec5SDimitry Andric    template <class _Tuple,
4060b57cec5SDimitry Andric              class = typename enable_if
4070b57cec5SDimitry Andric                      <
4080b57cec5SDimitry Andric                         __tuple_constructible<_Tuple, tuple<_Tp...> >::value
4090b57cec5SDimitry Andric                      >::type
4100b57cec5SDimitry Andric             >
4110b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
4120b57cec5SDimitry Andric        __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
4130b57cec5SDimitry Andric                                       typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
4140b57cec5SDimitry Andric            : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
4150b57cec5SDimitry Andric                                       typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
4160b57cec5SDimitry Andric            {}
4170b57cec5SDimitry Andric
4180b57cec5SDimitry Andric    template <class _Alloc, class _Tuple,
4190b57cec5SDimitry Andric              class = typename enable_if
4200b57cec5SDimitry Andric                      <
4210b57cec5SDimitry Andric                         __tuple_constructible<_Tuple, tuple<_Tp...> >::value
4220b57cec5SDimitry Andric                      >::type
4230b57cec5SDimitry Andric             >
4240b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
4250b57cec5SDimitry Andric        __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
4260b57cec5SDimitry Andric            : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
4270b57cec5SDimitry Andric                                       typename __make_tuple_types<_Tuple>::type>::type>(), __a,
4280b57cec5SDimitry Andric                                       _VSTD::forward<typename tuple_element<_Indx,
4290b57cec5SDimitry Andric                                       typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
4300b57cec5SDimitry Andric            {}
4310b57cec5SDimitry Andric
4320b57cec5SDimitry Andric    template <class _Tuple>
4330b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
4340b57cec5SDimitry Andric        typename enable_if
4350b57cec5SDimitry Andric        <
4360b57cec5SDimitry Andric            __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
4370b57cec5SDimitry Andric            __tuple_impl&
4380b57cec5SDimitry Andric        >::type
4390b57cec5SDimitry Andric        operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
4400b57cec5SDimitry Andric                                       typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
4410b57cec5SDimitry Andric        {
4420b57cec5SDimitry Andric            __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
4430b57cec5SDimitry Andric                                       typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
4440b57cec5SDimitry Andric            return *this;
4450b57cec5SDimitry Andric        }
4460b57cec5SDimitry Andric
4470b57cec5SDimitry Andric    __tuple_impl(const __tuple_impl&) = default;
4480b57cec5SDimitry Andric    __tuple_impl(__tuple_impl&&) = default;
4490b57cec5SDimitry Andric
4500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4510b57cec5SDimitry Andric    __tuple_impl&
4520b57cec5SDimitry Andric    operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
4530b57cec5SDimitry Andric    {
4540b57cec5SDimitry Andric        __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
4550b57cec5SDimitry Andric        return *this;
4560b57cec5SDimitry Andric    }
4570b57cec5SDimitry Andric
4580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4590b57cec5SDimitry Andric    __tuple_impl&
4600b57cec5SDimitry Andric    operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
4610b57cec5SDimitry Andric    {
4620b57cec5SDimitry Andric        __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
4630b57cec5SDimitry Andric        return *this;
4640b57cec5SDimitry Andric    }
4650b57cec5SDimitry Andric
4660b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4670b57cec5SDimitry Andric    void swap(__tuple_impl& __t)
4680b57cec5SDimitry Andric        _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
4690b57cec5SDimitry Andric    {
4700b57cec5SDimitry Andric        __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
4710b57cec5SDimitry Andric    }
4720b57cec5SDimitry Andric};
4730b57cec5SDimitry Andric
4740b57cec5SDimitry Andric
4750b57cec5SDimitry Andric
4760b57cec5SDimitry Andrictemplate <class ..._Tp>
4770b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS tuple
4780b57cec5SDimitry Andric{
4790b57cec5SDimitry Andric    typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
4800b57cec5SDimitry Andric
4810b57cec5SDimitry Andric    _BaseT __base_;
4820b57cec5SDimitry Andric
4830b57cec5SDimitry Andric#if defined(_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION)
4840b57cec5SDimitry Andric    static constexpr bool _EnableImplicitReducedArityExtension = true;
4850b57cec5SDimitry Andric#else
4860b57cec5SDimitry Andric    static constexpr bool _EnableImplicitReducedArityExtension = false;
4870b57cec5SDimitry Andric#endif
4880b57cec5SDimitry Andric
4890b57cec5SDimitry Andric    template <class ..._Args>
4900b57cec5SDimitry Andric    struct _PackExpandsToThisTuple : false_type {};
4910b57cec5SDimitry Andric
4920b57cec5SDimitry Andric    template <class _Arg>
4930b57cec5SDimitry Andric    struct _PackExpandsToThisTuple<_Arg>
4940b57cec5SDimitry Andric        : is_same<typename __uncvref<_Arg>::type, tuple> {};
4950b57cec5SDimitry Andric
4960b57cec5SDimitry Andric    template <bool _MaybeEnable, class _Dummy = void>
4970b57cec5SDimitry Andric    struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
4980b57cec5SDimitry Andric
4990b57cec5SDimitry Andric    template <class _Dummy>
5000b57cec5SDimitry Andric    struct _CheckArgsConstructor<true, _Dummy>
5010b57cec5SDimitry Andric    {
502e40139ffSDimitry Andric        template <int&...>
503e40139ffSDimitry Andric        static constexpr bool __enable_implicit_default() {
504e40139ffSDimitry Andric           return __all<__is_implicitly_default_constructible<_Tp>::value... >::value;
5050b57cec5SDimitry Andric        }
5060b57cec5SDimitry Andric
507e40139ffSDimitry Andric        template <int&...>
508e40139ffSDimitry Andric        static constexpr bool __enable_explicit_default() {
509e40139ffSDimitry Andric            return
510e40139ffSDimitry Andric                __all<is_default_constructible<_Tp>::value...>::value &&
511e40139ffSDimitry Andric                !__enable_implicit_default< >();
512e40139ffSDimitry Andric        }
513e40139ffSDimitry Andric
514e40139ffSDimitry Andric
5150b57cec5SDimitry Andric        template <class ..._Args>
5160b57cec5SDimitry Andric        static constexpr bool __enable_explicit() {
5170b57cec5SDimitry Andric            return
5180b57cec5SDimitry Andric                __tuple_constructible<
5190b57cec5SDimitry Andric                    tuple<_Args...>,
5200b57cec5SDimitry Andric                    typename __make_tuple_types<tuple,
5210b57cec5SDimitry Andric                             sizeof...(_Args) < sizeof...(_Tp) ?
5220b57cec5SDimitry Andric                                 sizeof...(_Args) :
5230b57cec5SDimitry Andric                                 sizeof...(_Tp)>::type
5240b57cec5SDimitry Andric                >::value &&
5250b57cec5SDimitry Andric                !__tuple_convertible<
5260b57cec5SDimitry Andric                    tuple<_Args...>,
5270b57cec5SDimitry Andric                    typename __make_tuple_types<tuple,
5280b57cec5SDimitry Andric                             sizeof...(_Args) < sizeof...(_Tp) ?
5290b57cec5SDimitry Andric                                 sizeof...(_Args) :
5300b57cec5SDimitry Andric                                 sizeof...(_Tp)>::type
5310b57cec5SDimitry Andric                >::value &&
5320b57cec5SDimitry Andric                __all_default_constructible<
5330b57cec5SDimitry Andric                    typename __make_tuple_types<tuple, sizeof...(_Tp),
5340b57cec5SDimitry Andric                             sizeof...(_Args) < sizeof...(_Tp) ?
5350b57cec5SDimitry Andric                                 sizeof...(_Args) :
5360b57cec5SDimitry Andric                                 sizeof...(_Tp)>::type
5370b57cec5SDimitry Andric                >::value;
5380b57cec5SDimitry Andric        }
5390b57cec5SDimitry Andric
5400b57cec5SDimitry Andric        template <class ..._Args>
5410b57cec5SDimitry Andric        static constexpr bool __enable_implicit() {
5420b57cec5SDimitry Andric            return
5430b57cec5SDimitry Andric               __tuple_constructible<
5440b57cec5SDimitry Andric                    tuple<_Args...>,
5450b57cec5SDimitry Andric                    typename __make_tuple_types<tuple,
5460b57cec5SDimitry Andric                             sizeof...(_Args) < sizeof...(_Tp) ?
5470b57cec5SDimitry Andric                                 sizeof...(_Args) :
5480b57cec5SDimitry Andric                                 sizeof...(_Tp)>::type
5490b57cec5SDimitry Andric                >::value &&
5500b57cec5SDimitry Andric                __tuple_convertible<
5510b57cec5SDimitry Andric                    tuple<_Args...>,
5520b57cec5SDimitry Andric                    typename __make_tuple_types<tuple,
5530b57cec5SDimitry Andric                             sizeof...(_Args) < sizeof...(_Tp) ?
5540b57cec5SDimitry Andric                                 sizeof...(_Args) :
5550b57cec5SDimitry Andric                                 sizeof...(_Tp)>::type
5560b57cec5SDimitry Andric                >::value &&
5570b57cec5SDimitry Andric                __all_default_constructible<
5580b57cec5SDimitry Andric                    typename __make_tuple_types<tuple, sizeof...(_Tp),
5590b57cec5SDimitry Andric                             sizeof...(_Args) < sizeof...(_Tp) ?
5600b57cec5SDimitry Andric                                 sizeof...(_Args) :
5610b57cec5SDimitry Andric                                 sizeof...(_Tp)>::type
5620b57cec5SDimitry Andric                >::value;
5630b57cec5SDimitry Andric        }
5640b57cec5SDimitry Andric    };
5650b57cec5SDimitry Andric
5660b57cec5SDimitry Andric    template <bool _MaybeEnable,
5670b57cec5SDimitry Andric              bool = sizeof...(_Tp) == 1,
5680b57cec5SDimitry Andric              class _Dummy = void>
5690b57cec5SDimitry Andric    struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
5700b57cec5SDimitry Andric
5710b57cec5SDimitry Andric    template <class _Dummy>
5720b57cec5SDimitry Andric    struct _CheckTupleLikeConstructor<true, false, _Dummy>
5730b57cec5SDimitry Andric    {
5740b57cec5SDimitry Andric        template <class _Tuple>
5750b57cec5SDimitry Andric        static constexpr bool __enable_implicit() {
5760b57cec5SDimitry Andric            return __tuple_constructible<_Tuple, tuple>::value
5770b57cec5SDimitry Andric                && __tuple_convertible<_Tuple, tuple>::value;
5780b57cec5SDimitry Andric        }
5790b57cec5SDimitry Andric
5800b57cec5SDimitry Andric        template <class _Tuple>
5810b57cec5SDimitry Andric        static constexpr bool __enable_explicit() {
5820b57cec5SDimitry Andric            return __tuple_constructible<_Tuple, tuple>::value
5830b57cec5SDimitry Andric               && !__tuple_convertible<_Tuple, tuple>::value;
5840b57cec5SDimitry Andric        }
5850b57cec5SDimitry Andric    };
5860b57cec5SDimitry Andric
5870b57cec5SDimitry Andric    template <class _Dummy>
5880b57cec5SDimitry Andric    struct _CheckTupleLikeConstructor<true, true, _Dummy>
5890b57cec5SDimitry Andric    {
5900b57cec5SDimitry Andric        // This trait is used to disable the tuple-like constructor when
5910b57cec5SDimitry Andric        // the UTypes... constructor should be selected instead.
5920b57cec5SDimitry Andric        // See LWG issue #2549.
5930b57cec5SDimitry Andric        template <class _Tuple>
5940b57cec5SDimitry Andric        using _PreferTupleLikeConstructor = _Or<
5950b57cec5SDimitry Andric            // Don't attempt the two checks below if the tuple we are given
5960b57cec5SDimitry Andric            // has the same type as this tuple.
5970b57cec5SDimitry Andric            _IsSame<__uncvref_t<_Tuple>, tuple>,
5980b57cec5SDimitry Andric            _Lazy<_And,
5990b57cec5SDimitry Andric                _Not<is_constructible<_Tp..., _Tuple>>,
6000b57cec5SDimitry Andric                _Not<is_convertible<_Tuple, _Tp...>>
6010b57cec5SDimitry Andric            >
6020b57cec5SDimitry Andric        >;
6030b57cec5SDimitry Andric
6040b57cec5SDimitry Andric        template <class _Tuple>
6050b57cec5SDimitry Andric        static constexpr bool __enable_implicit() {
6060b57cec5SDimitry Andric            return _And<
6070b57cec5SDimitry Andric                __tuple_constructible<_Tuple, tuple>,
6080b57cec5SDimitry Andric                __tuple_convertible<_Tuple, tuple>,
6090b57cec5SDimitry Andric                _PreferTupleLikeConstructor<_Tuple>
6100b57cec5SDimitry Andric            >::value;
6110b57cec5SDimitry Andric        }
6120b57cec5SDimitry Andric
6130b57cec5SDimitry Andric        template <class _Tuple>
6140b57cec5SDimitry Andric        static constexpr bool __enable_explicit() {
6150b57cec5SDimitry Andric            return _And<
6160b57cec5SDimitry Andric                __tuple_constructible<_Tuple, tuple>,
6170b57cec5SDimitry Andric                _PreferTupleLikeConstructor<_Tuple>,
6180b57cec5SDimitry Andric                _Not<__tuple_convertible<_Tuple, tuple>>
6190b57cec5SDimitry Andric            >::value;
6200b57cec5SDimitry Andric        }
6210b57cec5SDimitry Andric    };
6220b57cec5SDimitry Andric
6230b57cec5SDimitry Andric    template <class _Tuple, bool _DisableIfLValue>
6240b57cec5SDimitry Andric    using _EnableImplicitTupleLikeConstructor = _EnableIf<
6250b57cec5SDimitry Andric                         _CheckTupleLikeConstructor<
6260b57cec5SDimitry Andric                             __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
6270b57cec5SDimitry Andric                             && !_PackExpandsToThisTuple<_Tuple>::value
6280b57cec5SDimitry Andric                             && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
6290b57cec5SDimitry Andric                         >::template __enable_implicit<_Tuple>(),
6300b57cec5SDimitry Andric                         bool
6310b57cec5SDimitry Andric                      >;
6320b57cec5SDimitry Andric
6330b57cec5SDimitry Andric    template <class _Tuple, bool _DisableIfLValue>
6340b57cec5SDimitry Andric    using _EnableExplicitTupleLikeConstructor = _EnableIf<
6350b57cec5SDimitry Andric                         _CheckTupleLikeConstructor<
6360b57cec5SDimitry Andric                             __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
6370b57cec5SDimitry Andric                             && !_PackExpandsToThisTuple<_Tuple>::value
6380b57cec5SDimitry Andric                             && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
6390b57cec5SDimitry Andric                         >::template __enable_explicit<_Tuple>(),
6400b57cec5SDimitry Andric                         bool
6410b57cec5SDimitry Andric                      >;
6420b57cec5SDimitry Andric    template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
6430b57cec5SDimitry Andric        typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
6440b57cec5SDimitry Andric    template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
6450b57cec5SDimitry Andric        const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
6460b57cec5SDimitry Andric    template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
6470b57cec5SDimitry Andric        typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
6480b57cec5SDimitry Andric    template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
6490b57cec5SDimitry Andric        const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
6500b57cec5SDimitry Andricpublic:
6510b57cec5SDimitry Andric
652e40139ffSDimitry Andric    template <bool _Dummy = true, _EnableIf<
653e40139ffSDimitry Andric        _CheckArgsConstructor<_Dummy>::__enable_implicit_default()
654e40139ffSDimitry Andric    , void*> = nullptr>
655e40139ffSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
656e40139ffSDimitry Andric    tuple()
657e40139ffSDimitry Andric        _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
658e40139ffSDimitry Andric
659e40139ffSDimitry Andric    template <bool _Dummy = true, _EnableIf<
660e40139ffSDimitry Andric        _CheckArgsConstructor<_Dummy>::__enable_explicit_default()
661e40139ffSDimitry Andric    , void*> = nullptr>
662e40139ffSDimitry Andric    explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
663e40139ffSDimitry Andric    tuple()
6640b57cec5SDimitry Andric        _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
6650b57cec5SDimitry Andric
6660b57cec5SDimitry Andric    tuple(tuple const&) = default;
6670b57cec5SDimitry Andric    tuple(tuple&&) = default;
6680b57cec5SDimitry Andric
669e40139ffSDimitry Andric    template <class _AllocArgT, class _Alloc, _EnableIf<
670e40139ffSDimitry Andric             _CheckArgsConstructor<_IsSame<allocator_arg_t, _AllocArgT>::value >::__enable_implicit_default()
671e40139ffSDimitry Andric      , void*> = nullptr
6720b57cec5SDimitry Andric    >
6730b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6740b57cec5SDimitry Andric    tuple(_AllocArgT, _Alloc const& __a)
6750b57cec5SDimitry Andric      : __base_(allocator_arg_t(), __a,
6760b57cec5SDimitry Andric                    __tuple_indices<>(), __tuple_types<>(),
6770b57cec5SDimitry Andric                    typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
6780b57cec5SDimitry Andric                    __tuple_types<_Tp...>()) {}
6790b57cec5SDimitry Andric
680e40139ffSDimitry Andric    template <class _AllocArgT, class _Alloc, _EnableIf<
681e40139ffSDimitry Andric             _CheckArgsConstructor<_IsSame<allocator_arg_t, _AllocArgT>::value>::__enable_explicit_default()
682e40139ffSDimitry Andric      , void*> = nullptr
683e40139ffSDimitry Andric    >
684e40139ffSDimitry Andric    explicit _LIBCPP_INLINE_VISIBILITY
685e40139ffSDimitry Andric    tuple(_AllocArgT, _Alloc const& __a)
686e40139ffSDimitry Andric      : __base_(allocator_arg_t(), __a,
687e40139ffSDimitry Andric                    __tuple_indices<>(), __tuple_types<>(),
688e40139ffSDimitry Andric                    typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
689e40139ffSDimitry Andric                    __tuple_types<_Tp...>()) {}
690e40139ffSDimitry Andric
6910b57cec5SDimitry Andric    template <bool _Dummy = true,
6920b57cec5SDimitry Andric              typename enable_if
6930b57cec5SDimitry Andric                      <
6940b57cec5SDimitry Andric                         _CheckArgsConstructor<
6950b57cec5SDimitry Andric                            _Dummy
6960b57cec5SDimitry Andric                         >::template __enable_implicit<_Tp const&...>(),
6970b57cec5SDimitry Andric                         bool
6980b57cec5SDimitry Andric                      >::type = false
6990b57cec5SDimitry Andric        >
7000b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
7010b57cec5SDimitry Andric    tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
7020b57cec5SDimitry Andric        : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
7030b57cec5SDimitry Andric                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
7040b57cec5SDimitry Andric                typename __make_tuple_indices<0>::type(),
7050b57cec5SDimitry Andric                typename __make_tuple_types<tuple, 0>::type(),
7060b57cec5SDimitry Andric                __t...
7070b57cec5SDimitry Andric               ) {}
7080b57cec5SDimitry Andric
7090b57cec5SDimitry Andric    template <bool _Dummy = true,
7100b57cec5SDimitry Andric              typename enable_if
7110b57cec5SDimitry Andric                      <
7120b57cec5SDimitry Andric                         _CheckArgsConstructor<
7130b57cec5SDimitry Andric                            _Dummy
7140b57cec5SDimitry Andric                         >::template __enable_explicit<_Tp const&...>(),
7150b57cec5SDimitry Andric                         bool
7160b57cec5SDimitry Andric                      >::type = false
7170b57cec5SDimitry Andric        >
7180b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
7190b57cec5SDimitry Andric    explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
7200b57cec5SDimitry Andric        : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
7210b57cec5SDimitry Andric                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
7220b57cec5SDimitry Andric                typename __make_tuple_indices<0>::type(),
7230b57cec5SDimitry Andric                typename __make_tuple_types<tuple, 0>::type(),
7240b57cec5SDimitry Andric                __t...
7250b57cec5SDimitry Andric               ) {}
7260b57cec5SDimitry Andric
7270b57cec5SDimitry Andric    template <class _Alloc, bool _Dummy = true,
7280b57cec5SDimitry Andric              typename enable_if
7290b57cec5SDimitry Andric                      <
7300b57cec5SDimitry Andric                         _CheckArgsConstructor<
7310b57cec5SDimitry Andric                            _Dummy
7320b57cec5SDimitry Andric                         >::template __enable_implicit<_Tp const&...>(),
7330b57cec5SDimitry Andric                         bool
7340b57cec5SDimitry Andric                      >::type = false
7350b57cec5SDimitry Andric        >
7360b57cec5SDimitry Andric      _LIBCPP_INLINE_VISIBILITY
7370b57cec5SDimitry Andric      tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
7380b57cec5SDimitry Andric        : __base_(allocator_arg_t(), __a,
7390b57cec5SDimitry Andric                typename __make_tuple_indices<sizeof...(_Tp)>::type(),
7400b57cec5SDimitry Andric                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
7410b57cec5SDimitry Andric                typename __make_tuple_indices<0>::type(),
7420b57cec5SDimitry Andric                typename __make_tuple_types<tuple, 0>::type(),
7430b57cec5SDimitry Andric                __t...
7440b57cec5SDimitry Andric               ) {}
7450b57cec5SDimitry Andric
7460b57cec5SDimitry Andric    template <class _Alloc, bool _Dummy = true,
7470b57cec5SDimitry Andric              typename enable_if
7480b57cec5SDimitry Andric                      <
7490b57cec5SDimitry Andric                         _CheckArgsConstructor<
7500b57cec5SDimitry Andric                            _Dummy
7510b57cec5SDimitry Andric                         >::template __enable_explicit<_Tp const&...>(),
7520b57cec5SDimitry Andric                         bool
7530b57cec5SDimitry Andric                      >::type = false
7540b57cec5SDimitry Andric        >
7550b57cec5SDimitry Andric      _LIBCPP_INLINE_VISIBILITY
7560b57cec5SDimitry Andric      explicit
7570b57cec5SDimitry Andric      tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
7580b57cec5SDimitry Andric        : __base_(allocator_arg_t(), __a,
7590b57cec5SDimitry Andric                typename __make_tuple_indices<sizeof...(_Tp)>::type(),
7600b57cec5SDimitry Andric                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
7610b57cec5SDimitry Andric                typename __make_tuple_indices<0>::type(),
7620b57cec5SDimitry Andric                typename __make_tuple_types<tuple, 0>::type(),
7630b57cec5SDimitry Andric                __t...
7640b57cec5SDimitry Andric               ) {}
7650b57cec5SDimitry Andric
7660b57cec5SDimitry Andric    template <class ..._Up,
7670b57cec5SDimitry Andric              bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value,
7680b57cec5SDimitry Andric              typename enable_if
7690b57cec5SDimitry Andric                      <
7700b57cec5SDimitry Andric                         _CheckArgsConstructor<
7710b57cec5SDimitry Andric                             sizeof...(_Up) == sizeof...(_Tp)
7720b57cec5SDimitry Andric                             && !_PackIsTuple
7730b57cec5SDimitry Andric                         >::template __enable_implicit<_Up...>() ||
7740b57cec5SDimitry Andric                        _CheckArgsConstructor<
7750b57cec5SDimitry Andric                            _EnableImplicitReducedArityExtension
7760b57cec5SDimitry Andric                            && sizeof...(_Up) < sizeof...(_Tp)
7770b57cec5SDimitry Andric                            && !_PackIsTuple
7780b57cec5SDimitry Andric                         >::template __enable_implicit<_Up...>(),
7790b57cec5SDimitry Andric                         bool
7800b57cec5SDimitry Andric                      >::type = false
7810b57cec5SDimitry Andric             >
7820b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
7830b57cec5SDimitry Andric        tuple(_Up&&... __u)
7840b57cec5SDimitry Andric            _NOEXCEPT_((
7850b57cec5SDimitry Andric                is_nothrow_constructible<_BaseT,
7860b57cec5SDimitry Andric                    typename __make_tuple_indices<sizeof...(_Up)>::type,
7870b57cec5SDimitry Andric                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
7880b57cec5SDimitry Andric                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
7890b57cec5SDimitry Andric                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
7900b57cec5SDimitry Andric                    _Up...
7910b57cec5SDimitry Andric                >::value
7920b57cec5SDimitry Andric            ))
7930b57cec5SDimitry Andric            : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
7940b57cec5SDimitry Andric                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
7950b57cec5SDimitry Andric                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
7960b57cec5SDimitry Andric                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
7970b57cec5SDimitry Andric                    _VSTD::forward<_Up>(__u)...) {}
7980b57cec5SDimitry Andric
7990b57cec5SDimitry Andric    template <class ..._Up,
8000b57cec5SDimitry Andric              typename enable_if
8010b57cec5SDimitry Andric                      <
8020b57cec5SDimitry Andric                         _CheckArgsConstructor<
8030b57cec5SDimitry Andric                             sizeof...(_Up) <= sizeof...(_Tp)
8040b57cec5SDimitry Andric                             && !_PackExpandsToThisTuple<_Up...>::value
8050b57cec5SDimitry Andric                         >::template __enable_explicit<_Up...>() ||
8060b57cec5SDimitry Andric                         _CheckArgsConstructor<
8070b57cec5SDimitry Andric                            !_EnableImplicitReducedArityExtension
8080b57cec5SDimitry Andric                            && sizeof...(_Up) < sizeof...(_Tp)
8090b57cec5SDimitry Andric                            && !_PackExpandsToThisTuple<_Up...>::value
8100b57cec5SDimitry Andric                         >::template __enable_implicit<_Up...>(),
8110b57cec5SDimitry Andric                         bool
8120b57cec5SDimitry Andric                      >::type = false
8130b57cec5SDimitry Andric             >
8140b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
8150b57cec5SDimitry Andric        explicit
8160b57cec5SDimitry Andric        tuple(_Up&&... __u)
8170b57cec5SDimitry Andric            _NOEXCEPT_((
8180b57cec5SDimitry Andric                is_nothrow_constructible<_BaseT,
8190b57cec5SDimitry Andric                    typename __make_tuple_indices<sizeof...(_Up)>::type,
8200b57cec5SDimitry Andric                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
8210b57cec5SDimitry Andric                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
8220b57cec5SDimitry Andric                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
8230b57cec5SDimitry Andric                    _Up...
8240b57cec5SDimitry Andric                >::value
8250b57cec5SDimitry Andric            ))
8260b57cec5SDimitry Andric            : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
8270b57cec5SDimitry Andric                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
8280b57cec5SDimitry Andric                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
8290b57cec5SDimitry Andric                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
8300b57cec5SDimitry Andric                    _VSTD::forward<_Up>(__u)...) {}
8310b57cec5SDimitry Andric
8320b57cec5SDimitry Andric    template <class _Alloc, class ..._Up,
8330b57cec5SDimitry Andric              typename enable_if
8340b57cec5SDimitry Andric                      <
8350b57cec5SDimitry Andric                         _CheckArgsConstructor<
8360b57cec5SDimitry Andric                             sizeof...(_Up) == sizeof...(_Tp) &&
8370b57cec5SDimitry Andric                             !_PackExpandsToThisTuple<_Up...>::value
8380b57cec5SDimitry Andric                         >::template __enable_implicit<_Up...>(),
8390b57cec5SDimitry Andric                         bool
8400b57cec5SDimitry Andric                      >::type = false
8410b57cec5SDimitry Andric             >
8420b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
8430b57cec5SDimitry Andric        tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
8440b57cec5SDimitry Andric            : __base_(allocator_arg_t(), __a,
8450b57cec5SDimitry Andric                    typename __make_tuple_indices<sizeof...(_Up)>::type(),
8460b57cec5SDimitry Andric                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
8470b57cec5SDimitry Andric                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
8480b57cec5SDimitry Andric                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
8490b57cec5SDimitry Andric                    _VSTD::forward<_Up>(__u)...) {}
8500b57cec5SDimitry Andric
8510b57cec5SDimitry Andric    template <class _Alloc, class ..._Up,
8520b57cec5SDimitry Andric              typename enable_if
8530b57cec5SDimitry Andric                      <
8540b57cec5SDimitry Andric                         _CheckArgsConstructor<
8550b57cec5SDimitry Andric                             sizeof...(_Up) == sizeof...(_Tp) &&
8560b57cec5SDimitry Andric                             !_PackExpandsToThisTuple<_Up...>::value
8570b57cec5SDimitry Andric                         >::template __enable_explicit<_Up...>(),
8580b57cec5SDimitry Andric                         bool
8590b57cec5SDimitry Andric                      >::type = false
8600b57cec5SDimitry Andric             >
8610b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
8620b57cec5SDimitry Andric        explicit
8630b57cec5SDimitry Andric        tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
8640b57cec5SDimitry Andric            : __base_(allocator_arg_t(), __a,
8650b57cec5SDimitry Andric                    typename __make_tuple_indices<sizeof...(_Up)>::type(),
8660b57cec5SDimitry Andric                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
8670b57cec5SDimitry Andric                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
8680b57cec5SDimitry Andric                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
8690b57cec5SDimitry Andric                    _VSTD::forward<_Up>(__u)...) {}
8700b57cec5SDimitry Andric
8710b57cec5SDimitry Andric    template <class _Tuple, _EnableImplicitTupleLikeConstructor<_Tuple, true> = false>
8720b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
8730b57cec5SDimitry Andric        tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
8740b57cec5SDimitry Andric            : __base_(_VSTD::forward<_Tuple>(__t)) {}
8750b57cec5SDimitry Andric
8760b57cec5SDimitry Andric    template <class _Tuple, _EnableImplicitTupleLikeConstructor<const _Tuple&, false> = false>
8770b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
8780b57cec5SDimitry Andric        tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
8790b57cec5SDimitry Andric            : __base_(__t) {}
8800b57cec5SDimitry Andric    template <class _Tuple, _EnableExplicitTupleLikeConstructor<_Tuple, true> = false>
8810b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
8820b57cec5SDimitry Andric        explicit
8830b57cec5SDimitry Andric        tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
8840b57cec5SDimitry Andric            : __base_(_VSTD::forward<_Tuple>(__t)) {}
8850b57cec5SDimitry Andric
8860b57cec5SDimitry Andric    template <class _Tuple, _EnableExplicitTupleLikeConstructor<const _Tuple&, false> = false>
8870b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
8880b57cec5SDimitry Andric        explicit
8890b57cec5SDimitry Andric        tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
8900b57cec5SDimitry Andric            : __base_(__t) {}
8910b57cec5SDimitry Andric
8920b57cec5SDimitry Andric    template <class _Alloc, class _Tuple,
8930b57cec5SDimitry Andric              typename enable_if
8940b57cec5SDimitry Andric                      <
8950b57cec5SDimitry Andric                         _CheckTupleLikeConstructor<
8960b57cec5SDimitry Andric                             __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
8970b57cec5SDimitry Andric                         >::template __enable_implicit<_Tuple>(),
8980b57cec5SDimitry Andric                         bool
8990b57cec5SDimitry Andric                      >::type = false
9000b57cec5SDimitry Andric             >
9010b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
9020b57cec5SDimitry Andric        tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
9030b57cec5SDimitry Andric            : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
9040b57cec5SDimitry Andric
9050b57cec5SDimitry Andric    template <class _Alloc, class _Tuple,
9060b57cec5SDimitry Andric              typename enable_if
9070b57cec5SDimitry Andric                      <
9080b57cec5SDimitry Andric                         _CheckTupleLikeConstructor<
9090b57cec5SDimitry Andric                             __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
9100b57cec5SDimitry Andric                         >::template __enable_explicit<_Tuple>(),
9110b57cec5SDimitry Andric                         bool
9120b57cec5SDimitry Andric                      >::type = false
9130b57cec5SDimitry Andric             >
9140b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
9150b57cec5SDimitry Andric        explicit
9160b57cec5SDimitry Andric        tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
9170b57cec5SDimitry Andric            : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
9180b57cec5SDimitry Andric
9190b57cec5SDimitry Andric    using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>;
9200b57cec5SDimitry Andric    using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>;
9210b57cec5SDimitry Andric
9220b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9230b57cec5SDimitry Andric    tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t)
9240b57cec5SDimitry Andric        _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
9250b57cec5SDimitry Andric    {
9260b57cec5SDimitry Andric        __base_.operator=(__t.__base_);
9270b57cec5SDimitry Andric        return *this;
9280b57cec5SDimitry Andric    }
9290b57cec5SDimitry Andric
9300b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9310b57cec5SDimitry Andric    tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t)
9320b57cec5SDimitry Andric        _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
9330b57cec5SDimitry Andric    {
9340b57cec5SDimitry Andric        __base_.operator=(static_cast<_BaseT&&>(__t.__base_));
9350b57cec5SDimitry Andric        return *this;
9360b57cec5SDimitry Andric    }
9370b57cec5SDimitry Andric
9380b57cec5SDimitry Andric    template <class _Tuple,
9390b57cec5SDimitry Andric              class = typename enable_if
9400b57cec5SDimitry Andric                      <
9410b57cec5SDimitry Andric                         __tuple_assignable<_Tuple, tuple>::value
9420b57cec5SDimitry Andric                      >::type
9430b57cec5SDimitry Andric             >
9440b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
9450b57cec5SDimitry Andric        tuple&
9460b57cec5SDimitry Andric        operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<_BaseT&, _Tuple>::value))
9470b57cec5SDimitry Andric        {
9480b57cec5SDimitry Andric            __base_.operator=(_VSTD::forward<_Tuple>(__t));
9490b57cec5SDimitry Andric            return *this;
9500b57cec5SDimitry Andric        }
9510b57cec5SDimitry Andric
9520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9530b57cec5SDimitry Andric    void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
9540b57cec5SDimitry Andric        {__base_.swap(__t.__base_);}
9550b57cec5SDimitry Andric};
9560b57cec5SDimitry Andric
9570b57cec5SDimitry Andrictemplate <>
9580b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS tuple<>
9590b57cec5SDimitry Andric{
9600b57cec5SDimitry Andricpublic:
9610b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9620b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR tuple() _NOEXCEPT = default;
9630b57cec5SDimitry Andric    template <class _Alloc>
9640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9650b57cec5SDimitry Andric        tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
9660b57cec5SDimitry Andric    template <class _Alloc>
9670b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9680b57cec5SDimitry Andric        tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
9690b57cec5SDimitry Andric    template <class _Up>
9700b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9710b57cec5SDimitry Andric        tuple(array<_Up, 0>) _NOEXCEPT {}
9720b57cec5SDimitry Andric    template <class _Alloc, class _Up>
9730b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9740b57cec5SDimitry Andric        tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
9750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9760b57cec5SDimitry Andric    void swap(tuple&) _NOEXCEPT {}
9770b57cec5SDimitry Andric};
9780b57cec5SDimitry Andric
9790b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
980e40139ffSDimitry Andrictemplate <class ..._Tp>
981e40139ffSDimitry Andrictuple(_Tp...) -> tuple<_Tp...>;
982e40139ffSDimitry Andrictemplate <class _Tp1, class _Tp2>
983e40139ffSDimitry Andrictuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
984e40139ffSDimitry Andrictemplate <class _Alloc, class ..._Tp>
985e40139ffSDimitry Andrictuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
986e40139ffSDimitry Andrictemplate <class _Alloc, class _Tp1, class _Tp2>
987e40139ffSDimitry Andrictuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
988e40139ffSDimitry Andrictemplate <class _Alloc, class ..._Tp>
989e40139ffSDimitry Andrictuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
9900b57cec5SDimitry Andric#endif
9910b57cec5SDimitry Andric
9920b57cec5SDimitry Andrictemplate <class ..._Tp>
9930b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9940b57cec5SDimitry Andrictypename enable_if
9950b57cec5SDimitry Andric<
9960b57cec5SDimitry Andric    __all<__is_swappable<_Tp>::value...>::value,
9970b57cec5SDimitry Andric    void
9980b57cec5SDimitry Andric>::type
9990b57cec5SDimitry Andricswap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
10000b57cec5SDimitry Andric                 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
10010b57cec5SDimitry Andric    {__t.swap(__u);}
10020b57cec5SDimitry Andric
10030b57cec5SDimitry Andric// get
10040b57cec5SDimitry Andric
10050b57cec5SDimitry Andrictemplate <size_t _Ip, class ..._Tp>
10060b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
10070b57cec5SDimitry Andrictypename tuple_element<_Ip, tuple<_Tp...> >::type&
10080b57cec5SDimitry Andricget(tuple<_Tp...>& __t) _NOEXCEPT
10090b57cec5SDimitry Andric{
10100b57cec5SDimitry Andric    typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
10110b57cec5SDimitry Andric    return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
10120b57cec5SDimitry Andric}
10130b57cec5SDimitry Andric
10140b57cec5SDimitry Andrictemplate <size_t _Ip, class ..._Tp>
10150b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
10160b57cec5SDimitry Andricconst typename tuple_element<_Ip, tuple<_Tp...> >::type&
10170b57cec5SDimitry Andricget(const tuple<_Tp...>& __t) _NOEXCEPT
10180b57cec5SDimitry Andric{
10190b57cec5SDimitry Andric    typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
10200b57cec5SDimitry Andric    return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
10210b57cec5SDimitry Andric}
10220b57cec5SDimitry Andric
10230b57cec5SDimitry Andrictemplate <size_t _Ip, class ..._Tp>
10240b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
10250b57cec5SDimitry Andrictypename tuple_element<_Ip, tuple<_Tp...> >::type&&
10260b57cec5SDimitry Andricget(tuple<_Tp...>&& __t) _NOEXCEPT
10270b57cec5SDimitry Andric{
10280b57cec5SDimitry Andric    typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
10290b57cec5SDimitry Andric    return static_cast<type&&>(
10300b57cec5SDimitry Andric             static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
10310b57cec5SDimitry Andric}
10320b57cec5SDimitry Andric
10330b57cec5SDimitry Andrictemplate <size_t _Ip, class ..._Tp>
10340b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
10350b57cec5SDimitry Andricconst typename tuple_element<_Ip, tuple<_Tp...> >::type&&
10360b57cec5SDimitry Andricget(const tuple<_Tp...>&& __t) _NOEXCEPT
10370b57cec5SDimitry Andric{
10380b57cec5SDimitry Andric    typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
10390b57cec5SDimitry Andric    return static_cast<const type&&>(
10400b57cec5SDimitry Andric             static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
10410b57cec5SDimitry Andric}
10420b57cec5SDimitry Andric
10430b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
10440b57cec5SDimitry Andric
10450b57cec5SDimitry Andricnamespace __find_detail {
10460b57cec5SDimitry Andric
10470b57cec5SDimitry Andricstatic constexpr size_t __not_found = -1;
10480b57cec5SDimitry Andricstatic constexpr size_t __ambiguous = __not_found - 1;
10490b57cec5SDimitry Andric
10500b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
10510b57cec5SDimitry Andricconstexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
10520b57cec5SDimitry Andric    return !__matches ? __res :
10530b57cec5SDimitry Andric        (__res == __not_found ? __curr_i : __ambiguous);
10540b57cec5SDimitry Andric}
10550b57cec5SDimitry Andric
10560b57cec5SDimitry Andrictemplate <size_t _Nx>
10570b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
10580b57cec5SDimitry Andricconstexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
10590b57cec5SDimitry Andric  return __i == _Nx ? __not_found :
10600b57cec5SDimitry Andric      __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
10610b57cec5SDimitry Andric}
10620b57cec5SDimitry Andric
10630b57cec5SDimitry Andrictemplate <class _T1, class ..._Args>
10640b57cec5SDimitry Andricstruct __find_exactly_one_checked {
10650b57cec5SDimitry Andric    static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
10660b57cec5SDimitry Andric    static constexpr size_t value = __find_detail::__find_idx(0, __matches);
10670b57cec5SDimitry Andric    static_assert(value != __not_found, "type not found in type list" );
10680b57cec5SDimitry Andric    static_assert(value != __ambiguous, "type occurs more than once in type list");
10690b57cec5SDimitry Andric};
10700b57cec5SDimitry Andric
10710b57cec5SDimitry Andrictemplate <class _T1>
10720b57cec5SDimitry Andricstruct __find_exactly_one_checked<_T1> {
10730b57cec5SDimitry Andric    static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
10740b57cec5SDimitry Andric};
10750b57cec5SDimitry Andric
10760b57cec5SDimitry Andric} // namespace __find_detail;
10770b57cec5SDimitry Andric
10780b57cec5SDimitry Andrictemplate <typename _T1, typename... _Args>
10790b57cec5SDimitry Andricstruct __find_exactly_one_t
10800b57cec5SDimitry Andric    : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
10810b57cec5SDimitry Andric};
10820b57cec5SDimitry Andric
10830b57cec5SDimitry Andrictemplate <class _T1, class... _Args>
10840b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
10850b57cec5SDimitry Andricconstexpr _T1& get(tuple<_Args...>& __tup) noexcept
10860b57cec5SDimitry Andric{
10870b57cec5SDimitry Andric    return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
10880b57cec5SDimitry Andric}
10890b57cec5SDimitry Andric
10900b57cec5SDimitry Andrictemplate <class _T1, class... _Args>
10910b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
10920b57cec5SDimitry Andricconstexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
10930b57cec5SDimitry Andric{
10940b57cec5SDimitry Andric    return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
10950b57cec5SDimitry Andric}
10960b57cec5SDimitry Andric
10970b57cec5SDimitry Andrictemplate <class _T1, class... _Args>
10980b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
10990b57cec5SDimitry Andricconstexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
11000b57cec5SDimitry Andric{
11010b57cec5SDimitry Andric    return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
11020b57cec5SDimitry Andric}
11030b57cec5SDimitry Andric
11040b57cec5SDimitry Andrictemplate <class _T1, class... _Args>
11050b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
11060b57cec5SDimitry Andricconstexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
11070b57cec5SDimitry Andric{
11080b57cec5SDimitry Andric    return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
11090b57cec5SDimitry Andric}
11100b57cec5SDimitry Andric
11110b57cec5SDimitry Andric#endif
11120b57cec5SDimitry Andric
11130b57cec5SDimitry Andric// tie
11140b57cec5SDimitry Andric
11150b57cec5SDimitry Andrictemplate <class ..._Tp>
11160b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
11170b57cec5SDimitry Andrictuple<_Tp&...>
11180b57cec5SDimitry Andrictie(_Tp&... __t) _NOEXCEPT
11190b57cec5SDimitry Andric{
11200b57cec5SDimitry Andric    return tuple<_Tp&...>(__t...);
11210b57cec5SDimitry Andric}
11220b57cec5SDimitry Andric
11230b57cec5SDimitry Andrictemplate <class _Up>
11240b57cec5SDimitry Andricstruct __ignore_t
11250b57cec5SDimitry Andric{
11260b57cec5SDimitry Andric    template <class _Tp>
11270b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
11280b57cec5SDimitry Andric    const __ignore_t& operator=(_Tp&&) const {return *this;}
11290b57cec5SDimitry Andric};
11300b57cec5SDimitry Andric
11310b57cec5SDimitry Andricnamespace {
11320b57cec5SDimitry Andric  _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
11330b57cec5SDimitry Andric}
11340b57cec5SDimitry Andric
11350b57cec5SDimitry Andrictemplate <class... _Tp>
11360b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
11370b57cec5SDimitry Andrictuple<typename __unwrap_ref_decay<_Tp>::type...>
11380b57cec5SDimitry Andricmake_tuple(_Tp&&... __t)
11390b57cec5SDimitry Andric{
11400b57cec5SDimitry Andric    return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
11410b57cec5SDimitry Andric}
11420b57cec5SDimitry Andric
11430b57cec5SDimitry Andrictemplate <class... _Tp>
11440b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
11450b57cec5SDimitry Andrictuple<_Tp&&...>
11460b57cec5SDimitry Andricforward_as_tuple(_Tp&&... __t) _NOEXCEPT
11470b57cec5SDimitry Andric{
11480b57cec5SDimitry Andric    return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
11490b57cec5SDimitry Andric}
11500b57cec5SDimitry Andric
11510b57cec5SDimitry Andrictemplate <size_t _Ip>
11520b57cec5SDimitry Andricstruct __tuple_equal
11530b57cec5SDimitry Andric{
11540b57cec5SDimitry Andric    template <class _Tp, class _Up>
11550b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
11560b57cec5SDimitry Andric    bool operator()(const _Tp& __x, const _Up& __y)
11570b57cec5SDimitry Andric    {
11580b57cec5SDimitry Andric        return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
11590b57cec5SDimitry Andric    }
11600b57cec5SDimitry Andric};
11610b57cec5SDimitry Andric
11620b57cec5SDimitry Andrictemplate <>
11630b57cec5SDimitry Andricstruct __tuple_equal<0>
11640b57cec5SDimitry Andric{
11650b57cec5SDimitry Andric    template <class _Tp, class _Up>
11660b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
11670b57cec5SDimitry Andric    bool operator()(const _Tp&, const _Up&)
11680b57cec5SDimitry Andric    {
11690b57cec5SDimitry Andric        return true;
11700b57cec5SDimitry Andric    }
11710b57cec5SDimitry Andric};
11720b57cec5SDimitry Andric
11730b57cec5SDimitry Andrictemplate <class ..._Tp, class ..._Up>
11740b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
11750b57cec5SDimitry Andricbool
11760b57cec5SDimitry Andricoperator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
11770b57cec5SDimitry Andric{
11780b57cec5SDimitry Andric    static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
11790b57cec5SDimitry Andric    return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
11800b57cec5SDimitry Andric}
11810b57cec5SDimitry Andric
11820b57cec5SDimitry Andrictemplate <class ..._Tp, class ..._Up>
11830b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
11840b57cec5SDimitry Andricbool
11850b57cec5SDimitry Andricoperator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
11860b57cec5SDimitry Andric{
11870b57cec5SDimitry Andric    return !(__x == __y);
11880b57cec5SDimitry Andric}
11890b57cec5SDimitry Andric
11900b57cec5SDimitry Andrictemplate <size_t _Ip>
11910b57cec5SDimitry Andricstruct __tuple_less
11920b57cec5SDimitry Andric{
11930b57cec5SDimitry Andric    template <class _Tp, class _Up>
11940b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
11950b57cec5SDimitry Andric    bool operator()(const _Tp& __x, const _Up& __y)
11960b57cec5SDimitry Andric    {
11970b57cec5SDimitry Andric        const size_t __idx = tuple_size<_Tp>::value - _Ip;
11980b57cec5SDimitry Andric        if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
11990b57cec5SDimitry Andric            return true;
12000b57cec5SDimitry Andric        if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
12010b57cec5SDimitry Andric            return false;
12020b57cec5SDimitry Andric        return __tuple_less<_Ip-1>()(__x, __y);
12030b57cec5SDimitry Andric    }
12040b57cec5SDimitry Andric};
12050b57cec5SDimitry Andric
12060b57cec5SDimitry Andrictemplate <>
12070b57cec5SDimitry Andricstruct __tuple_less<0>
12080b57cec5SDimitry Andric{
12090b57cec5SDimitry Andric    template <class _Tp, class _Up>
12100b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
12110b57cec5SDimitry Andric    bool operator()(const _Tp&, const _Up&)
12120b57cec5SDimitry Andric    {
12130b57cec5SDimitry Andric        return false;
12140b57cec5SDimitry Andric    }
12150b57cec5SDimitry Andric};
12160b57cec5SDimitry Andric
12170b57cec5SDimitry Andrictemplate <class ..._Tp, class ..._Up>
12180b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
12190b57cec5SDimitry Andricbool
12200b57cec5SDimitry Andricoperator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
12210b57cec5SDimitry Andric{
12220b57cec5SDimitry Andric    static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
12230b57cec5SDimitry Andric    return __tuple_less<sizeof...(_Tp)>()(__x, __y);
12240b57cec5SDimitry Andric}
12250b57cec5SDimitry Andric
12260b57cec5SDimitry Andrictemplate <class ..._Tp, class ..._Up>
12270b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
12280b57cec5SDimitry Andricbool
12290b57cec5SDimitry Andricoperator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
12300b57cec5SDimitry Andric{
12310b57cec5SDimitry Andric    return __y < __x;
12320b57cec5SDimitry Andric}
12330b57cec5SDimitry Andric
12340b57cec5SDimitry Andrictemplate <class ..._Tp, class ..._Up>
12350b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
12360b57cec5SDimitry Andricbool
12370b57cec5SDimitry Andricoperator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
12380b57cec5SDimitry Andric{
12390b57cec5SDimitry Andric    return !(__x < __y);
12400b57cec5SDimitry Andric}
12410b57cec5SDimitry Andric
12420b57cec5SDimitry Andrictemplate <class ..._Tp, class ..._Up>
12430b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
12440b57cec5SDimitry Andricbool
12450b57cec5SDimitry Andricoperator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
12460b57cec5SDimitry Andric{
12470b57cec5SDimitry Andric    return !(__y < __x);
12480b57cec5SDimitry Andric}
12490b57cec5SDimitry Andric
12500b57cec5SDimitry Andric// tuple_cat
12510b57cec5SDimitry Andric
12520b57cec5SDimitry Andrictemplate <class _Tp, class _Up> struct __tuple_cat_type;
12530b57cec5SDimitry Andric
12540b57cec5SDimitry Andrictemplate <class ..._Ttypes, class ..._Utypes>
12550b57cec5SDimitry Andricstruct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
12560b57cec5SDimitry Andric{
12570b57cec5SDimitry Andric    typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type;
12580b57cec5SDimitry Andric};
12590b57cec5SDimitry Andric
12600b57cec5SDimitry Andrictemplate <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
12610b57cec5SDimitry Andricstruct __tuple_cat_return_1
12620b57cec5SDimitry Andric{
12630b57cec5SDimitry Andric};
12640b57cec5SDimitry Andric
12650b57cec5SDimitry Andrictemplate <class ..._Types, class _Tuple0>
12660b57cec5SDimitry Andricstruct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
12670b57cec5SDimitry Andric{
12680b57cec5SDimitry Andric    typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>,
12690b57cec5SDimitry Andric            typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
12700b57cec5SDimitry Andric                                                                           type;
12710b57cec5SDimitry Andric};
12720b57cec5SDimitry Andric
12730b57cec5SDimitry Andrictemplate <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
12740b57cec5SDimitry Andricstruct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
12750b57cec5SDimitry Andric    : public __tuple_cat_return_1<
12760b57cec5SDimitry Andric                 typename __tuple_cat_type<
12770b57cec5SDimitry Andric                     tuple<_Types...>,
12780b57cec5SDimitry Andric                     typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
12790b57cec5SDimitry Andric                 >::type,
12800b57cec5SDimitry Andric                 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
12810b57cec5SDimitry Andric                 _Tuple1, _Tuples...>
12820b57cec5SDimitry Andric{
12830b57cec5SDimitry Andric};
12840b57cec5SDimitry Andric
12850b57cec5SDimitry Andrictemplate <class ..._Tuples> struct __tuple_cat_return;
12860b57cec5SDimitry Andric
12870b57cec5SDimitry Andrictemplate <class _Tuple0, class ..._Tuples>
12880b57cec5SDimitry Andricstruct __tuple_cat_return<_Tuple0, _Tuples...>
12890b57cec5SDimitry Andric    : public __tuple_cat_return_1<tuple<>,
12900b57cec5SDimitry Andric         __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
12910b57cec5SDimitry Andric                                                                     _Tuples...>
12920b57cec5SDimitry Andric{
12930b57cec5SDimitry Andric};
12940b57cec5SDimitry Andric
12950b57cec5SDimitry Andrictemplate <>
12960b57cec5SDimitry Andricstruct __tuple_cat_return<>
12970b57cec5SDimitry Andric{
12980b57cec5SDimitry Andric    typedef _LIBCPP_NODEBUG_TYPE tuple<> type;
12990b57cec5SDimitry Andric};
13000b57cec5SDimitry Andric
13010b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
13020b57cec5SDimitry Andrictuple<>
13030b57cec5SDimitry Andrictuple_cat()
13040b57cec5SDimitry Andric{
13050b57cec5SDimitry Andric    return tuple<>();
13060b57cec5SDimitry Andric}
13070b57cec5SDimitry Andric
13080b57cec5SDimitry Andrictemplate <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
13090b57cec5SDimitry Andricstruct __tuple_cat_return_ref_imp;
13100b57cec5SDimitry Andric
13110b57cec5SDimitry Andrictemplate <class ..._Types, size_t ..._I0, class _Tuple0>
13120b57cec5SDimitry Andricstruct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
13130b57cec5SDimitry Andric{
13140b57cec5SDimitry Andric    typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
13150b57cec5SDimitry Andric    typedef tuple<_Types..., typename __apply_cv<_Tuple0,
13160b57cec5SDimitry Andric                          typename tuple_element<_I0, _T0>::type>::type&&...> type;
13170b57cec5SDimitry Andric};
13180b57cec5SDimitry Andric
13190b57cec5SDimitry Andrictemplate <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
13200b57cec5SDimitry Andricstruct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
13210b57cec5SDimitry Andric                                  _Tuple0, _Tuple1, _Tuples...>
13220b57cec5SDimitry Andric    : public __tuple_cat_return_ref_imp<
13230b57cec5SDimitry Andric         tuple<_Types..., typename __apply_cv<_Tuple0,
13240b57cec5SDimitry Andric               typename tuple_element<_I0,
13250b57cec5SDimitry Andric                  typename remove_reference<_Tuple0>::type>::type>::type&&...>,
13260b57cec5SDimitry Andric         typename __make_tuple_indices<tuple_size<typename
13270b57cec5SDimitry Andric                                 remove_reference<_Tuple1>::type>::value>::type,
13280b57cec5SDimitry Andric         _Tuple1, _Tuples...>
13290b57cec5SDimitry Andric{
13300b57cec5SDimitry Andric};
13310b57cec5SDimitry Andric
13320b57cec5SDimitry Andrictemplate <class _Tuple0, class ..._Tuples>
13330b57cec5SDimitry Andricstruct __tuple_cat_return_ref
13340b57cec5SDimitry Andric    : public __tuple_cat_return_ref_imp<tuple<>,
13350b57cec5SDimitry Andric               typename __make_tuple_indices<
13360b57cec5SDimitry Andric                        tuple_size<typename remove_reference<_Tuple0>::type>::value
13370b57cec5SDimitry Andric               >::type, _Tuple0, _Tuples...>
13380b57cec5SDimitry Andric{
13390b57cec5SDimitry Andric};
13400b57cec5SDimitry Andric
13410b57cec5SDimitry Andrictemplate <class _Types, class _I0, class _J0>
13420b57cec5SDimitry Andricstruct __tuple_cat;
13430b57cec5SDimitry Andric
13440b57cec5SDimitry Andrictemplate <class ..._Types, size_t ..._I0, size_t ..._J0>
13450b57cec5SDimitry Andricstruct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
13460b57cec5SDimitry Andric{
13470b57cec5SDimitry Andric    template <class _Tuple0>
13480b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
13490b57cec5SDimitry Andric    typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
13500b57cec5SDimitry Andric    operator()(tuple<_Types...> __t, _Tuple0&& __t0)
13510b57cec5SDimitry Andric    {
1352*480093f4SDimitry Andric        return _VSTD::forward_as_tuple(
1353*480093f4SDimitry Andric            _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
13540b57cec5SDimitry Andric            _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
13550b57cec5SDimitry Andric    }
13560b57cec5SDimitry Andric
13570b57cec5SDimitry Andric    template <class _Tuple0, class _Tuple1, class ..._Tuples>
13580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
13590b57cec5SDimitry Andric    typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
13600b57cec5SDimitry Andric    operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
13610b57cec5SDimitry Andric    {
13620b57cec5SDimitry Andric        typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
13630b57cec5SDimitry Andric        typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1;
13640b57cec5SDimitry Andric        return __tuple_cat<
1365*480093f4SDimitry Andric            tuple<_Types...,
1366*480093f4SDimitry Andric                  typename __apply_cv<_Tuple0, typename tuple_element<
1367*480093f4SDimitry Andric                                                   _J0, _T0>::type>::type&&...>,
1368*480093f4SDimitry Andric            typename __make_tuple_indices<sizeof...(_Types) +
1369*480093f4SDimitry Andric                                          tuple_size<_T0>::value>::type,
1370*480093f4SDimitry Andric            typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1371*480093f4SDimitry Andric            _VSTD::forward_as_tuple(
13720b57cec5SDimitry Andric                _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1373*480093f4SDimitry Andric                _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1374*480093f4SDimitry Andric            _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
13750b57cec5SDimitry Andric    }
13760b57cec5SDimitry Andric};
13770b57cec5SDimitry Andric
13780b57cec5SDimitry Andrictemplate <class _Tuple0, class... _Tuples>
13790b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
13800b57cec5SDimitry Andrictypename __tuple_cat_return<_Tuple0, _Tuples...>::type
13810b57cec5SDimitry Andrictuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
13820b57cec5SDimitry Andric{
13830b57cec5SDimitry Andric    typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
13840b57cec5SDimitry Andric    return __tuple_cat<tuple<>, __tuple_indices<>,
13850b57cec5SDimitry Andric                  typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
13860b57cec5SDimitry Andric                  (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
13870b57cec5SDimitry Andric                                            _VSTD::forward<_Tuples>(__tpls)...);
13880b57cec5SDimitry Andric}
13890b57cec5SDimitry Andric
13900b57cec5SDimitry Andrictemplate <class ..._Tp, class _Alloc>
13910b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
13920b57cec5SDimitry Andric    : true_type {};
13930b57cec5SDimitry Andric
13940b57cec5SDimitry Andrictemplate <class _T1, class _T2>
13950b57cec5SDimitry Andrictemplate <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
13960b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
13970b57cec5SDimitry Andricpair<_T1, _T2>::pair(piecewise_construct_t,
13980b57cec5SDimitry Andric                     tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
13990b57cec5SDimitry Andric                     __tuple_indices<_I1...>, __tuple_indices<_I2...>)
14000b57cec5SDimitry Andric    :  first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
14010b57cec5SDimitry Andric      second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
14020b57cec5SDimitry Andric{
14030b57cec5SDimitry Andric}
14040b57cec5SDimitry Andric
14050b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
14060b57cec5SDimitry Andrictemplate <class _Tp>
14070b57cec5SDimitry Andric_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
14080b57cec5SDimitry Andric
14090b57cec5SDimitry Andric#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
14100b57cec5SDimitry Andric
14110b57cec5SDimitry Andrictemplate <class _Fn, class _Tuple, size_t ..._Id>
14120b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14130b57cec5SDimitry Andricconstexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
14140b57cec5SDimitry Andric                                            __tuple_indices<_Id...>)
14150b57cec5SDimitry Andric_LIBCPP_NOEXCEPT_RETURN(
14160b57cec5SDimitry Andric    _VSTD::__invoke_constexpr(
14170b57cec5SDimitry Andric        _VSTD::forward<_Fn>(__f),
14180b57cec5SDimitry Andric        _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
14190b57cec5SDimitry Andric)
14200b57cec5SDimitry Andric
14210b57cec5SDimitry Andrictemplate <class _Fn, class _Tuple>
14220b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14230b57cec5SDimitry Andricconstexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
14240b57cec5SDimitry Andric_LIBCPP_NOEXCEPT_RETURN(
14250b57cec5SDimitry Andric    _VSTD::__apply_tuple_impl(
14260b57cec5SDimitry Andric        _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
14270b57cec5SDimitry Andric        typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
14280b57cec5SDimitry Andric)
14290b57cec5SDimitry Andric
14300b57cec5SDimitry Andrictemplate <class _Tp, class _Tuple, size_t... _Idx>
14310b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14320b57cec5SDimitry Andricconstexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
14330b57cec5SDimitry Andric_LIBCPP_NOEXCEPT_RETURN(
14340b57cec5SDimitry Andric    _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
14350b57cec5SDimitry Andric)
14360b57cec5SDimitry Andric
14370b57cec5SDimitry Andrictemplate <class _Tp, class _Tuple>
14380b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14390b57cec5SDimitry Andricconstexpr _Tp make_from_tuple(_Tuple&& __t)
14400b57cec5SDimitry Andric_LIBCPP_NOEXCEPT_RETURN(
14410b57cec5SDimitry Andric    _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
14420b57cec5SDimitry Andric        typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
14430b57cec5SDimitry Andric)
14440b57cec5SDimitry Andric
14450b57cec5SDimitry Andric#undef _LIBCPP_NOEXCEPT_RETURN
14460b57cec5SDimitry Andric
14470b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER > 14
14480b57cec5SDimitry Andric
14490b57cec5SDimitry Andric#endif // !defined(_LIBCPP_CXX03_LANG)
14500b57cec5SDimitry Andric
14510b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
14520b57cec5SDimitry Andric
14530b57cec5SDimitry Andric#endif  // _LIBCPP_TUPLE
1454