From 88541918845136dea9131ba99138dd33830e0e69 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sun, 7 Jan 2024 16:55:08 +0100 Subject: [PATCH] Make listener<>::instances inline This simplifies the user interface and removes a clang warning about it being potentially uninitialized. See #2139. --- client/chatline.cpp | 1 - client/listener.h | 17 +---------------- client/map_updates_handler.cpp | 2 -- 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/client/chatline.cpp b/client/chatline.cpp index 59a6531c6b..5a4a47ae1f 100644 --- a/client/chatline.cpp +++ b/client/chatline.cpp @@ -47,7 +47,6 @@ static bool is_plain_public_message(const QString &s); -FC_CPP_DECLARE_LISTENER(chat_listener) QStringList chat_listener::history = QStringList(); namespace { diff --git a/client/listener.h b/client/listener.h index a801003185..a4dab190e8 100644 --- a/client/listener.h +++ b/client/listener.h @@ -27,13 +27,6 @@ }; ~~~~~ - The listener needs some static data. Declaring it is as simple as putting - a macro in some source file: - - ~~~~~{.cpp} - FC_CPP_DECLARE_LISTENER(foo_listener) - ~~~~~ - Then, you call the listeners from the implementation of the C interface: ~~~~~{.cpp} @@ -104,7 +97,7 @@ template class listener { private: // All instances of type_t that have called listen(). - static std::set *> instances; + inline static std::set *> instances{}; protected: explicit listener(); @@ -117,14 +110,6 @@ template class listener { static void invoke(_member_fct_ function, _args_ &&...args); }; -/*************************************************************************** - Macro to declare the static data needed by listener<> classes -***************************************************************************/ -#define FC_CPP_DECLARE_LISTENER(_type_) \ - template <> \ - std::set *> listener<_type_>::instances = \ - std::set *>(); - /*************************************************************************** Constructor ***************************************************************************/ diff --git a/client/map_updates_handler.cpp b/client/map_updates_handler.cpp index 81969cb92d..58d154b0ce 100644 --- a/client/map_updates_handler.cpp +++ b/client/map_updates_handler.cpp @@ -9,8 +9,6 @@ #include "options.h" #include "tileset/tilespec.h" -FC_CPP_DECLARE_LISTENER(freeciv::map_updates_handler) - namespace freeciv { /**