From 6caa48d8012ad924d67105d7d771ed37e06d6205 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Sun, 7 Apr 2024 02:47:36 +0000 Subject: [PATCH] feat add dispatcher to sled.h --- src/sled/experimental/design_patterns/dispatcher.h | 4 +++- src/sled/sled.h | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sled/experimental/design_patterns/dispatcher.h b/src/sled/experimental/design_patterns/dispatcher.h index 53871df..46d9f78 100644 --- a/src/sled/experimental/design_patterns/dispatcher.h +++ b/src/sled/experimental/design_patterns/dispatcher.h @@ -4,6 +4,7 @@ #include "sled/synchronization/mutex.h" #include #include +#include namespace sled { namespace experimental { @@ -11,12 +12,13 @@ namespace experimental { template class Dispatcher { public: + static_assert(!std::is_rvalue_reference::value, "must be a value type"); enum class DispatchResult { kHandled, kNotFound }; struct Handler { virtual ~Handler() = default; virtual bool HandleMessage(const T &) = 0; - virtual bool OnMessage(T &&) = 0; + virtual bool OnMessage(const T &) = 0; }; virtual ~Dispatcher() = default; diff --git a/src/sled/sled.h b/src/sled/sled.h index 515a236..1ba8602 100644 --- a/src/sled/sled.h +++ b/src/sled/sled.h @@ -9,6 +9,9 @@ namespace async {} #include "inja.hpp" #include "rx.h" +// experimental +#include "sled/experimental/design_patterns/dispatcher.h" + // event_bus #include "sled/event_bus/event_bus.h"