2010-05-12 03:42:16 +08:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP___TUPLE
|
|
|
|
#define _LIBCPP___TUPLE
|
|
|
|
|
|
|
|
#include <__config>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <type_traits>
|
|
|
|
|
2011-10-18 04:05:10 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-02 09:16:40 +08:00
|
|
|
# pragma GCC system_header
|
2011-10-18 04:05:10 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2019-01-12 05:57:12 +08:00
|
|
|
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_size;
|
2017-01-03 07:54:13 +08:00
|
|
|
|
2017-01-05 06:38:46 +08:00
|
|
|
#if !defined(_LIBCPP_CXX03_LANG)
|
|
|
|
template <class _Tp, class...>
|
|
|
|
using __enable_if_tuple_size_imp = _Tp;
|
2017-01-03 07:54:13 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
2019-01-12 05:57:12 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp<
|
2017-01-05 06:38:46 +08:00
|
|
|
const _Tp,
|
|
|
|
typename enable_if<!is_volatile<_Tp>::value>::type,
|
|
|
|
integral_constant<size_t, sizeof(tuple_size<_Tp>)>>>
|
|
|
|
: public integral_constant<size_t, tuple_size<_Tp>::value> {};
|
2010-11-18 03:22:43 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
2019-01-12 05:57:12 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp<
|
2017-01-05 06:38:46 +08:00
|
|
|
volatile _Tp,
|
|
|
|
typename enable_if<!is_const<_Tp>::value>::type,
|
|
|
|
integral_constant<size_t, sizeof(tuple_size<_Tp>)>>>
|
|
|
|
: public integral_constant<size_t, tuple_size<_Tp>::value> {};
|
2010-11-18 03:22:43 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
2019-01-12 05:57:12 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp<
|
2017-01-05 06:38:46 +08:00
|
|
|
const volatile _Tp,
|
|
|
|
integral_constant<size_t, sizeof(tuple_size<_Tp>)>>>
|
|
|
|
: public integral_constant<size_t, tuple_size<_Tp>::value> {};
|
|
|
|
|
|
|
|
#else
|
2019-01-12 05:57:12 +08:00
|
|
|
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_size<const _Tp> : public tuple_size<_Tp> {};
|
|
|
|
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_size<volatile _Tp> : public tuple_size<_Tp> {};
|
|
|
|
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_size<const volatile _Tp> : public tuple_size<_Tp> {};
|
2017-01-05 06:38:46 +08:00
|
|
|
#endif
|
2010-11-18 03:22:43 +08:00
|
|
|
|
2019-04-02 00:39:34 +08:00
|
|
|
template <size_t _Ip, class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_element;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-11-18 03:22:43 +08:00
|
|
|
template <size_t _Ip, class _Tp>
|
2019-04-02 00:39:34 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp>
|
2010-11-18 03:22:43 +08:00
|
|
|
{
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type;
|
2010-11-18 03:22:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <size_t _Ip, class _Tp>
|
2019-04-02 00:39:34 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp>
|
2010-11-18 03:22:43 +08:00
|
|
|
{
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type;
|
2010-11-18 03:22:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <size_t _Ip, class _Tp>
|
2019-04-02 00:39:34 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp>
|
2010-11-18 03:22:43 +08:00
|
|
|
{
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type;
|
2010-11-18 03:22:43 +08:00
|
|
|
};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp> struct __tuple_like : false_type {};
|
|
|
|
|
2010-12-12 04:47:50 +08:00
|
|
|
template <class _Tp> struct __tuple_like<const _Tp> : public __tuple_like<_Tp> {};
|
|
|
|
template <class _Tp> struct __tuple_like<volatile _Tp> : public __tuple_like<_Tp> {};
|
|
|
|
template <class _Tp> struct __tuple_like<const volatile _Tp> : public __tuple_like<_Tp> {};
|
|
|
|
|
2015-03-17 23:08:03 +08:00
|
|
|
// tuple specializations
|
|
|
|
|
2017-04-19 09:23:39 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2016-07-01 06:34:43 +08:00
|
|
|
|
|
|
|
template <size_t...> struct __tuple_indices {};
|
|
|
|
|
|
|
|
template <class _IdxType, _IdxType... _Values>
|
|
|
|
struct __integer_sequence {
|
|
|
|
template <template <class _OIdxType, _OIdxType...> class _ToIndexSeq, class _ToIndexType>
|
|
|
|
using __convert = _ToIndexSeq<_ToIndexType, _Values...>;
|
|
|
|
|
|
|
|
template <size_t _Sp>
|
|
|
|
using __to_tuple_indices = __tuple_indices<(_Values + _Sp)...>;
|
|
|
|
};
|
|
|
|
|
|
|
|
#if !__has_builtin(__make_integer_seq) || defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
|
|
|
|
namespace __detail {
|
|
|
|
|
|
|
|
template<typename _Tp, size_t ..._Extra> struct __repeat;
|
|
|
|
template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<__integer_sequence<_Tp, _Np...>, _Extra...> {
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG __integer_sequence<_Tp,
|
2016-07-01 06:34:43 +08:00
|
|
|
_Np...,
|
|
|
|
sizeof...(_Np) + _Np...,
|
|
|
|
2 * sizeof...(_Np) + _Np...,
|
|
|
|
3 * sizeof...(_Np) + _Np...,
|
|
|
|
4 * sizeof...(_Np) + _Np...,
|
|
|
|
5 * sizeof...(_Np) + _Np...,
|
|
|
|
6 * sizeof...(_Np) + _Np...,
|
|
|
|
7 * sizeof...(_Np) + _Np...,
|
|
|
|
_Extra...> type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<size_t _Np> struct __parity;
|
|
|
|
template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {};
|
|
|
|
|
|
|
|
template<> struct __make<0> { typedef __integer_sequence<size_t> type; };
|
|
|
|
template<> struct __make<1> { typedef __integer_sequence<size_t, 0> type; };
|
|
|
|
template<> struct __make<2> { typedef __integer_sequence<size_t, 0, 1> type; };
|
|
|
|
template<> struct __make<3> { typedef __integer_sequence<size_t, 0, 1, 2> type; };
|
|
|
|
template<> struct __make<4> { typedef __integer_sequence<size_t, 0, 1, 2, 3> type; };
|
|
|
|
template<> struct __make<5> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4> type; };
|
|
|
|
template<> struct __make<6> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4, 5> type; };
|
|
|
|
template<> struct __make<7> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4, 5, 6> type; };
|
|
|
|
|
|
|
|
template<> struct __parity<0> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type> {}; };
|
|
|
|
template<> struct __parity<1> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 1> {}; };
|
|
|
|
template<> struct __parity<2> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 2, _Np - 1> {}; };
|
|
|
|
template<> struct __parity<3> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 3, _Np - 2, _Np - 1> {}; };
|
|
|
|
template<> struct __parity<4> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
|
|
|
|
template<> struct __parity<5> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
|
|
|
|
template<> struct __parity<6> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
|
|
|
|
template<> struct __parity<7> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 7, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // !__has_builtin(__make_integer_seq) || defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
|
2016-07-01 06:34:43 +08:00
|
|
|
|
|
|
|
#if __has_builtin(__make_integer_seq)
|
|
|
|
template <size_t _Ep, size_t _Sp>
|
|
|
|
using __make_indices_imp =
|
|
|
|
typename __make_integer_seq<__integer_sequence, size_t, _Ep - _Sp>::template
|
|
|
|
__to_tuple_indices<_Sp>;
|
|
|
|
#else
|
|
|
|
template <size_t _Ep, size_t _Sp>
|
|
|
|
using __make_indices_imp =
|
|
|
|
typename __detail::__make<_Ep - _Sp>::type::template __to_tuple_indices<_Sp>;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template <size_t _Ep, size_t _Sp = 0>
|
|
|
|
struct __make_tuple_indices
|
|
|
|
{
|
|
|
|
static_assert(_Sp <= _Ep, "__make_tuple_indices input error");
|
|
|
|
typedef __make_indices_imp<_Ep, _Sp> type;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-01-05 07:56:00 +08:00
|
|
|
template <class ..._Tp> class _LIBCPP_TEMPLATE_VIS tuple;
|
2015-03-17 23:08:03 +08:00
|
|
|
|
2011-01-25 00:07:25 +08:00
|
|
|
template <class... _Tp> struct __tuple_like<tuple<_Tp...> > : true_type {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-07-25 12:32:07 +08:00
|
|
|
template <class ..._Tp>
|
2019-01-12 05:57:12 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS tuple_size<tuple<_Tp...> >
|
2016-07-25 12:32:07 +08:00
|
|
|
: public integral_constant<size_t, sizeof...(_Tp)>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <size_t _Ip, class ..._Tp>
|
2013-07-18 02:25:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2011-01-25 00:07:25 +08:00
|
|
|
typename tuple_element<_Ip, tuple<_Tp...> >::type&
|
2011-05-28 03:08:18 +08:00
|
|
|
get(tuple<_Tp...>&) _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <size_t _Ip, class ..._Tp>
|
2013-07-18 02:25:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2011-01-25 00:07:25 +08:00
|
|
|
const typename tuple_element<_Ip, tuple<_Tp...> >::type&
|
2011-05-28 03:08:18 +08:00
|
|
|
get(const tuple<_Tp...>&) _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-11-18 03:52:17 +08:00
|
|
|
template <size_t _Ip, class ..._Tp>
|
2013-07-18 02:25:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2011-01-25 00:07:25 +08:00
|
|
|
typename tuple_element<_Ip, tuple<_Tp...> >::type&&
|
2011-05-28 03:08:18 +08:00
|
|
|
get(tuple<_Tp...>&&) _NOEXCEPT;
|
2015-12-18 08:36:55 +08:00
|
|
|
|
|
|
|
template <size_t _Ip, class ..._Tp>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
|
|
|
|
get(const tuple<_Tp...>&&) _NOEXCEPT;
|
2017-04-19 09:23:39 +08:00
|
|
|
|
|
|
|
#endif // !defined(_LIBCPP_CXX03_LANG)
|
2015-03-17 23:08:03 +08:00
|
|
|
|
|
|
|
// pair specializations
|
|
|
|
|
|
|
|
template <class _T1, class _T2> struct __tuple_like<pair<_T1, _T2> > : true_type {};
|
2010-11-18 03:52:17 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <size_t _Ip, class _T1, class _T2>
|
2013-07-18 02:25:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
typename tuple_element<_Ip, pair<_T1, _T2> >::type&
|
2011-05-28 03:08:18 +08:00
|
|
|
get(pair<_T1, _T2>&) _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <size_t _Ip, class _T1, class _T2>
|
2013-07-18 02:25:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
|
2011-05-28 03:08:18 +08:00
|
|
|
get(const pair<_T1, _T2>&) _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-19 09:23:39 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-11-18 03:52:17 +08:00
|
|
|
template <size_t _Ip, class _T1, class _T2>
|
2013-07-18 02:25:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-11-18 03:52:17 +08:00
|
|
|
typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
|
2011-05-28 03:08:18 +08:00
|
|
|
get(pair<_T1, _T2>&&) _NOEXCEPT;
|
2015-12-18 08:36:55 +08:00
|
|
|
|
|
|
|
template <size_t _Ip, class _T1, class _T2>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
|
|
|
|
get(const pair<_T1, _T2>&&) _NOEXCEPT;
|
2015-03-17 23:08:03 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// array specializations
|
|
|
|
|
2017-01-05 07:56:00 +08:00
|
|
|
template <class _Tp, size_t _Size> struct _LIBCPP_TEMPLATE_VIS array;
|
2015-03-17 23:08:03 +08:00
|
|
|
|
|
|
|
template <class _Tp, size_t _Size> struct __tuple_like<array<_Tp, _Size> > : true_type {};
|
2010-11-18 03:52:17 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <size_t _Ip, class _Tp, size_t _Size>
|
2013-07-18 02:25:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
_Tp&
|
2011-06-01 05:06:33 +08:00
|
|
|
get(array<_Tp, _Size>&) _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <size_t _Ip, class _Tp, size_t _Size>
|
2013-07-18 02:25:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
const _Tp&
|
2011-06-01 05:06:33 +08:00
|
|
|
get(const array<_Tp, _Size>&) _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-19 09:23:39 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-11-18 03:52:17 +08:00
|
|
|
template <size_t _Ip, class _Tp, size_t _Size>
|
2013-07-18 02:25:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-11-18 03:52:17 +08:00
|
|
|
_Tp&&
|
2011-06-01 05:06:33 +08:00
|
|
|
get(array<_Tp, _Size>&&) _NOEXCEPT;
|
2015-12-18 08:36:55 +08:00
|
|
|
|
|
|
|
template <size_t _Ip, class _Tp, size_t _Size>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
const _Tp&&
|
|
|
|
get(const array<_Tp, _Size>&&) _NOEXCEPT;
|
2015-03-17 23:08:03 +08:00
|
|
|
#endif
|
|
|
|
|
2017-04-19 09:23:39 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
// __tuple_types
|
|
|
|
|
|
|
|
template <class ..._Tp> struct __tuple_types {};
|
|
|
|
|
2016-07-01 11:54:54 +08:00
|
|
|
#if !__has_builtin(__type_pack_element)
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-07-01 11:54:54 +08:00
|
|
|
namespace __indexer_detail {
|
|
|
|
|
|
|
|
template <size_t _Idx, class _Tp>
|
2021-08-31 22:32:11 +08:00
|
|
|
struct __indexed { using type _LIBCPP_NODEBUG = _Tp; };
|
2016-07-01 11:54:54 +08:00
|
|
|
|
|
|
|
template <class _Types, class _Indexes> struct __indexer;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-07-01 11:54:54 +08:00
|
|
|
template <class ..._Types, size_t ..._Idx>
|
|
|
|
struct __indexer<__tuple_types<_Types...>, __tuple_indices<_Idx...>>
|
|
|
|
: __indexed<_Idx, _Types>...
|
|
|
|
{};
|
|
|
|
|
|
|
|
template <size_t _Idx, class _Tp>
|
|
|
|
__indexed<_Idx, _Tp> __at_index(__indexed<_Idx, _Tp> const&);
|
|
|
|
|
|
|
|
} // namespace __indexer_detail
|
|
|
|
|
|
|
|
template <size_t _Idx, class ..._Types>
|
2021-08-31 22:32:11 +08:00
|
|
|
using __type_pack_element _LIBCPP_NODEBUG = typename decltype(
|
2016-07-01 11:54:54 +08:00
|
|
|
__indexer_detail::__at_index<_Idx>(
|
|
|
|
__indexer_detail::__indexer<
|
|
|
|
__tuple_types<_Types...>,
|
|
|
|
typename __make_tuple_indices<sizeof...(_Types)>::type
|
|
|
|
>{})
|
|
|
|
)::type;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template <size_t _Ip, class ..._Types>
|
2022-02-18 05:53:20 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...> >
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2016-07-01 11:54:54 +08:00
|
|
|
static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range");
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG __type_pack_element<_Ip, _Types...> type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2016-07-01 12:07:39 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class ..._Tp>
|
2019-01-12 05:57:12 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS tuple_size<__tuple_types<_Tp...> >
|
2010-05-12 03:42:16 +08:00
|
|
|
: public integral_constant<size_t, sizeof...(_Tp)>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2011-01-25 00:07:25 +08:00
|
|
|
template <class... _Tp> struct __tuple_like<__tuple_types<_Tp...> > : true_type {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-07-01 11:54:54 +08:00
|
|
|
template <bool _ApplyLV, bool _ApplyConst, bool _ApplyVolatile>
|
|
|
|
struct __apply_cv_mf;
|
|
|
|
template <>
|
|
|
|
struct __apply_cv_mf<false, false, false> {
|
|
|
|
template <class _Tp> using __apply = _Tp;
|
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct __apply_cv_mf<false, true, false> {
|
2021-08-31 22:32:11 +08:00
|
|
|
template <class _Tp> using __apply _LIBCPP_NODEBUG = const _Tp;
|
2016-07-01 11:54:54 +08:00
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct __apply_cv_mf<false, false, true> {
|
2021-08-31 22:32:11 +08:00
|
|
|
template <class _Tp> using __apply _LIBCPP_NODEBUG = volatile _Tp;
|
2016-07-01 11:54:54 +08:00
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct __apply_cv_mf<false, true, true> {
|
2021-08-31 22:32:11 +08:00
|
|
|
template <class _Tp> using __apply _LIBCPP_NODEBUG = const volatile _Tp;
|
2016-07-01 11:54:54 +08:00
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct __apply_cv_mf<true, false, false> {
|
2021-08-31 22:32:11 +08:00
|
|
|
template <class _Tp> using __apply _LIBCPP_NODEBUG = _Tp&;
|
2016-07-01 11:54:54 +08:00
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct __apply_cv_mf<true, true, false> {
|
2021-08-31 22:32:11 +08:00
|
|
|
template <class _Tp> using __apply _LIBCPP_NODEBUG = const _Tp&;
|
2016-07-01 11:54:54 +08:00
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct __apply_cv_mf<true, false, true> {
|
2021-08-31 22:32:11 +08:00
|
|
|
template <class _Tp> using __apply _LIBCPP_NODEBUG = volatile _Tp&;
|
2016-07-01 11:54:54 +08:00
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct __apply_cv_mf<true, true, true> {
|
2021-08-31 22:32:11 +08:00
|
|
|
template <class _Tp> using __apply _LIBCPP_NODEBUG = const volatile _Tp&;
|
2016-07-01 11:54:54 +08:00
|
|
|
};
|
|
|
|
template <class _Tp, class _RawTp = typename remove_reference<_Tp>::type>
|
2021-08-31 22:32:11 +08:00
|
|
|
using __apply_cv_t _LIBCPP_NODEBUG = __apply_cv_mf<
|
2016-07-01 11:54:54 +08:00
|
|
|
is_lvalue_reference<_Tp>::value,
|
|
|
|
is_const<_RawTp>::value,
|
|
|
|
is_volatile<_RawTp>::value>;
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
// __make_tuple_types
|
|
|
|
|
2010-09-28 01:54:17 +08:00
|
|
|
// __make_tuple_types<_Tuple<_Types...>, _Ep, _Sp>::type is a
|
|
|
|
// __tuple_types<_Types...> using only those _Types in the range [_Sp, _Ep).
|
|
|
|
// _Sp defaults to 0 and _Ep defaults to tuple_size<_Tuple>. If _Tuple is a
|
|
|
|
// lvalue_reference type, then __tuple_types<_Types&...> is the result.
|
|
|
|
|
2016-07-01 11:54:54 +08:00
|
|
|
template <class _TupleTypes, class _TupleIndices>
|
|
|
|
struct __make_tuple_types_flat;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-07-01 11:54:54 +08:00
|
|
|
template <template <class...> class _Tuple, class ..._Types, size_t ..._Idx>
|
|
|
|
struct __make_tuple_types_flat<_Tuple<_Types...>, __tuple_indices<_Idx...>> {
|
|
|
|
// Specialization for pair, tuple, and __tuple_types
|
|
|
|
template <class _Tp, class _ApplyFn = __apply_cv_t<_Tp>>
|
2021-08-31 22:32:11 +08:00
|
|
|
using __apply_quals _LIBCPP_NODEBUG = __tuple_types<
|
2016-07-01 11:54:54 +08:00
|
|
|
typename _ApplyFn::template __apply<__type_pack_element<_Idx, _Types...>>...
|
|
|
|
>;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2016-07-01 11:54:54 +08:00
|
|
|
template <class _Vt, size_t _Np, size_t ..._Idx>
|
|
|
|
struct __make_tuple_types_flat<array<_Vt, _Np>, __tuple_indices<_Idx...>> {
|
2016-07-02 09:25:46 +08:00
|
|
|
template <size_t>
|
|
|
|
using __value_type = _Vt;
|
2016-07-01 11:54:54 +08:00
|
|
|
template <class _Tp, class _ApplyFn = __apply_cv_t<_Tp>>
|
|
|
|
using __apply_quals = __tuple_types<
|
2016-07-02 09:25:46 +08:00
|
|
|
typename _ApplyFn::template __apply<__value_type<_Idx>>...
|
2016-07-01 11:54:54 +08:00
|
|
|
>;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2016-07-01 11:54:54 +08:00
|
|
|
template <class _Tp, size_t _Ep = tuple_size<typename remove_reference<_Tp>::type>::value,
|
|
|
|
size_t _Sp = 0,
|
|
|
|
bool _SameSize = (_Ep == tuple_size<typename remove_reference<_Tp>::type>::value)>
|
2010-05-12 03:42:16 +08:00
|
|
|
struct __make_tuple_types
|
|
|
|
{
|
|
|
|
static_assert(_Sp <= _Ep, "__make_tuple_types input error");
|
2016-07-01 11:54:54 +08:00
|
|
|
using _RawTp = typename remove_cv<typename remove_reference<_Tp>::type>::type;
|
|
|
|
using _Maker = __make_tuple_types_flat<_RawTp, typename __make_tuple_indices<_Ep, _Sp>::type>;
|
|
|
|
using type = typename _Maker::template __apply_quals<_Tp>;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class ..._Types, size_t _Ep>
|
|
|
|
struct __make_tuple_types<tuple<_Types...>, _Ep, 0, true> {
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG __tuple_types<_Types...> type;
|
2016-07-01 11:54:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class ..._Types, size_t _Ep>
|
|
|
|
struct __make_tuple_types<__tuple_types<_Types...>, _Ep, 0, true> {
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG __tuple_types<_Types...> type;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2016-07-01 12:07:39 +08:00
|
|
|
template <bool ..._Preds>
|
|
|
|
struct __all_dummy;
|
|
|
|
|
|
|
|
template <bool ..._Pred>
|
2021-12-04 03:55:57 +08:00
|
|
|
struct __all : _IsSame<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...>> {};
|
2016-07-01 12:07:39 +08:00
|
|
|
|
|
|
|
struct __tuple_sfinae_base {
|
2016-07-02 09:25:46 +08:00
|
|
|
template <template <class, class...> class _Trait,
|
|
|
|
class ..._LArgs, class ..._RArgs>
|
|
|
|
static auto __do_test(__tuple_types<_LArgs...>, __tuple_types<_RArgs...>)
|
|
|
|
-> __all<typename enable_if<_Trait<_LArgs, _RArgs>::value, bool>::type{true}...>;
|
|
|
|
template <template <class...> class>
|
|
|
|
static auto __do_test(...) -> false_type;
|
|
|
|
|
|
|
|
template <class _FromArgs, class _ToArgs>
|
|
|
|
using __constructible = decltype(__do_test<is_constructible>(_ToArgs{}, _FromArgs{}));
|
|
|
|
template <class _FromArgs, class _ToArgs>
|
|
|
|
using __convertible = decltype(__do_test<is_convertible>(_FromArgs{}, _ToArgs{}));
|
|
|
|
template <class _FromArgs, class _ToArgs>
|
|
|
|
using __assignable = decltype(__do_test<is_assignable>(_ToArgs{}, _FromArgs{}));
|
2016-07-01 12:07:39 +08:00
|
|
|
};
|
2014-10-28 14:31:22 +08:00
|
|
|
|
2016-07-01 12:07:39 +08:00
|
|
|
// __tuple_convertible
|
2014-10-28 14:31:22 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value,
|
|
|
|
bool = __tuple_like<_Up>::value>
|
|
|
|
struct __tuple_convertible
|
|
|
|
: public false_type {};
|
|
|
|
|
|
|
|
template <class _Tp, class _Up>
|
|
|
|
struct __tuple_convertible<_Tp, _Up, true, true>
|
2016-07-01 12:07:39 +08:00
|
|
|
: public __tuple_sfinae_base::__convertible<
|
2014-10-28 14:31:22 +08:00
|
|
|
typename __make_tuple_types<_Tp>::type
|
|
|
|
, typename __make_tuple_types<_Up>::type
|
|
|
|
>
|
|
|
|
{};
|
|
|
|
|
2016-07-01 12:07:39 +08:00
|
|
|
// __tuple_constructible
|
|
|
|
|
2012-04-02 07:10:42 +08:00
|
|
|
template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value,
|
|
|
|
bool = __tuple_like<_Up>::value>
|
|
|
|
struct __tuple_constructible
|
|
|
|
: public false_type {};
|
|
|
|
|
|
|
|
template <class _Tp, class _Up>
|
|
|
|
struct __tuple_constructible<_Tp, _Up, true, true>
|
2016-07-01 12:07:39 +08:00
|
|
|
: public __tuple_sfinae_base::__constructible<
|
2014-10-28 14:31:22 +08:00
|
|
|
typename __make_tuple_types<_Tp>::type
|
|
|
|
, typename __make_tuple_types<_Up>::type
|
|
|
|
>
|
|
|
|
{};
|
|
|
|
|
2016-07-01 12:07:39 +08:00
|
|
|
// __tuple_assignable
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value,
|
|
|
|
bool = __tuple_like<_Up>::value>
|
|
|
|
struct __tuple_assignable
|
|
|
|
: public false_type {};
|
|
|
|
|
|
|
|
template <class _Tp, class _Up>
|
|
|
|
struct __tuple_assignable<_Tp, _Up, true, true>
|
2016-07-01 12:07:39 +08:00
|
|
|
: public __tuple_sfinae_base::__assignable<
|
|
|
|
typename __make_tuple_types<_Tp>::type
|
2016-07-02 09:25:46 +08:00
|
|
|
, typename __make_tuple_types<_Up&>::type
|
2016-07-01 12:07:39 +08:00
|
|
|
>
|
2010-05-12 03:42:16 +08:00
|
|
|
{};
|
|
|
|
|
2016-07-25 12:32:07 +08:00
|
|
|
|
|
|
|
template <size_t _Ip, class ..._Tp>
|
2019-04-02 00:39:34 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, tuple<_Tp...> >
|
2016-07-25 12:32:07 +08:00
|
|
|
{
|
2021-08-31 22:32:11 +08:00
|
|
|
typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
|
2016-07-25 12:32:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#if _LIBCPP_STD_VER > 11
|
|
|
|
template <size_t _Ip, class ..._Tp>
|
2021-08-31 22:32:11 +08:00
|
|
|
using tuple_element_t _LIBCPP_NODEBUG = typename tuple_element <_Ip, _Tp...>::type;
|
2016-07-25 12:32:07 +08:00
|
|
|
#endif
|
|
|
|
|
2016-12-15 14:34:54 +08:00
|
|
|
template <bool _IsTuple, class _SizeTrait, size_t _Expected>
|
|
|
|
struct __tuple_like_with_size_imp : false_type {};
|
|
|
|
|
|
|
|
template <class _SizeTrait, size_t _Expected>
|
|
|
|
struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected>
|
|
|
|
: integral_constant<bool, _SizeTrait::value == _Expected> {};
|
|
|
|
|
2022-02-18 05:53:20 +08:00
|
|
|
template <class _Tuple, size_t _ExpectedSize, class _RawTuple = __uncvref_t<_Tuple> >
|
2021-08-31 22:32:11 +08:00
|
|
|
using __tuple_like_with_size _LIBCPP_NODEBUG = __tuple_like_with_size_imp<
|
2016-12-15 14:34:54 +08:00
|
|
|
__tuple_like<_RawTuple>::value,
|
|
|
|
tuple_size<_RawTuple>, _ExpectedSize
|
|
|
|
>;
|
2016-07-25 12:32:07 +08:00
|
|
|
|
|
|
|
struct _LIBCPP_TYPE_VIS __check_tuple_constructor_fail {
|
2019-10-01 04:55:30 +08:00
|
|
|
|
|
|
|
static constexpr bool __enable_explicit_default() { return false; }
|
|
|
|
static constexpr bool __enable_implicit_default() { return false; }
|
2016-07-25 12:32:07 +08:00
|
|
|
template <class ...>
|
|
|
|
static constexpr bool __enable_explicit() { return false; }
|
|
|
|
template <class ...>
|
|
|
|
static constexpr bool __enable_implicit() { return false; }
|
|
|
|
template <class ...>
|
|
|
|
static constexpr bool __enable_assign() { return false; }
|
|
|
|
};
|
2017-04-19 09:23:39 +08:00
|
|
|
#endif // !defined(_LIBCPP_CXX03_LANG)
|
2016-07-25 12:32:07 +08:00
|
|
|
|
2016-08-15 09:51:54 +08:00
|
|
|
#if _LIBCPP_STD_VER > 14
|
|
|
|
|
|
|
|
template <bool _CanCopy, bool _CanMove>
|
|
|
|
struct __sfinae_ctor_base {};
|
|
|
|
template <>
|
|
|
|
struct __sfinae_ctor_base<false, false> {
|
|
|
|
__sfinae_ctor_base() = default;
|
|
|
|
__sfinae_ctor_base(__sfinae_ctor_base const&) = delete;
|
|
|
|
__sfinae_ctor_base(__sfinae_ctor_base &&) = delete;
|
|
|
|
__sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default;
|
|
|
|
__sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default;
|
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct __sfinae_ctor_base<true, false> {
|
|
|
|
__sfinae_ctor_base() = default;
|
|
|
|
__sfinae_ctor_base(__sfinae_ctor_base const&) = default;
|
|
|
|
__sfinae_ctor_base(__sfinae_ctor_base &&) = delete;
|
|
|
|
__sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default;
|
|
|
|
__sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default;
|
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct __sfinae_ctor_base<false, true> {
|
|
|
|
__sfinae_ctor_base() = default;
|
|
|
|
__sfinae_ctor_base(__sfinae_ctor_base const&) = delete;
|
|
|
|
__sfinae_ctor_base(__sfinae_ctor_base &&) = default;
|
|
|
|
__sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default;
|
|
|
|
__sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <bool _CanCopy, bool _CanMove>
|
|
|
|
struct __sfinae_assign_base {};
|
|
|
|
template <>
|
|
|
|
struct __sfinae_assign_base<false, false> {
|
|
|
|
__sfinae_assign_base() = default;
|
|
|
|
__sfinae_assign_base(__sfinae_assign_base const&) = default;
|
|
|
|
__sfinae_assign_base(__sfinae_assign_base &&) = default;
|
|
|
|
__sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete;
|
|
|
|
__sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete;
|
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct __sfinae_assign_base<true, false> {
|
|
|
|
__sfinae_assign_base() = default;
|
|
|
|
__sfinae_assign_base(__sfinae_assign_base const&) = default;
|
|
|
|
__sfinae_assign_base(__sfinae_assign_base &&) = default;
|
|
|
|
__sfinae_assign_base& operator=(__sfinae_assign_base const&) = default;
|
|
|
|
__sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete;
|
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct __sfinae_assign_base<false, true> {
|
|
|
|
__sfinae_assign_base() = default;
|
|
|
|
__sfinae_assign_base(__sfinae_assign_base const&) = default;
|
|
|
|
__sfinae_assign_base(__sfinae_assign_base &&) = default;
|
|
|
|
__sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete;
|
|
|
|
__sfinae_assign_base& operator=(__sfinae_assign_base&&) = default;
|
|
|
|
};
|
|
|
|
#endif // _LIBCPP_STD_VER > 14
|
|
|
|
|
2015-03-17 23:08:03 +08:00
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP___TUPLE
|