Repository: microsoft/terminal
File: src/inc/til/winrt.h (C/C++)

Code before:
        void operator()(const winrt::event_token& token) { _handlers.remove(token); }
        template<typename... Arg>
        void raise(auto&&... args)
        {
            _handlers(std::forward<decltype(args)>(args)...);
        }
        winrt::event<ArgsT> _handlers;
    };

    template<typename ArgsT>
    struct forwarded_event
    {
        forwarded_event<ArgsT>() = delete;
        forwarded_event<ArgsT>(event<ArgsT>& other) :
            _origin{ other } {}
        forwarded_event<ArgsT>(forwarded_event<ArgsT>& other) :
            _origin{ other._origin } {}

        winrt::event_token operator()(const ArgsT& handler) { return _origin(handler); }
        void operator()(const winrt::event_token& token) { _origin(token); }
        template<typename... Arg>
        void raise(auto&&... args)
        {
            _origin.raise(std::forward<decltype(args)>(args)...);
        }
        event<ArgsT>& _origin;
    };

    template<typename SenderT, typename ArgsT>
    struct typed_event
    {
        typed_event<SenderT, ArgsT>() = default;
        winrt::event_token operator()(const winrt::Windows::Foundation::TypedEventHandler<SenderT, ArgsT>& handler) { return _handlers.add(handler); }
        void operator()(const winrt::event_token& token) { _handlers.remove(token); }
        template<typename... Arg>
        void raise(Arg const&... args)
        {
            _handlers(std::forward<decltype(args)>(args)...);
        }
        winrt::event<winrt::Windows::Foundation::TypedEventHandler<SenderT, ArgsT>> _handlers;
    };
#endif
#ifdef WINRT_Windows_UI_Xaml_DataH

    using property_changed_event = event<winrt::Windows::UI::Xaml::Data::PropertyChangedEventHandler>;

    // This  unfortunately doesn't seem feasible. It's gonna just result in more
    // macros, which no one wants.
    //
    // Explanation can be found in the operator() below.
    /*

Review comment (suggestion):
sorry, is this `til::event` or `winrt::event`?

FWIW: I thought forwarded events were for cross-class or cross-library forwarding, where someone making a `forwarded_event` couldn't actually get at the implementing type's inner details to see their `til::event`

Code after:
        void raise(Arg const&... args)
        {
            _handlers(std::forward<decltype(args)>(args)...);
        }
        winrt::event<winrt::Windows::Foundation::TypedEventHandler<SenderT, ArgsT>> _handlers;
    };
#endif
#ifdef WINRT_Windows_UI_Xaml_DataH

    using property_changed_event = event<winrt::Windows::UI::Xaml::Data::PropertyChangedEventHandler>;

    // Making a til::observable_property unfortunately doesn't seem feasible.
    // It's gonna just result in more macros, which no one wants.
    //
    // 1. We don't know who the sender is, or would require `this` to always be
    //    the first parameter to one of these observable_property's.
    //
    // 2. We don't know what our own name is. We need to actually raise an event
    //    with the name of the variable as the parameter. Only way to do that is
    //    with something  like
    //
    //        til::observable<int> Foo(this, L"Foo", 42)
    //
    //    which then kinda implies the creation of:
    //
    //        #define OBSERVABLE(type, name, ...) til::observable_property<type> name{ this, L## #name, this.PropertyChanged, __VA_ARGS__ };
    //
    //     Which is just silly

#endif
}