diff --git a/rclcpp/include/rclcpp/type_adapter.hpp b/rclcpp/include/rclcpp/type_adapter.hpp index 14cfb2934a..4acc1e901f 100644 --- a/rclcpp/include/rclcpp/type_adapter.hpp +++ b/rclcpp/include/rclcpp/type_adapter.hpp @@ -116,17 +116,29 @@ struct is_type_adapter>: std::true_type {}; template struct TypeAdapter::value>>: T {}; +namespace detail +{ + +template +struct assert_type_pair_is_specialized_type_adapter +{ + using type_adapter = TypeAdapter; + static_assert( + type_adapter::is_specialized::value, + "No type adapter for this custom type/ros message type pair"); +}; + +} // detail + /// Template metafunction that can make the type being adapted explicit. template struct adapt_type { template - struct as : TypeAdapter - { - static_assert( - TypeAdapter::is_specialized::value, - "No type adapter for this custom type/ros message type pair"); - }; + using as = typename ::rclcpp::detail::assert_type_pair_is_specialized_type_adapter< + CustomType, + ROSMessageType + >::type_adapter; }; /// Implicit type adapter used as a short hand way to create something with just the custom type. diff --git a/rclcpp/test/rclcpp/test_publisher_with_type_adapter.cpp b/rclcpp/test/rclcpp/test_publisher_with_type_adapter.cpp index a9ba8d7c2d..2f5d540568 100644 --- a/rclcpp/test/rclcpp/test_publisher_with_type_adapter.cpp +++ b/rclcpp/test/rclcpp/test_publisher_with_type_adapter.cpp @@ -156,13 +156,11 @@ TEST_F(TestPublisher, various_creation_signatures) { auto publisher = node->create_publisher("topic", 42); (void)publisher; } - /* TODO(audrow) Enable this test once the adapt_type<>::as<> syntax is supported { using StringTypeAdapter = rclcpp::adapt_type::as; auto publisher = node->create_publisher("topic", 42); (void)publisher; } - */ } } diff --git a/rclcpp/test/rclcpp/test_subscription_with_type_adapter.cpp b/rclcpp/test/rclcpp/test_subscription_with_type_adapter.cpp index fc413a890a..54c11bf1b1 100644 --- a/rclcpp/test/rclcpp/test_subscription_with_type_adapter.cpp +++ b/rclcpp/test/rclcpp/test_subscription_with_type_adapter.cpp @@ -139,13 +139,12 @@ TEST_F(TestSubscription, various_creation_signatures) { node->create_subscription("topic", 42, [](const std::string &) {}); (void)sub; } - /* TODO(audrow) Enable this test once the adapt_type<>::as<> syntax is supported { using StringTypeAdapter = rclcpp::adapt_type::as; - auto sub = node->create_subscription("topic", 42, [](const std::string &) {}); + auto sub = + node->create_subscription("topic", 42, [](const std::string &) {}); (void)sub; } - */ } /*