From aefacd6a122abdc5312cb7b2f573e5ac70a615a4 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Wed, 17 Dec 2025 17:57:04 +0100 Subject: [PATCH] Clean up til::event (#19654) Dedupe the two structs by using a type alias. Also cleans up the implicit bool operator, template args, etc. --- src/inc/til/winrt.h | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/inc/til/winrt.h b/src/inc/til/winrt.h index 101d558f7f..c2917286f0 100644 --- a/src/inc/til/winrt.h +++ b/src/inc/til/winrt.h @@ -60,32 +60,22 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" template struct event { - event() = default; + explicit operator bool() const noexcept { return static_cast(_handlers); } winrt::event_token operator()(const ArgsT& handler) { return _handlers.add(handler); } - void operator()(const winrt::event_token& token) { _handlers.remove(token); } - operator bool() const noexcept { return bool(_handlers); } - template + void operator()(winrt::event_token token) { _handlers.remove(token); } + void raise(auto&&... args) { _handlers(std::forward(args)...); } + + private: winrt::event _handlers; }; template - struct typed_event - { - typed_event() = default; - winrt::event_token operator()(const winrt::Windows::Foundation::TypedEventHandler& handler) { return _handlers.add(handler); } - void operator()(const winrt::event_token& token) { _handlers.remove(token); } - operator bool() const noexcept { return bool(_handlers); } - template - void raise(Arg const&... args) - { - _handlers(std::forward(args)...); - } - winrt::event> _handlers; - }; + using typed_event = til::event>; + #endif #ifdef WINRT_Windows_UI_Xaml_Data_H