Cleaning up some tuple code.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@114848 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ee6ccd0e32
commit
e049cc5f75
@ -127,6 +127,11 @@ template <class... _Tp> struct __tuple_like<__tuple_types<_Tp...>> : true_type {
|
||||
|
||||
// __make_tuple_types
|
||||
|
||||
// __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.
|
||||
|
||||
template <class _TupleTypes, class _Tp, size_t _Sp, size_t _Ep>
|
||||
struct __make_tuple_types_imp;
|
||||
|
||||
@ -135,7 +140,7 @@ struct __make_tuple_types_imp<__tuple_types<_Types...>, _Tp, _Sp, _Ep>
|
||||
{
|
||||
typedef typename remove_reference<_Tp>::type _Tpr;
|
||||
typedef typename __make_tuple_types_imp<__tuple_types<_Types...,
|
||||
typename conditional<is_reference<_Tp>::value,
|
||||
typename conditional<is_lvalue_reference<_Tp>::value,
|
||||
typename tuple_element<_Sp, _Tpr>::type&,
|
||||
typename tuple_element<_Sp, _Tpr>::type>::type>,
|
||||
_Tp, _Sp+1, _Ep>::type type;
|
||||
@ -154,32 +159,6 @@ struct __make_tuple_types
|
||||
typedef typename __make_tuple_types_imp<__tuple_types<>, _Tp, _Sp, _Ep>::type type;
|
||||
};
|
||||
|
||||
// __make_assignable_types
|
||||
|
||||
template <class _Tuple, class _Tp, size_t _Sp, size_t _Ep>
|
||||
struct __make_assignable_types_imp;
|
||||
|
||||
template <class ..._Types, class _Tp, size_t _Sp, size_t _Ep>
|
||||
struct __make_assignable_types_imp<__tuple_types<_Types...>, _Tp, _Sp, _Ep>
|
||||
{
|
||||
typedef typename __make_assignable_types_imp<__tuple_types<_Types...,
|
||||
typename remove_reference<typename tuple_element<_Sp, _Tp>::type>::type>,
|
||||
_Tp, _Sp+1, _Ep>::type type;
|
||||
};
|
||||
|
||||
template <class ..._Types, class _Tp, size_t _Ep>
|
||||
struct __make_assignable_types_imp<__tuple_types<_Types...>, _Tp, _Ep, _Ep>
|
||||
{
|
||||
typedef __tuple_types<_Types...> type;
|
||||
};
|
||||
|
||||
template <class _Tp, size_t _Ep = tuple_size<typename remove_reference<_Tp>::type>::value, size_t _Sp = 0>
|
||||
struct __make_assignable_types
|
||||
{
|
||||
static_assert(_Sp <= _Ep, "__make_assignable_types input error");
|
||||
typedef typename __make_assignable_types_imp<__tuple_types<>, typename remove_reference<_Tp>::type, _Sp, _Ep>::type type;
|
||||
};
|
||||
|
||||
// __tuple_convertible
|
||||
|
||||
template <bool, class _Tp, class _Up>
|
||||
@ -209,6 +188,19 @@ struct __tuple_convertible<_Tp, _Up, true, true>
|
||||
|
||||
// __tuple_assignable
|
||||
|
||||
template <bool, class _Tp, class _Up>
|
||||
struct __tuple_assignable_imp : public false_type {};
|
||||
|
||||
template <class _Tp0, class ..._Tp, class _Up0, class ..._Up>
|
||||
struct __tuple_assignable_imp<true, __tuple_types<_Tp0, _Tp...>, __tuple_types<_Up0, _Up...>>
|
||||
: public integral_constant<bool,
|
||||
__is_assignable<_Up0&, _Tp0>::value &&
|
||||
__tuple_assignable_imp<true, __tuple_types<_Tp...>, __tuple_types<_Up...>>::value> {};
|
||||
|
||||
template <>
|
||||
struct __tuple_assignable_imp<true, __tuple_types<>, __tuple_types<>>
|
||||
: public true_type {};
|
||||
|
||||
template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value,
|
||||
bool = __tuple_like<_Up>::value>
|
||||
struct __tuple_assignable
|
||||
@ -216,9 +208,9 @@ struct __tuple_assignable
|
||||
|
||||
template <class _Tp, class _Up>
|
||||
struct __tuple_assignable<_Tp, _Up, true, true>
|
||||
: public __tuple_convertible_imp<tuple_size<typename remove_reference<_Tp>::type>::value ==
|
||||
tuple_size<_Up>::value,
|
||||
typename __make_tuple_types<_Tp>::type, typename __make_assignable_types<_Up>::type>
|
||||
: public __tuple_assignable_imp<tuple_size<typename remove_reference<_Tp>::type>::value ==
|
||||
tuple_size<_Up>::value,
|
||||
typename __make_tuple_types<_Tp>::type, typename __make_tuple_types<_Up>::type>
|
||||
{};
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
@ -193,18 +193,21 @@ public:
|
||||
{static_assert(!is_reference<_Hp>::value,
|
||||
"Attempted to default construct a reference element in a tuple");}
|
||||
|
||||
template <class _Tp>
|
||||
template <class _Tp,
|
||||
class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
explicit __tuple_leaf(_Tp&& __t)
|
||||
: value(_STD::forward<_Tp>(__t))
|
||||
{static_assert(!is_lvalue_reference<_Hp>::value ||
|
||||
{static_assert(!is_reference<_Hp>::value ||
|
||||
is_lvalue_reference<_Hp>::value &&
|
||||
(is_lvalue_reference<_Tp>::value ||
|
||||
is_same<typename remove_reference<_Tp>::type,
|
||||
reference_wrapper<
|
||||
typename remove_reference<_Hp>::type
|
||||
>
|
||||
>::value),
|
||||
>::value) ||
|
||||
(is_rvalue_reference<_Hp>::value &&
|
||||
!is_lvalue_reference<_Tp>::value),
|
||||
"Attempted to construct a reference element in a tuple with an rvalue");}
|
||||
|
||||
template <class _Tp, class _Alloc>
|
||||
@ -249,6 +252,10 @@ public:
|
||||
>::value),
|
||||
"Attempted to construct a reference element in a tuple with an rvalue");}
|
||||
|
||||
__tuple_leaf(const __tuple_leaf& __t)
|
||||
: value(__t.get())
|
||||
{static_assert(!is_rvalue_reference<_Hp>::value, "Can not copy a tuple with rvalue reference member");}
|
||||
|
||||
template <class _Tp>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t)
|
||||
@ -297,7 +304,8 @@ public:
|
||||
__tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
|
||||
: _Hp(__a) {}
|
||||
|
||||
template <class _Tp>
|
||||
template <class _Tp,
|
||||
class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
explicit __tuple_leaf(_Tp&& __t)
|
||||
: _Hp(_STD::forward<_Tp>(__t)) {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user