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/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)