Skip to content

Commit aefacd6

Browse files
authored
Clean up til::event (#19654)
Dedupe the two structs by using a type alias. Also cleans up the implicit bool operator, template args, etc.
1 parent 2f8c51e commit aefacd6

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/inc/til/winrt.h

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,32 +60,22 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
6060
template<typename ArgsT>
6161
struct event
6262
{
63-
event<ArgsT>() = default;
63+
explicit operator bool() const noexcept { return static_cast<bool>(_handlers); }
6464
winrt::event_token operator()(const ArgsT& handler) { return _handlers.add(handler); }
65-
void operator()(const winrt::event_token& token) { _handlers.remove(token); }
66-
operator bool() const noexcept { return bool(_handlers); }
67-
template<typename... Arg>
65+
void operator()(winrt::event_token token) { _handlers.remove(token); }
66+
6867
void raise(auto&&... args)
6968
{
7069
_handlers(std::forward<decltype(args)>(args)...);
7170
}
71+
72+
private:
7273
winrt::event<ArgsT> _handlers;
7374
};
7475

7576
template<typename SenderT = winrt::Windows::Foundation::IInspectable, typename ArgsT = winrt::Windows::Foundation::IInspectable>
76-
struct typed_event
77-
{
78-
typed_event<SenderT, ArgsT>() = default;
79-
winrt::event_token operator()(const winrt::Windows::Foundation::TypedEventHandler<SenderT, ArgsT>& handler) { return _handlers.add(handler); }
80-
void operator()(const winrt::event_token& token) { _handlers.remove(token); }
81-
operator bool() const noexcept { return bool(_handlers); }
82-
template<typename... Arg>
83-
void raise(Arg const&... args)
84-
{
85-
_handlers(std::forward<decltype(args)>(args)...);
86-
}
87-
winrt::event<winrt::Windows::Foundation::TypedEventHandler<SenderT, ArgsT>> _handlers;
88-
};
77+
using typed_event = til::event<winrt::Windows::Foundation::TypedEventHandler<SenderT, ArgsT>>;
78+
8979
#endif
9080
#ifdef WINRT_Windows_UI_Xaml_Data_H
9181

0 commit comments

Comments
 (0)