Skip to content

registerEventHandler: lambda deduction fails without explicit template parameter #1

Open

Description

@bert-laverman

Problem

EventHandler::registerEventHandler takes std::function<void(const EventType&)>, which blocks template argument deduction when the caller passes a lambda. Every call site must spell out the explicit type:

evtHandler.registerEventHandler<Messages::EventMsg>(evtKeyA, [&](const Messages::EventMsg&) { ... });

Without the explicit <Messages::EventMsg> the compiler cannot deduce EventType from a lambda (a lambda is not a std::function), and the call fails to compile.

Suggested fix

Add an unconstrained forwarding overload that deduces the handler argument type and extracts EventType via std::invoke_result or a traits helper:

template <typename F>
EventHandler& registerEventHandler(EventId id, F&& handler, bool autoRemove = false);

This lets call sites drop the explicit template argument entirely:

evtHandler.registerEventHandler(evtKeyA, [&](const Messages::EventMsg&) { ... });

The same issue likely affects any other method that takes std::function<void(const SomeMsg&)> as a deducible template parameter.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions