From 340ccf9fc428fa8c2cadef1c44951b5da75172a5 Mon Sep 17 00:00:00 2001 From: Morten Kristensen Date: Sat, 22 Aug 2020 13:14:56 +0200 Subject: [PATCH] Disconnect with no slot will disconnect all --- sigs.h | 4 +++- tests/General.cc | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/sigs.h b/sigs.h index e01b518..bab3a08 100644 --- a/sigs.h +++ b/sigs.h @@ -295,7 +295,9 @@ class Signal final { eraseEntries(); } - void disconnect(std::optional conn) noexcept + /// Disconnects \p conn from signal. + /** If no value is given, all slots are disconnected. */ + void disconnect(std::optional conn = std::nullopt) noexcept { if (!conn) { clear(); diff --git a/tests/General.cc b/tests/General.cc index 7063ee2..82e0069 100644 --- a/tests/General.cc +++ b/tests/General.cc @@ -277,3 +277,12 @@ TEST(General, empty) s.clear(); ASSERT_TRUE(s.empty()); } + +TEST(General, disconnectWithNoSlotClearsAll) +{ + sigs::Signal s; + s.connect([] {}); + s.connect([] {}); + s.disconnect(); + ASSERT_TRUE(s.empty()); +}