Drake
extract_double.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdexcept>
4 
7 
8 namespace drake {
9 
25 template <typename T>
26 double ExtractDoubleOrThrow(const T& scalar) {
27  static_assert(!is_numeric<T>::value,
28  "Numeric scalar types should overload this function");
29  throw std::runtime_error(NiceTypeName::Get<T>() +
30  " cannot be converted to a double");
31 }
32 
34 inline double ExtractDoubleOrThrow(double scalar) { return scalar; }
35 
36 } // namespace drake
Definition: automotive_demo.cc:88
This file contains traits for number (scalar) types.
double ExtractDoubleOrThrow(const Eigen::AutoDiffScalar< DerType > &scalar)
Returns the autodiff scalar&#39;s value() as a double.
Definition: autodiff_overloads.h:134
is_numeric is true for types that are on the real line.
Definition: number_traits.h:31