Patrick Venture | aadb30d | 2020-08-10 09:17:11 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | ef1f886 | 2020-08-17 09:34:35 -0700 | [diff] [blame] | 3 | #include <stdexcept> |
Patrick Venture | aadb30d | 2020-08-10 09:17:11 -0700 | [diff] [blame] | 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 |