[libcxx] r189036 - Zhihao Yuan noted that a move assignment operation was missing from std::adjacent_difference. Fixed.

Howard Hinnant hhinnant at apple.com
Thu Aug 22 11:02:35 PDT 2013


Author: hhinnant
Date: Thu Aug 22 13:02:34 2013
New Revision: 189036

URL: http://llvm.org/viewvc/llvm-project?rev=189036&view=rev
Log:
Zhihao Yuan noted that a move assignment operation was missing from std::adjacent_difference.  Fixed.

Modified:
    libcxx/trunk/include/numeric
    libcxx/trunk/test/numerics/numeric.ops/adjacent.difference/adjacent_difference.pass.cpp
    libcxx/trunk/test/numerics/numeric.ops/adjacent.difference/adjacent_difference_op.pass.cpp

Modified: libcxx/trunk/include/numeric
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/numeric?rev=189036&r1=189035&r2=189036&view=diff
==============================================================================
--- libcxx/trunk/include/numeric (original)
+++ libcxx/trunk/include/numeric Thu Aug 22 13:02:34 2013
@@ -157,7 +157,7 @@ adjacent_difference(_InputIterator __fir
         {
             typename iterator_traits<_InputIterator>::value_type __t2(*__first);
             *__result = __t2 - __t1;
-            __t1 = __t2;
+            __t1 = _VSTD::move(__t2);
         }
     }
     return __result;
@@ -177,7 +177,7 @@ adjacent_difference(_InputIterator __fir
         {
             typename iterator_traits<_InputIterator>::value_type __t2(*__first);
             *__result = __binary_op(__t2, __t1);
-            __t1 = __t2;
+            __t1 = _VSTD::move(__t2);
         }
     }
     return __result;

Modified: libcxx/trunk/test/numerics/numeric.ops/adjacent.difference/adjacent_difference.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/numeric.ops/adjacent.difference/adjacent_difference.pass.cpp?rev=189036&r1=189035&r2=189036&view=diff
==============================================================================
--- libcxx/trunk/test/numerics/numeric.ops/adjacent.difference/adjacent_difference.pass.cpp (original)
+++ libcxx/trunk/test/numerics/numeric.ops/adjacent.difference/adjacent_difference.pass.cpp Thu Aug 22 13:02:34 2013
@@ -38,6 +38,43 @@ test()
         assert(ib[i] == ir[i]);
 }
 
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+class Y;
+
+class X
+{
+    int i_;
+
+    X& operator=(const X&);
+public:
+    explicit X(int i) : i_(i) {}
+    X(const X& x) : i_(x.i_) {}
+    X& operator=(X&& x)
+    {
+        i_ = x.i_;
+        x.i_ = -1;
+        return *this;
+    }
+
+    friend X operator-(const X& x, const X& y) {return X(x.i_ - y.i_);}
+
+    friend class Y;
+};
+
+class Y
+{
+    int i_;
+
+    Y& operator=(const Y&);
+public:
+    explicit Y(int i) : i_(i) {}
+    Y(const Y& y) : i_(y.i_) {}
+    void operator=(const X& x) {i_ = x.i_;}
+};
+
+#endif
+
 int main()
 {
     test<input_iterator<const int*>, output_iterator<int*> >();
@@ -69,4 +106,10 @@ int main()
     test<const int*, bidirectional_iterator<int*> >();
     test<const int*, random_access_iterator<int*> >();
     test<const int*, int*>();
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    X x[3] = {X(1), X(2), X(3)};
+    Y y[3] = {Y(1), Y(2), Y(3)};
+    std::adjacent_difference(x, x+3, y);
+#endif
 }

Modified: libcxx/trunk/test/numerics/numeric.ops/adjacent.difference/adjacent_difference_op.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/numeric.ops/adjacent.difference/adjacent_difference_op.pass.cpp?rev=189036&r1=189035&r2=189036&view=diff
==============================================================================
--- libcxx/trunk/test/numerics/numeric.ops/adjacent.difference/adjacent_difference_op.pass.cpp (original)
+++ libcxx/trunk/test/numerics/numeric.ops/adjacent.difference/adjacent_difference_op.pass.cpp Thu Aug 22 13:02:34 2013
@@ -40,6 +40,44 @@ test()
         assert(ib[i] == ir[i]);
 }
 
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+class Y;
+
+class X
+{
+    int i_;
+
+    X& operator=(const X&);
+public:
+    explicit X(int i) : i_(i) {}
+    X(const X& x) : i_(x.i_) {}
+    X& operator=(X&& x)
+    {
+        i_ = x.i_;
+        x.i_ = -1;
+        return *this;
+    }
+
+    friend X operator-(const X& x, const X& y) {return X(x.i_ - y.i_);}
+
+    friend class Y;
+};
+
+class Y
+{
+    int i_;
+
+    Y& operator=(const Y&);
+public:
+    explicit Y(int i) : i_(i) {}
+    Y(const Y& y) : i_(y.i_) {}
+    void operator=(const X& x) {i_ = x.i_;}
+};
+
+#endif
+
+
 int main()
 {
     test<input_iterator<const int*>, output_iterator<int*> >();
@@ -71,4 +109,10 @@ int main()
     test<const int*, bidirectional_iterator<int*> >();
     test<const int*, random_access_iterator<int*> >();
     test<const int*, int*>();
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    X x[3] = {X(1), X(2), X(3)};
+    Y y[3] = {Y(1), Y(2), Y(3)};
+    std::adjacent_difference(x, x+3, y, std::minus<X>());
+#endif
 }





More information about the cfe-commits mailing list