Skip to content

Commit 14e413a

Browse files
committed
connection: Take the slot_base directly, without the intermediate slot_iterator.
1 parent e427dee commit 14e413a

File tree

3 files changed

+16
-103
lines changed

3 files changed

+16
-103
lines changed

sigc++/connection.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ connection::connection() noexcept : slot_(nullptr)
2626
{
2727
}
2828

29-
connection::connection(const connection& c) : slot_(c.slot_)
29+
connection::connection(slot_base* slot)
30+
: slot_(slot)
3031
{
31-
// Let the connection forget about the signal handler when the handler object dies:
3232
if (slot_)
3333
slot_->add_destroy_notify_callback(this, &notify);
3434
}
3535

36-
connection::connection(slot_base& sl) : slot_(&sl)
36+
37+
connection::connection(const connection& c) : slot_(c.slot_)
3738
{
3839
// Let the connection forget about the signal handler when the handler object dies:
39-
slot_->add_destroy_notify_callback(this, &notify);
40+
if (slot_)
41+
slot_->add_destroy_notify_callback(this, &notify);
4042
}
4143

4244
connection&

sigc++/connection.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
namespace sigc
2525
{
2626

27-
template <typename T_slot>
28-
struct slot_iterator;
29-
3027
/** Convinience class for safe disconnection.
3128
* Iterators must not be used beyond the lifetime of the list
3229
* they work on. A connection object can be created from a
@@ -54,34 +51,13 @@ struct SIGC_API connection : public notifiable
5451
/** Constructs a connection object from a slot list iterator.
5552
* @param it The slot list iterator to take the slot from.
5653
*/
57-
template <typename T_slot>
58-
connection(const slot_iterator<T_slot>& it) : slot_(&(*it))
59-
{
60-
if (slot_)
61-
slot_->add_destroy_notify_callback(this, &notify);
62-
}
63-
64-
/** Constructs a connection object from a slot object.
65-
* This is only useful if you create your own slot list.
66-
* @param sl The slot to operate on.
67-
*/
68-
explicit connection(slot_base& sl);
54+
explicit connection(slot_base* slot);
6955

7056
/** Overrides this connection object copying another one.
7157
* @param c The connection object to make a copy from.
7258
*/
7359
connection& operator=(const connection& c);
7460

75-
/** Overrides this connection object with another slot list iterator.
76-
* @param it The new slot list iterator to take the slot from.
77-
*/
78-
template <typename T_slot>
79-
connection& operator=(const slot_iterator<T_slot>& it)
80-
{
81-
set_slot(&(*it));
82-
return *this;
83-
}
84-
8561
~connection();
8662

8763
/** Returns whether the connection is still active.

sigc++/signal.h

Lines changed: 9 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -33,66 +33,6 @@
3333
namespace sigc
3434
{
3535

36-
/** STL-style iterator for slot_list.
37-
*
38-
* @ingroup signal
39-
*/
40-
template <typename T_slot>
41-
struct slot_iterator
42-
{
43-
using size_type = std::size_t;
44-
using difference_type = std::ptrdiff_t;
45-
using iterator_category = std::bidirectional_iterator_tag;
46-
47-
using slot_type = T_slot;
48-
49-
using value_type = T_slot;
50-
using pointer = T_slot*;
51-
using reference = T_slot&;
52-
53-
using iterator_type = typename internal::signal_impl::iterator_type;
54-
55-
slot_iterator() = default;
56-
57-
explicit slot_iterator(const iterator_type& i) : i_(i) {}
58-
59-
reference operator*() const { return static_cast<reference>(*i_); }
60-
61-
pointer operator->() const { return &(operator*()); }
62-
63-
slot_iterator& operator++()
64-
{
65-
++i_;
66-
return *this;
67-
}
68-
69-
slot_iterator operator++(int)
70-
{
71-
slot_iterator tmp(*this);
72-
++i_;
73-
return tmp;
74-
}
75-
76-
slot_iterator& operator--()
77-
{
78-
--i_;
79-
return *this;
80-
}
81-
82-
slot_iterator operator--(int)
83-
{
84-
slot_iterator tmp(*this);
85-
--i_;
86-
return tmp;
87-
}
88-
89-
bool operator==(const slot_iterator& other) const { return i_ == other.i_; }
90-
91-
bool operator!=(const slot_iterator& other) const { return i_ != other.i_; }
92-
93-
iterator_type i_;
94-
};
95-
9636
namespace internal
9737
{
9838

@@ -471,21 +411,12 @@ class signal_with_accumulator : public signal_base
471411
public:
472412
using slot_type = slot<T_return(T_arg...)>;
473413

474-
private:
475-
using iterator = slot_iterator<slot_type>;
476-
477-
public:
478-
479-
480414
/** Add a slot to the list of slots.
481415
* Any functor or slot may be passed into connect().
482416
* It will be converted into a slot implicitly.
483-
* The returned iterator may be stored for disconnection
417+
* The returned connection may be stored for disconnection
484418
* of the slot at some later point. It stays valid until
485-
* the slot is removed from the list of slots. The iterator
486-
* can also be implicitly converted into a sigc::connection object
487-
* that may be used safely beyond the life time of the slot.
488-
*
419+
* the slot is disconnected from the signal.
489420
* std::function<> and C++11 lambda expressions are functors.
490421
* These are examples of functors that can be connected to a signal.
491422
*
@@ -496,11 +427,13 @@ class signal_with_accumulator : public signal_base
496427
* to a std::function, you can connect the std::function to a signal.
497428
*
498429
* @param slot_ The slot to add to the list of slots.
499-
* @return An iterator pointing to the new slot in the list.
430+
* @return A connection.
500431
*/
501432
connection connect(const slot_type& slot_)
502433
{
503-
return connection(iterator(signal_base::connect(slot_)));
434+
auto iter = signal_base::connect(slot_);
435+
auto& slot_base = *iter;
436+
return connection(&slot_base);
504437
}
505438

506439
/** Add a slot to the list of slots.
@@ -510,7 +443,9 @@ class signal_with_accumulator : public signal_base
510443
*/
511444
connection connect(slot_type&& slot_)
512445
{
513-
return connection(iterator(signal_base::connect(std::move(slot_))));
446+
auto iter = signal_base::connect(std::move(slot_));
447+
auto& slot_base = *iter;
448+
return connection(&slot_base);
514449
}
515450

516451
/** Triggers the emission of the signal.

0 commit comments

Comments
 (0)