Преглед на файлове

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

Michele Caini преди 5 години
родител
ревизия
7db0f540bd
променени са 2 файла, в които са добавени 6 реда и са изтрити 2 реда
  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
 ```cpp
 // emits all the events of the given type at once
 // 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
 // emits all the events queued so far at once
 dispatcher.update();
 dispatcher.update();

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

@@ -66,7 +66,11 @@ class dispatcher {
 
 
         template<typename... Args>
         template<typename... Args>
         void enqueue(Args &&... 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 {
         id_type type_id() const ENTT_NOEXCEPT override {