Make Values::at return as const

release/4.3a0
Varun Agrawal 2020-11-19 13:42:52 -05:00
parent 70b04afaa3
commit 32070b013f
2 changed files with 9 additions and 10 deletions

View File

@ -338,19 +338,18 @@ namespace gtsam {
} // internal
/* ************************************************************************* */
template<typename ValueType>
ValueType Values::at(Key j) const {
template <typename ValueType>
const ValueType Values::at(Key j) const {
// Find the item
KeyValueMap::const_iterator item = values_.find(j);
// Throw exception if it does not exist
if(item == values_.end())
throw ValuesKeyDoesNotExist("at", j);
if (item == values_.end()) throw ValuesKeyDoesNotExist("at", j);
// Check the type and throw exception if incorrect
// h() split in two lines to avoid internal compiler error (MSVC2017)
auto h = internal::handle<ValueType>();
return h(j,item->second);
// Check the type and throw exception if incorrect
// h() split in two lines to avoid internal compiler error (MSVC2017)
auto h = internal::handle<ValueType>();
return h(j, item->second);
}
/* ************************************************************************* */

View File

@ -187,8 +187,8 @@ namespace gtsam {
* Dynamic matrices/vectors can be retrieved as fixed-size, but not vice-versa.
* @return The stored value
*/
template<typename ValueType>
ValueType at(Key j) const;
template <typename ValueType>
const ValueType at(Key j) const;
/// version for double
double atDouble(size_t key) const { return at<double>(key);}