[libsigc++2] slot and signal: Add missing move constructors and move assignments



commit 18a9f6dce1793ca1f0c3f30add5308b870e92497
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Sun Nov 8 10:04:31 2015 +0100

    slot and signal: Add missing move constructors and move assignments
    
    * sigc++/functors/macros/slot.h.m4: Add move operators for slot<>.
    * sigc++/macros/signal.h.m4: Add move operators for signal#<> and signal<>.
    * tests/test_signal_move.cc:
    * tests/test_slot_move.cc: Test that the source objects are empty.
    Bug #756484.

 sigc++/functors/macros/slot.h.m4 |   34 ++++++++++++++++++++++++++++++++--
 sigc++/macros/signal.h.m4        |   31 +++++++++++++++++++++++++++++++
 tests/test_signal_move.cc        |    4 ++--
 tests/test_slot_move.cc          |    4 ++--
 4 files changed, 67 insertions(+), 6 deletions(-)
---
diff --git a/sigc++/functors/macros/slot.h.m4 b/sigc++/functors/macros/slot.h.m4
index 4e9b00f..683841d 100644
--- a/sigc++/functors/macros/slot.h.m4
+++ b/sigc++/functors/macros/slot.h.m4
@@ -215,13 +215,43 @@ public:
   slot(const T_functor& _A_func)
     : parent_type(_A_func) {}
 
-  // Without reinterpret_cast (or static_cast) parent_type(const T_functor& _A_func)
+  // Without static_cast parent_type(const T_functor& _A_func)
   // is called instead of the copy constructor.
   /** Constructs a slot, copying an existing one.
    * @param src The existing slot to copy.
    */
   slot(const slot& src)
-    : parent_type(reinterpret_cast<const parent_type&>(src)) {}
+    : parent_type(static_cast<const parent_type&>(src)) {}
+
+  // Without static_cast parent_type(const T_functor& _A_func)
+  // is called instead of the move constructor.
+  /** Constructs a slot, moving an existing one.
+   * If @p src is connected to a parent (e.g. a signal), it is copied, not moved.
+   * @param src The existing slot to move or copy.
+   */
+  slot(slot&& src)
+    : parent_type(std::move(static_cast<parent_type&>(src))) {}
+
+  /** Overrides this slot, making a copy from another slot.
+   * @param src The slot from which to make a copy.
+   * @return @p this.
+   */
+  slot& operator=(const slot& src)
+  {
+    parent_type::operator=(src);
+    return *this;
+  }
+
+  /** Overrides this slot, making a move from another slot.
+   * If @p src is connected to a parent (e.g. a signal), it is copied, not moved.
+   * @param src The slot from which to move or copy.
+   * @return @p this.
+   */
+  slot& operator=(slot&& src)
+  {
+    parent_type::operator=(std::move(src));
+    return *this;
+  }
 };
 
 ifelse($1, $2,[dnl
diff --git a/sigc++/macros/signal.h.m4 b/sigc++/macros/signal.h.m4
index ac1e19e..500813d 100644
--- a/sigc++/macros/signal.h.m4
+++ b/sigc++/macros/signal.h.m4
@@ -391,6 +391,21 @@ FOR(1, $1,[
 
   signal$1(const signal$1& src)
     : signal_base(src) {}
+
+  signal$1(signal$1&& src)
+    : signal_base(std::move(src)) {}
+
+  signal$1& operator=(const signal$1& src)
+  {
+    signal_base::operator=(src);
+    return *this;
+  }
+
+  signal$1& operator=(signal$1&& src)
+  {
+    signal_base::operator=(std::move(src));
+    return *this;
+  }
 };
 
 ])
@@ -512,8 +527,24 @@ ifelse($1, $2,[dnl
   };
 
   signal() {}
+
   signal(const signal& src)
     : signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>(src) {}
+
+  signal(signal&& src)
+    : signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>(std::move(src)) {}
+
+  signal& operator=(const signal& src)
+  {
+    signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>::operator=(src);
+    return *this;
+  }
+
+  signal& operator=(signal&& src)
+  {
+    signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>::operator=(std::move(src));
+    return *this;
+  }
 };
 
 ])
diff --git a/tests/test_signal_move.cc b/tests/test_signal_move.cc
index 73a7ed2..6365e5b 100644
--- a/tests/test_signal_move.cc
+++ b/tests/test_signal_move.cc
@@ -37,14 +37,14 @@ int main(int argc, char* argv[])
 
   //Test the move constructor:
   sigc::signal<int, int> sig2(std::move(sig));
-  //sig(-2); Add when more move constructors have been added
+  sig(-2);
   sig2(2);
   util->check_result(result_stream, "foo(int 2)");
 
   //Test the move assignment operator:
   sigc::signal<int, int> sig3;
   sig3 = std::move(sig2);
-  //sig2(-3); Add when more move assignment operators have been added
+  sig2(-3);
   sig3(3);
   util->check_result(result_stream, "foo(int 3)");
 
diff --git a/tests/test_slot_move.cc b/tests/test_slot_move.cc
index df36d0b..c479da1 100644
--- a/tests/test_slot_move.cc
+++ b/tests/test_slot_move.cc
@@ -53,14 +53,14 @@ int main(int argc, char* argv[])
 
   // test move constructor:
   sigc::slot<void,int> s2(std::move(s1));
-  //s1(-2); Add when more move constructors have been added
+  s1(-2);
   s2(2);
   util->check_result(result_stream, "foo(int 2)");
 
   // test move assignment:
   sigc::slot<void,int> s3;
   s3 = std::move(s2);
-  //s2(-3); Add when more move assignment operators have been added
+  s2(-3);
   s3(3);
   util->check_result(result_stream, "foo(int 3)");
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]