Browse Source

dispatcher: enqueue works fine with aggregates now (close #491)

Michele Caini 5 years ago
parent
commit
7db0f540bd
2 changed files with 6 additions and 2 deletions
  1. 1 1
      docs/md/signal.md
  2. 5 1
      src/entt/signal/dispatcher.hpp

+ 1 - 1
docs/md/signal.md

@@ -372,7 +372,7 @@ the messages that are still pending are sent to the listeners at once:
 
 ```cpp
 // emits all the events of the given type at once
-dispatcher.update<my_event>();
+dispatcher.update<an_event>();
 
 // emits all the events queued so far at once
 dispatcher.update();

+ 5 - 1
src/entt/signal/dispatcher.hpp

@@ -66,7 +66,11 @@ class dispatcher {
 
         template<typename... Args>
         void enqueue(Args &&... args) {
-            events.emplace_back(std::forward<Args>(args)...);
+            if constexpr(std::is_aggregate_v<Event>) {
+                events.push_back(Event{std::forward<Args>(args)...});
+            } else {
+                events.emplace_back(std::forward<Args>(args)...);
+            }
         }
 
         id_type type_id() const ENTT_NOEXCEPT override {