diff --git a/rclcpp/include/rclcpp/any_service_callback.hpp b/rclcpp/include/rclcpp/any_service_callback.hpp index 1758464ea8..56c07d4c66 100644 --- a/rclcpp/include/rclcpp/any_service_callback.hpp +++ b/rclcpp/include/rclcpp/any_service_callback.hpp @@ -63,7 +63,40 @@ class AnyServiceCallback void set(CallbackT && callback) { - callback_ = std::forward(callback); + // Workaround Windows issue with std::bind + if constexpr ( + rclcpp::function_traits::same_arguments< + CallbackT, + SharedPtrCallback + >::value) + { + callback_.template emplace(callback); + } else if constexpr ( // NOLINT, can't satisfy both cpplint and uncrustify + rclcpp::function_traits::same_arguments< + CallbackT, + SharedPtrWithRequestHeaderCallback + >::value) + { + callback_.template emplace(callback); + } else if constexpr ( // NOLINT + rclcpp::function_traits::same_arguments< + CallbackT, + SharedPtrDeferResponseCallback + >::value) + { + callback_.template emplace(callback); + } else if constexpr ( // NOLINT + rclcpp::function_traits::same_arguments< + CallbackT, + SharedPtrDeferResponseCallbackWithServiceHandle + >::value) + { + callback_.template emplace(callback); + } else { + // the else clause is not needed, but anyways we should only be doing this instead + // of all the above workaround ... + callback_ = std::forward(callback); + } } template< @@ -75,7 +108,40 @@ class AnyServiceCallback if (!callback) { throw std::invalid_argument("AnyServiceCallback::set(): callback cannot be nullptr"); } - callback_ = std::forward(callback); + // Workaround Windows issue with std::bind + if constexpr ( + rclcpp::function_traits::same_arguments< + CallbackT, + SharedPtrCallback + >::value) + { + callback_.template emplace(callback); + } else if constexpr ( // NOLINT + rclcpp::function_traits::same_arguments< + CallbackT, + SharedPtrWithRequestHeaderCallback + >::value) + { + callback_.template emplace(callback); + } else if constexpr ( // NOLINT + rclcpp::function_traits::same_arguments< + CallbackT, + SharedPtrDeferResponseCallback + >::value) + { + callback_.template emplace(callback); + } else if constexpr ( // NOLINT + rclcpp::function_traits::same_arguments< + CallbackT, + SharedPtrDeferResponseCallbackWithServiceHandle + >::value) + { + callback_.template emplace(callback); + } else { + // the else clause is not needed, but anyways we should only be doing this instead + // of all the above workaround ... + callback_ = std::forward(callback); + } } // template>