Merge pull request #608 from borglab/fix/606

Mark Values::at return type as const
release/4.3a0
Varun Agrawal 2020-11-30 15:49:35 -05:00 committed by GitHub
commit b0962ede05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);}