1 #pragma once 2 3 #include <stdexcept> 4 5 namespace pid_control 6 { 7 8 struct VariantToDoubleVisitor 9 { 10 template <typename T> 11 std::enable_if_t<std::is_arithmetic<T>::value, double> 12 operator()(const T& t) const 13 { 14 return static_cast<double>(t); 15 } 16 17 template <typename T> 18 std::enable_if_t<!std::is_arithmetic<T>::value, double> 19 operator()(const T& t) const 20 { 21 throw std::invalid_argument("Cannot translate type to double"); 22 } 23 }; 24 25 } // namespace pid_control 26