diff options
author | crupest <crupest@outlook.com> | 2024-01-01 22:20:21 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2024-01-18 21:12:28 +0800 |
commit | df799bf394fa63dc9f39a5b09fe21c16b1cc8a57 (patch) | |
tree | c9efa5b7a53545e2e1b7a9dff765817208911a7a /include/cru | |
parent | f79fc16b29a32c21461490a6482eada7baa9d7f8 (diff) | |
download | cru-df799bf394fa63dc9f39a5b09fe21c16b1cc8a57.tar.gz cru-df799bf394fa63dc9f39a5b09fe21c16b1cc8a57.tar.bz2 cru-df799bf394fa63dc9f39a5b09fe21c16b1cc8a57.zip |
NEED TEST: fix compile errors of Event2 and create init test.
Diffstat (limited to 'include/cru')
-rw-r--r-- | include/cru/common/Event2.h | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/include/cru/common/Event2.h b/include/cru/common/Event2.h index 5c3a330a..7d7bda82 100644 --- a/include/cru/common/Event2.h +++ b/include/cru/common/Event2.h @@ -51,7 +51,8 @@ class EventHandlerToken { static_assert(is_event2_v<TEvent2>, "TEvent2 must be Event2 class."); public: - EventHandlerToken(ObjectResolver<TEvent2> event_resolver, int token_value); + EventHandlerToken(ObjectResolver<TEvent2> event_resolver, int token_value) + : event_resolver_(std::move(event_resolver)), token_value_(token_value) {} ObjectResolver<TEvent2> GetEventResolver() const { return event_resolver_; } int GetTokenValue() const { return token_value_; } @@ -82,17 +83,17 @@ class Event2 : public SelfResolvable<Event2<TArgument, TResult>> { public: using HandlerToken = EventHandlerToken<Event2>; using Context = EventContext<TArgument, TResult>; - using Handler = std::function<void(Context&)>; + using Handler = std::function<void(Context*)>; using SpyOnlyHandler = std::function<void()>; template <typename TFunc> static std::enable_if_t<std::invocable<TFunc>, Handler> WrapAsHandler( TFunc&& handler) { - return Handler([h = std::forward<TFunc>(handler)](Context&) { h(); }); + return Handler([h = std::forward<TFunc>(handler)](Context*) { h(); }); } template <typename TFunc> - static std::enable_if_t<std::invocable<TFunc, Context&>, Handler> + static std::enable_if_t<std::invocable<TFunc, Context*>, Handler> WrapAsHandler(TFunc&& handler) { return Handler(std::forward<TFunc>(handler)); } @@ -138,19 +139,19 @@ class Event2 : public SelfResolvable<Event2<TArgument, TResult>> { TResult Raise() { Context context; - RunInContext(context); + RunInContext(&context); return context.TakeResult(); } TResult Raise(TArgument argument) { Context context(std::move(argument)); - RunInContext(context); + RunInContext(&context); return context.TakeResult(); } TResult Raise(TArgument argument, TResult result) { Context context(std::move(argument), std::move(result)); - RunInContext(context); + RunInContext(&context); return context.TakeResult(); } |