From 03505728f2054fac94806216f2fbb1e3208ec49d Mon Sep 17 00:00:00 2001 From: Mateusz Palczuk Date: Wed, 19 Feb 2025 16:36:30 +0100 Subject: [PATCH] Change compile time check for `ParamsType` in `API::spawn` Change behavior from not matching the templated function to matching to everything, but then asserting the correct types. This better reflects the intention, as we do not want to match some other function for different types, but to terminate the compilation Signed-off-by: Mateusz Palczuk --- .../include/traffic_simulator/api/api.hpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/simulation/traffic_simulator/include/traffic_simulator/api/api.hpp b/simulation/traffic_simulator/include/traffic_simulator/api/api.hpp index 54f66ffb816..6da1bfe0339 100644 --- a/simulation/traffic_simulator/include/traffic_simulator/api/api.hpp +++ b/simulation/traffic_simulator/include/traffic_simulator/api/api.hpp @@ -110,12 +110,7 @@ class API auto updateFrame() -> bool; // entities, ego - spawn - template < - typename PoseType, typename ParamsType, - typename = std::enable_if_t, traffic_simulator_msgs::msg::VehicleParameters>, - std::is_same, traffic_simulator_msgs::msg::PedestrianParameters>, - std::is_same, traffic_simulator_msgs::msg::MiscObjectParameters>>>> + template auto spawn( const std::string & name, const PoseType & pose, const ParamsType & parameters, const std::string & behavior = "", const std::string & model3d = "") -> entity::EntityBase & @@ -124,6 +119,14 @@ class API using PedestrianParameters = traffic_simulator_msgs::msg::PedestrianParameters; using MiscObjectParameters = traffic_simulator_msgs::msg::MiscObjectParameters; + static_assert( + std::disjunction_v< + std::is_same, VehicleParameters>, + std::is_same, PedestrianParameters>, + std::is_same, MiscObjectParameters>>, + "ParamsType must be either a VehicleParameters, a PedestrianParameters, or a " + "MiscObjectParameters"); + auto register_to_entity_manager = [&]() -> entity::EntityBase & { if constexpr (std::is_same_v) { if (behavior == VehicleBehavior::autoware()) {