Skip to content

Commit

Permalink
Disconnect with no slot will disconnect all
Browse files Browse the repository at this point in the history
  • Loading branch information
netromdk committed Aug 22, 2020
1 parent e6f32ce commit 340ccf9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sigs.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ class Signal<Ret(Args...)> final {
eraseEntries();
}

void disconnect(std::optional<Connection> conn) noexcept
/// Disconnects \p conn from signal.
/** If no value is given, all slots are disconnected. */
void disconnect(std::optional<Connection> conn = std::nullopt) noexcept
{
if (!conn) {
clear();
Expand Down
9 changes: 9 additions & 0 deletions tests/General.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,12 @@ TEST(General, empty)
s.clear();
ASSERT_TRUE(s.empty());
}

TEST(General, disconnectWithNoSlotClearsAll)
{
sigs::Signal<void()> s;
s.connect([] {});
s.connect([] {});
s.disconnect();
ASSERT_TRUE(s.empty());
}

0 comments on commit 340ccf9

Please sign in to comment.