ros2 / ros2/rclcpp

Prefer lambda to std::bind

Open
#1,701 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted question
Dominant language
C++
Stars
805
Forks
564
Avg merge
1d 17h
Merged PRs (30d)
27

Description

Feature request

Feature description

Replace all std::bind with lambda. Is it worth doing it for now?

https://github.com/isocpp/CppCoreGuidelines/issues/1796

Implementation considerations

e.g.

Replace https://github.com/ros2/rclcpp/blob/e9e398d2d49de2ecc3148d425f8659d9db74918c/rclcpp/src/rclcpp/time_source.cpp#L130-L133 with

  parameter_subscription_ = rclcpp::AsyncParametersClient::on_parameter_event(
    node_topics_,
    [this](std::shared_ptr<const rcl_interfaces::msg::ParameterEvent> event) {
        return on_parameter_event(event);
      }
    );

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with rclcpp/src/rclcpp/time_source.cpp around lines 130-133, then inventory the other std::bind uses in rclcpp and check whether each replacement preserves its callback behavior. Done means all intended std::bind calls are replaced with equivalent lambdas and the existing rclcpp tests still pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
developer-experience
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.