Skip to content

Commit 3113259

Browse files
author
Kjell Ahlstedt
committed
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.
1 parent d31a907 commit 3113259

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

sigc++/macros/signal.h.m4

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,14 @@ public:
341341
iterator connect(const slot_type& slot_)
342342
{ return iterator(signal_base::connect(static_cast<const slot_base&>(slot_))); }
343343
344+
/** Add a slot to the list of slots.
345+
* @see connect(const slot_type& slot_).
346+
*
347+
* @newin{2,8}
348+
*/
349+
iterator connect(slot_type&& slot_)
350+
{ return iterator(signal_base::connect(std::move(static_cast<slot_base&>(slot_)))); }
351+
344352
/** Triggers the emission of the signal.
345353
* During signal emission all slots that have been connected
346354
* to the signal are invoked unless they are manually set into
@@ -780,12 +788,21 @@ struct slot_list
780788
iterator insert(iterator i, const slot_type& slot_)
781789
{ return iterator(list_->insert(i.i_, static_cast<const slot_base&>(slot_))); }
782790

791+
iterator insert(iterator i, slot_type&& slot_)
792+
{ return iterator(list_->insert(i.i_, std::move(static_cast<slot_base&>(slot_)))); }
793+
783794
void push_front(const slot_type& c)
784795
{ insert(begin(), c); }
785796

797+
void push_front(slot_type&& c)
798+
{ insert(begin(), std::move(c)); }
799+
786800
void push_back(const slot_type& c)
787801
{ insert(end(), c); }
788802

803+
void push_back(slot_type&& c)
804+
{ insert(end(), std::move(c)); }
805+
789806
iterator erase(iterator i)
790807
{ return iterator(list_->erase(i.i_)); }
791808

sigc++/signal_base.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ signal_impl::iterator_type signal_impl::connect(const slot_base& slot_)
9595
return insert(slots_.end(), slot_);
9696
}
9797

98+
signal_impl::iterator_type signal_impl::connect(slot_base&& slot_)
99+
{
100+
return insert(slots_.end(), std::move(slot_));
101+
}
102+
98103
signal_impl::iterator_type signal_impl::erase(iterator_type i)
99104
{
100105
// 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
119124
return temp;
120125
}
121126

127+
signal_impl::iterator_type signal_impl::insert(signal_impl::iterator_type i, slot_base&& slot_)
128+
{
129+
auto temp = slots_.insert(i, std::move(slot_));
130+
auto si = new self_and_iter(this, temp);
131+
temp->set_parent(si, &notify);
132+
return temp;
133+
}
134+
122135
void signal_impl::sweep()
123136
{
124137
// 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_)
220233
return impl()->connect(slot_);
221234
}
222235

236+
signal_base::iterator_type signal_base::connect(slot_base&& slot_)
237+
{
238+
return impl()->connect(std::move(slot_));
239+
}
240+
223241
signal_base::iterator_type signal_base::insert(iterator_type i, const slot_base& slot_)
224242
{
225243
return impl()->insert(i, slot_);
226244
}
227245

246+
signal_base::iterator_type signal_base::insert(iterator_type i, slot_base&& slot_)
247+
{
248+
return impl()->insert(i, std::move(slot_));
249+
}
250+
228251
signal_base::iterator_type signal_base::erase(iterator_type i)
229252
{
230253
return impl()->erase(i);

sigc++/signal_base.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,30 @@ struct SIGC_API signal_impl
126126
*/
127127
iterator_type connect(const slot_base& slot_);
128128

129+
/** Adds a slot at the bottom of the list of slots.
130+
* @param slot_ The slot to add to the list of slots.
131+
* @return An iterator pointing to the new slot in the list.
132+
*
133+
* @newin{2,8}
134+
*/
135+
iterator_type connect(slot_base&& slot_);
136+
129137
/** Adds a slot at the given position into the list of slots.
130138
* @param i An iterator indicating the position where @p slot_ should be inserted.
131139
* @param slot_ The slot to add to the list of slots.
132140
* @return An iterator pointing to the new slot in the list.
133141
*/
134142
iterator_type insert(iterator_type i, const slot_base& slot_);
135143

144+
/** Adds a slot at the given position into the list of slots.
145+
* @param i An iterator indicating the position where @p slot_ should be inserted.
146+
* @param slot_ The slot to add to the list of slots.
147+
* @return An iterator pointing to the new slot in the list.
148+
*
149+
* @newin{2,8}
150+
*/
151+
iterator_type insert(iterator_type i, slot_base&& slot_);
152+
136153
/** Removes the slot at the given position from the list of slots.
137154
* @param i An iterator pointing to the slot to be removed.
138155
* @return An iterator pointing to the slot in the list after the one removed.
@@ -349,6 +366,16 @@ struct SIGC_API signal_base : public trackable
349366
*/
350367
iterator_type connect(const slot_base& slot_);
351368

369+
/** Adds a slot at the end of the list of slots.
370+
* With connect(), slots can also be added during signal emission.
371+
* In this case, they won't be executed until the next emission occurs.
372+
* @param slot_ The slot to add to the list of slots.
373+
* @return An iterator pointing to the new slot in the list.
374+
*
375+
* @newin{2,8}
376+
*/
377+
iterator_type connect(slot_base&& slot_);
378+
352379
/** Adds a slot at the given position into the list of slots.
353380
* Note that this function does not work during signal emission!
354381
* @param i An iterator indicating the position where @e slot_ should be inserted.
@@ -357,6 +384,16 @@ struct SIGC_API signal_base : public trackable
357384
*/
358385
iterator_type insert(iterator_type i, const slot_base& slot_);
359386

387+
/** Adds a slot at the given position into the list of slots.
388+
* Note that this function does not work during signal emission!
389+
* @param i An iterator indicating the position where @e slot_ should be inserted.
390+
* @param slot_ The slot to add to the list of slots.
391+
* @return An iterator pointing to the new slot in the list.
392+
*
393+
* @newin{2,8}
394+
*/
395+
iterator_type insert(iterator_type i, slot_base&& slot_);
396+
360397
/** Removes the slot at the given position from the list of slots.
361398
* Note that this function does not work during signal emission!
362399
* @param i An iterator pointing to the slot to be removed.

0 commit comments

Comments
 (0)