LeviLamina
Loading...
Searching...
No Matches
Dispatcher.h
1#pragma once
2
3#include <concepts>
4
5namespace ll::reflection {
6template <class Storage, std::default_initializable Listener, bool CallInit = false>
7class Dispatcher {
8public:
9 using storage_type = Storage;
10 using listener_type = Listener;
11
12 Storage storage;
13 Listener listener;
14
15 void call() { listener.call(storage); }
16
17 template <class... Args>
18 Dispatcher(Args&&... args) : storage(std::forward<Args>(args)...),
19 listener() {
20 if constexpr (CallInit) {
21 call();
22 }
23 }
24 Dispatcher& operator=(Storage const& other) {
25 storage = other;
26 call();
27 return *this;
28 }
29 Dispatcher& operator=(Storage&& other) {
30 storage = std::move(other);
31 call();
32 return *this;
33 }
34
35 operator Storage const&() const { return storage; }
36
37 operator Storage&() { return storage; }
38};
39} // namespace ll::reflection
Definition Dispatcher.h:7