Merge pull request #1502 from zubingtan/use_auto_for_map_in_range_based_for_loop

Some refine works related to range-based for-loop of map constainer
release/4.3a0
Varun Agrawal 2023-04-13 00:56:24 -04:00 committed by GitHub
commit 5ab98a8c2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 14 deletions

View File

@ -76,8 +76,7 @@ void save(Archive& ar, const std::optional<T>& t, const unsigned int /*version*/
}
template <class Archive, class T>
void load(Archive& ar, std::optional<T>& t, const unsigned int /*version*/
) {
void load(Archive& ar, std::optional<T>& t, const unsigned int /*version*/) {
bool tflag;
ar >> boost::serialization::make_nvp("initialized", tflag);
if (!tflag) {

View File

@ -94,7 +94,10 @@ namespace gtsam {
for (Key j : f.keys()) cs[j] = f.cardinality(j);
// Convert map into keys
DiscreteKeys keys;
for (const std::pair<const Key, size_t>& key : cs) keys.push_back(key);
keys.reserve(cs.size());
for (const auto& key : cs) {
keys.emplace_back(key);
}
// apply operand
ADT result = ADT::apply(f, op);
// Make a new factor

View File

@ -79,7 +79,7 @@ namespace gtsam {
/* ************************************************************************ */
VectorValues::iterator VectorValues::insert(const std::pair<Key, Vector>& key_value) {
std::pair<iterator, bool> result = values_.insert(key_value);
const std::pair<iterator, bool> result = values_.insert(key_value);
if(!result.second)
throw std::invalid_argument(
"Requested to insert variable '" + DefaultKeyFormatter(key_value.first)
@ -344,14 +344,13 @@ namespace gtsam {
}
/* ************************************************************************ */
VectorValues operator*(const double a, const VectorValues &v)
{
VectorValues operator*(const double a, const VectorValues& c) {
VectorValues result;
for(const VectorValues::KeyValuePair& key_v: v)
for (const auto& [key, value] : c)
#ifdef TBB_GREATER_EQUAL_2020
result.values_.emplace(key_v.first, a * key_v.second);
result.values_.emplace(key, a * value);
#else
result.values_.insert({key_v.first, a * key_v.second});
result.values_.insert({key, a * value});
#endif
return result;
}