-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AnySubscriptionCallback doesn't accept std::bind
callbacks with bound arguments
#2429
Comments
@DensoADAS or @jmachowinski can you take a look at this? I read the error and nothing obvious jumped out at me. Maybe you have more context after landing #1928 |
I'll have a look. |
@mjcarroll I looked into this, as far as I can say, the argument deduction for std::bind in class SomeClass
{
public:
struct SomeHandle
{
int i;
};
void rosMessageHandler(const int& /*channelId*/,
SomeHandle /*clientHandle*/,
std::shared_ptr<rclcpp::SerializedMessage> /*msg*/) {
}
};
rclcpp::function_traits::function_traits<std::bind(&SomeClass::rosMessageHandler, &s, 1, SomeClass::SomeHandle(), std::placeholders::_1)>::arguments resolves to std::tuple<int const&, SomeClass::SomeHandle, std::shared_ptr<rclcpp::SerializedMessage> > instead of the expected std::shared_ptr<rclcpp::SerializedMessage> But this is serious meta programming foo, which isn't my best discipline. Any Ideas ? |
@mjcarroll https://github.com/cellumation/rclcpp/tree/function_traits_bug |
@mjcarroll Something I forgot to mention: As to why this bug now surfaced: |
This issue has been mentioned on ROS Discourse. There might be relevant details there: https://discourse.ros.org/t/rclcpp-template-metaprogramming-bug-help-wanted/36319/1 |
I guess in this (and related) blocks
you need to write some meta-function which iterates through |
Very crude proof-of-concept: https://godbolt.org/z/7oWfYTEqh |
The MSVC issue can easily be solved by:
Adding this does not hurt other compilers: https://godbolt.org/z/sP63PMdMM I won't spend time working on a cleaned-up solution (at least not in the foreseeable future). |
Bug report
Required Info:
Steps to reproduce issue
Expected behavior
std::bind(&FoxgloveBridge::rosMessageHandler, this, channelId, clientHandle, _1),
(source) is cast tostd::function
from any_subscription_callback.hppActual behavior
Additional information
For example
std::bind(&Class::method, this, std::placeholders::_1)
(without bound arguments) will build fineWe also were able to fix the issue by casting the callback to
std::function
before passing it to the subscriptionIs this how it is supposed to be done now, or is there a bug in casting std::bind from any_subscription_callback.hpp?
The text was updated successfully, but these errors were encountered: