[libsigc++2] Add a moving signal::connect() overload



commit 31132598511b2bfaa6671acbf6c2ed5a5eb151c6
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Mon Nov 16 15:31:06 2015 +0100

    Add a moving signal::connect() overload
    
    * sigc++/macros/signal.h.m4: Add signal#::connect(slot_type&&),
    slot_list::insert(iterator i, slot_type&&),
    slot_list::push_front(slot_type&&), push_back(slot_type&&).
    * sigc++/signal_base.[h|cc]: Add signal_base::connect(slot_base&&),
    signal_base::insert(slot_base&&), signal_impl::connect(slot_base&&),
    signal_impl::insert(slot_base&&). Bug #756484.

 sigc++/macros/signal.h.m4 |   17 +++++++++++++++++
 sigc++/signal_base.cc     |   23 +++++++++++++++++++++++
 sigc++/signal_base.h      |   37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 0 deletions(-)
---
diff --git a/sigc++/macros/signal.h.m4 b/sigc++/macros/signal.h.m4
index 500813d..cf3add5 100644
--- a/sigc++/macros/signal.h.m4
+++ b/sigc++/macros/signal.h.m4
@@ -341,6 +341,14 @@ public:
   iterator connect(const slot_type& slot_)
     { return iterator(signal_base::connect(static_cast<const slot_base&>(slot_))); }
 
+  /** Add a slot to the list of slots.
+   * @see connect(const slot_type& slot_).
+   *
+   * @newin{2,8}
+   */
+  iterator connect(slot_type&& slot_)
+    { return iterator(signal_base::connect(std::move(static_cast<slot_base&>(slot_)))); }
+
   /** Triggers the emission of the signal.
    * During signal emission all slots that have been connected
    * to the signal are invoked unless they are manually set into
@@ -780,12 +788,21 @@ struct slot_list
   iterator insert(iterator i, const slot_type& slot_)
     { return iterator(list_->insert(i.i_, static_cast<const slot_base&>(slot_))); }
 
+  iterator insert(iterator i, slot_type&& slot_)
+    { return iterator(list_->insert(i.i_, std::move(static_cast<slot_base&>(slot_)))); }
+
   void push_front(const slot_type& c)
     { insert(begin(), c); }
 
+  void push_front(slot_type&& c)
+    { insert(begin(), std::move(c)); }
+
   void push_back(const slot_type& c)
     { insert(end(), c); }
 
+  void push_back(slot_type&& c)
+    { insert(end(), std::move(c)); }
+
   iterator erase(iterator i)
     { return iterator(list_->erase(i.i_)); }
 
diff --git a/sigc++/signal_base.cc b/sigc++/signal_base.cc
index 5ecadff..cc8342b 100644
--- a/sigc++/signal_base.cc
+++ b/sigc++/signal_base.cc
@@ -95,6 +95,11 @@ signal_impl::iterator_type signal_impl::connect(const slot_base& slot_)
   return insert(slots_.end(), slot_);
 }
 
+signal_impl::iterator_type signal_impl::connect(slot_base&& slot_)
+{
+  return insert(slots_.end(), std::move(slot_));
+}
+
 signal_impl::iterator_type signal_impl::erase(iterator_type i)
 {
   // Don't let signal_impl::notify() erase the slot. It would be more
@@ -119,6 +124,14 @@ signal_impl::iterator_type signal_impl::insert(signal_impl::iterator_type i, con
   return temp;
 }
 
+signal_impl::iterator_type signal_impl::insert(signal_impl::iterator_type i, slot_base&& slot_)
+{
+  auto temp = slots_.insert(i, std::move(slot_));
+  auto si = new self_and_iter(this, temp);
+  temp->set_parent(si, &notify);
+  return temp;
+}
+
 void signal_impl::sweep()
 {
   // The deletion of a slot may cause the deletion of a signal_base,
@@ -220,11 +233,21 @@ signal_base::iterator_type signal_base::connect(const slot_base& slot_)
   return impl()->connect(slot_);
 }
 
+signal_base::iterator_type signal_base::connect(slot_base&& slot_)
+{
+  return impl()->connect(std::move(slot_));
+}
+
 signal_base::iterator_type signal_base::insert(iterator_type i, const slot_base& slot_)
 {
   return impl()->insert(i, slot_);
 }
 
+signal_base::iterator_type signal_base::insert(iterator_type i, slot_base&& slot_)
+{
+  return impl()->insert(i, std::move(slot_));
+}
+
 signal_base::iterator_type signal_base::erase(iterator_type i)
 {
   return impl()->erase(i);
diff --git a/sigc++/signal_base.h b/sigc++/signal_base.h
index 622135f..f50a6cb 100644
--- a/sigc++/signal_base.h
+++ b/sigc++/signal_base.h
@@ -126,6 +126,14 @@ struct SIGC_API signal_impl
    */
   iterator_type connect(const slot_base& slot_);
 
+  /** Adds a slot at the bottom of the list of slots.
+   * @param slot_ The slot to add to the list of slots.
+   * @return An iterator pointing to the new slot in the list.
+   *
+   * @newin{2,8}
+   */
+  iterator_type connect(slot_base&& slot_);
+
   /** Adds a slot at the given position into the list of slots.
    * @param i An iterator indicating the position where @p slot_ should be inserted.
    * @param slot_ The slot to add to the list of slots.
@@ -133,6 +141,15 @@ struct SIGC_API signal_impl
    */
   iterator_type insert(iterator_type i, const slot_base& slot_);
 
+  /** Adds a slot at the given position into the list of slots.
+   * @param i An iterator indicating the position where @p slot_ should be inserted.
+   * @param slot_ The slot to add to the list of slots.
+   * @return An iterator pointing to the new slot in the list.
+   *
+   * @newin{2,8}
+   */
+  iterator_type insert(iterator_type i, slot_base&& slot_);
+
   /** Removes the slot at the given position from the list of slots.
    * @param i An iterator pointing to the slot to be removed.
    * @return An iterator pointing to the slot in the list after the one removed.
@@ -349,6 +366,16 @@ protected:
    */
   iterator_type connect(const slot_base& slot_);
 
+  /** Adds a slot at the end of the list of slots.
+   * With connect(), slots can also be added during signal emission.
+   * In this case, they won't be executed until the next emission occurs.
+   * @param slot_ The slot to add to the list of slots.
+   * @return An iterator pointing to the new slot in the list.
+   *
+   * @newin{2,8}
+   */
+  iterator_type connect(slot_base&& slot_);
+
   /** Adds a slot at the given position into the list of slots.
    * Note that this function does not work during signal emission!
    * @param i An iterator indicating the position where @e slot_ should be inserted.
@@ -357,6 +384,16 @@ protected:
    */
   iterator_type insert(iterator_type i, const slot_base& slot_);
 
+  /** Adds a slot at the given position into the list of slots.
+   * Note that this function does not work during signal emission!
+   * @param i An iterator indicating the position where @e slot_ should be inserted.
+   * @param slot_ The slot to add to the list of slots.
+   * @return An iterator pointing to the new slot in the list.
+   *
+   * @newin{2,8}
+   */
+  iterator_type insert(iterator_type i, slot_base&& slot_);
+
   /** Removes the slot at the given position from the list of slots.
    * Note that this function does not work during signal emission!
    * @param i An iterator pointing to the slot to be removed.


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