[cfe-commits] [libcxx] r114848 - in /libcxx/trunk/include: __tuple tuple
Howard Hinnant
hhinnant at apple.com
Mon Sep 27 10:54:17 PDT 2010
Author: hhinnant
Date: Mon Sep 27 12:54:17 2010
New Revision: 114848
URL: http://llvm.org/viewvc/llvm-project?rev=114848&view=rev
Log:
Cleaning up some tuple code.
Modified:
libcxx/trunk/include/__tuple
libcxx/trunk/include/tuple
Modified: libcxx/trunk/include/__tuple
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__tuple?rev=114848&r1=114847&r2=114848&view=diff
==============================================================================
--- libcxx/trunk/include/__tuple (original)
+++ libcxx/trunk/include/__tuple Mon Sep 27 12:54:17 2010
@@ -127,6 +127,11 @@
// __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 @@
{
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 @@
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 @@
// __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 @@
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
Modified: libcxx/trunk/include/tuple
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/tuple?rev=114848&r1=114847&r2=114848&view=diff
==============================================================================
--- libcxx/trunk/include/tuple (original)
+++ libcxx/trunk/include/tuple Mon Sep 27 12:54:17 2010
@@ -193,18 +193,21 @@
{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 @@
>::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 @@
__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)) {}
More information about the cfe-commits
mailing list