Skip to content

Add explicit MessageT Subscribe and CreateSubscriber template overloads for callbacks - #912

Open
azeey wants to merge 2 commits into
gazebosim:mainfrom
azeey:fix/subscribe_explicit_message_type
Open

Add explicit MessageT Subscribe and CreateSubscriber template overloads for callbacks#912
azeey wants to merge 2 commits into
gazebosim:mainfrom
azeey:fix/subscribe_explicit_message_type

Conversation

@azeey

@azeey azeey commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

🦟 Bug fix

Fixes #880

Summary

Currently, Node::Subscribe and Node::CreateSubscriber deduce the message type from the provided callback. However, this causes compilation ambiguities when using callbacks that require explicit template arguments (such as lambda functions).

This PR introduces new template overloads for Node::Subscribe and Node::CreateSubscriber that allow users to explicitly specify the MessageT template parameter. This completely eliminates ambiguities for capturing lambdas.

Example usage:

node.Subscribe<msgs::Int32>(topic, [&](const msgs::Int32 &_msg)
{
  // do something
});

Note: As documented in the headers, using non-capturing lambdas with explicit template arguments still results in an ambiguity with the function pointer overload. This is marked with a TODO to be addressed in a follow-up.

Backport Policy

  • This is safe to backport to the following versions:
    • Jetty
    • Ionic
    • Harmonic
    • Fortress
  • This should not be backported
  • I am not sure
  • Other (fill in yourself)

Checklist

  • Signed all commits for DCO
  • Added a screen capture or video to the PR description that demonstrates the fix (as needed)
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • Updated Bazel files (if adding new files). Created an issue otherwise.
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers
  • Was GenAI used to generate this PR? If so, make sure to add "Assisted-by" to your commits. (See this policy for more info.)

Assisted-by: Gemini 3.6 Flash

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by and Generated-by messages.

Backports: If this is a backport, please use Rebase and Merge instead.

…ds for callbacks

Support explicit template parameters for capturing lambda callbacks
(e.g. node.Subscribe<MsgT>(topic, [&](const MsgT&) {}))
without ambiguity.

Assisted-by: Gemini 3.6 Flash
Signed-off-by: Addisu Z. Taddese <addisuzt@intrinsic.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

#642 made usage of Node::Subscribe with lambdas worse

2 participants