Make pair/tuples assignment operators SFINAE properly.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@276548 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/tuple b/include/tuple
index 31613d2..a68f115 100644
--- a/include/tuple
+++ b/include/tuple
@@ -647,6 +647,9 @@
_LIBCPP_CONSTEXPR tuple()
_NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
+ tuple(tuple const&) = default;
+ tuple(tuple&&) = default;
+
template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if<
__lazy_and<
is_same<allocator_arg_t, _AllocArgT>,
@@ -885,6 +888,25 @@
tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
: base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
+ using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>;
+ using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>;
+
+ _LIBCPP_INLINE_VISIBILITY
+ tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t)
+ _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
+ {
+ base_.operator=(__t.base_);
+ return *this;
+ }
+
+ _LIBCPP_INLINE_VISIBILITY
+ tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t)
+ _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
+ {
+ base_.operator=(static_cast<base&&>(__t.base_));
+ return *this;
+ }
+
template <class _Tuple,
class = typename enable_if
<
diff --git a/include/utility b/include/utility
index fd8a7f2..74a28d8 100644
--- a/include/utility
+++ b/include/utility
@@ -348,8 +348,15 @@
// Use the implicitly declared copy constructor in C++03
#endif
+ typedef typename remove_reference<_T1>::type _T1Unref;
+ typedef typename remove_reference<_T2>::type _T2Unref;
+
+ typedef integral_constant<bool,
+ is_copy_assignable<_T1>::value
+ && is_copy_assignable<_T2>::value> _CanCopyAssign;
+
_LIBCPP_INLINE_VISIBILITY
- pair& operator=(const pair& __p)
+ pair& operator=(typename conditional<_CanCopyAssign::value, pair, __nat>::type const& __p)
_NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value &&
is_nothrow_copy_assignable<second_type>::value)
{
@@ -377,10 +384,15 @@
: first(_VSTD::forward<_U1>(__p.first)),
second(_VSTD::forward<_U2>(__p.second)) {}
+ typedef integral_constant<bool,
+ is_move_assignable<_T1>::value
+ && is_move_assignable<_T2>::value> _CanMoveAssign;
+
_LIBCPP_INLINE_VISIBILITY
pair&
- operator=(pair&& __p) _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value &&
- is_nothrow_move_assignable<second_type>::value)
+ operator=(typename conditional<_CanMoveAssign::value, pair, __nat>::type&& __p)
+ _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value &&
+ is_nothrow_move_assignable<second_type>::value)
{
first = _VSTD::forward<first_type>(__p.first);
second = _VSTD::forward<second_type>(__p.second);
@@ -388,7 +400,6 @@
}
#ifndef _LIBCPP_HAS_NO_VARIADICS
-
template<class _Tuple,
class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
@@ -411,7 +422,7 @@
{}
template <class _Tuple,
- class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type>
+ class = typename enable_if<!is_same<typename decay<_Tuple>::type, pair>::value && __tuple_assignable<_Tuple, pair>::value>::type>
_LIBCPP_INLINE_VISIBILITY
pair&
operator=(_Tuple&& __p)