blob: 54126cfbd4bf7a31926aa62e153a8d059c1a15a1 [file] [log] [blame]
Patrick Ventureaadb30d2020-08-10 09:17:11 -07001#pragma once
2
Patrick Ventureef1f8862020-08-17 09:34:35 -07003#include <stdexcept>
Patrick Ventureaadb30d2020-08-10 09:17:11 -07004
5namespace pid_control
6{
7
8struct 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