[ros-users] [Discourse.ros.org] [Next Generation ROS] RFC: using C++14

Morgan Quigley ros.discourse at gmail.com
Thu Dec 8 19:47:24 UTC 2016




This is only tangentially related to the question of "should we use C++14", but anyway this is an attempt to simplify the minimal examples using generic lambas:

For example, this C++11 code:

    subscription_ = this->create_subscription<std_msgs::msg::String>(
      "topic",
      [](std_msgs::msg::String::UniquePtr msg) {
      printf("I heard: [%s]\n", msg->data.c_str());
    });

requires the message type to be listed twice: once for the create_subscription<> template, and once for the lambda parameter. It would be nice if we could do this:

    subscription_ = this->create_subscription<std_msgs::msg::String>(
      "topic", [](auto msg) {
      printf("I heard: [%s]\n", msg->data.c_str());
    });

However, that code change explodes spectacularly into a few hundred lines of gcc errors.

Does anybody know if that style of usage (mixing generic lambas with template instantiations) is just impossible in C++14 ? The overlap between lambdas and templates still seems a bit mysterious to me.






---
[Visit Topic](https://discourse.ros.org/t/rfc-using-c-14/921/9) or reply to this email to respond.




More information about the ros-users mailing list