diff --git a/gtsam/nonlinear/Values-inl.h b/gtsam/nonlinear/Values-inl.h index cd8473a09..446a67ec7 100644 --- a/gtsam/nonlinear/Values-inl.h +++ b/gtsam/nonlinear/Values-inl.h @@ -274,6 +274,7 @@ namespace gtsam { namespace internal { // Check the type and throw exception if incorrect + // Generic version, partially specialized below for various Eigen Matrix types template struct handle { ValueType operator()(Key j, const gtsam::Value * const pointer) { @@ -375,14 +376,7 @@ namespace gtsam { throw ValuesKeyDoesNotExist("at", j); // Check the type and throw exception if incorrect - const Value& value = *item->second; - try { - return dynamic_cast&>(value).value(); - } catch (std::bad_cast &) { - // NOTE(abe): clang warns about potential side effects if done in typeid - const Value* value = item->second; - throw ValuesIncorrectType(j, typeid(*value), typeid(ValueType)); - } + return internal::handle()(j,item->second); } /* ************************************************************************* */