From 0710091887d33e98faa949371e3c45c7f2b6873b Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Sat, 4 Feb 2023 09:01:13 -0800 Subject: [PATCH] Hunt down std::map::emplace candidates --- gtsam/base/DSFMap.h | 2 +- gtsam/base/FastMap.h | 2 +- gtsam/base/timing.cpp | 5 ++--- gtsam/geometry/CameraSet.h | 2 +- gtsam/inference/BayesTree-inst.h | 2 +- gtsam/inference/ClusterTree-inst.h | 2 +- gtsam/inference/EliminationTree-inst.h | 8 ++++---- gtsam/inference/VariableSlots.h | 3 +-- gtsam/inference/graph-inl.h | 4 ++-- gtsam/inference/graph.h | 2 +- gtsam/linear/VectorValues.cpp | 12 ++++++------ gtsam/linear/VectorValues.h | 8 ++++---- gtsam/nonlinear/ISAM2.cpp | 2 +- 13 files changed, 26 insertions(+), 28 deletions(-) diff --git a/gtsam/base/DSFMap.h b/gtsam/base/DSFMap.h index a666a8334..c7ae09f20 100644 --- a/gtsam/base/DSFMap.h +++ b/gtsam/base/DSFMap.h @@ -50,7 +50,7 @@ class DSFMap { iterator it = entries_.find(key); // if key does not exist, create and return itself if (it == entries_.end()) { - it = entries_.insert(std::make_pair(key, empty)).first; + it = entries_.insert({key, empty}).first; it->second.parent_ = it; it->second.rank_ = 0; } diff --git a/gtsam/base/FastMap.h b/gtsam/base/FastMap.h index 359c865a5..e8ef3fc4f 100644 --- a/gtsam/base/FastMap.h +++ b/gtsam/base/FastMap.h @@ -63,7 +63,7 @@ public: } /** Handy 'insert' function for Matlab wrapper */ - bool insert2(const KEY& key, const VALUE& val) { return Base::insert(std::make_pair(key, val)).second; } + bool insert2(const KEY& key, const VALUE& val) { return Base::insert({key, val}).second; } /** Handy 'exists' function */ bool exists(const KEY& e) const { return this->find(e) != this->end(); } diff --git a/gtsam/base/timing.cpp b/gtsam/base/timing.cpp index 3291415b8..72d08ad3b 100644 --- a/gtsam/base/timing.cpp +++ b/gtsam/base/timing.cpp @@ -222,10 +222,9 @@ size_t getTicTocID(const char *descriptionC) { static gtsam::FastMap idMap; // Retrieve or add this string - gtsam::FastMap::const_iterator it = idMap.find( - description); + auto it = idMap.find(description); if (it == idMap.end()) { - it = idMap.insert(std::make_pair(description, nextId)).first; + it = idMap.insert({description, nextId}).first; ++nextId; } diff --git a/gtsam/geometry/CameraSet.h b/gtsam/geometry/CameraSet.h index 901017bb3..23a4b467e 100644 --- a/gtsam/geometry/CameraSet.h +++ b/gtsam/geometry/CameraSet.h @@ -396,7 +396,7 @@ class CameraSet : public std::vector> { FastMap KeySlotMap; for (size_t slot = 0; slot < allKeys.size(); slot++) - KeySlotMap.insert(std::make_pair(allKeys[slot], slot)); + KeySlotMap.emplace(allKeys[slot], slot); // Schur complement trick // G = F' * F - F' * E * P * E' * F diff --git a/gtsam/inference/BayesTree-inst.h b/gtsam/inference/BayesTree-inst.h index 8d3712624..1f2aa2970 100644 --- a/gtsam/inference/BayesTree-inst.h +++ b/gtsam/inference/BayesTree-inst.h @@ -245,7 +245,7 @@ namespace gtsam { void BayesTree::fillNodesIndex(const sharedClique& subtree) { // Add each frontal variable of this root node for(const Key& j: subtree->conditional()->frontals()) { - bool inserted = nodes_.insert(std::make_pair(j, subtree)).second; + bool inserted = nodes_.insert({j, subtree}).second; assert(inserted); (void)inserted; } // Fill index for each child diff --git a/gtsam/inference/ClusterTree-inst.h b/gtsam/inference/ClusterTree-inst.h index 4d6dfb22e..b16a2a66f 100644 --- a/gtsam/inference/ClusterTree-inst.h +++ b/gtsam/inference/ClusterTree-inst.h @@ -210,7 +210,7 @@ struct EliminationData { // putting orphan subtrees in the index - they'll already be in the index of the ISAM2 // object they're added to. for (const Key& j: myData.bayesTreeNode->conditional()->frontals()) - nodesIndex_.insert(std::make_pair(j, myData.bayesTreeNode)); + nodesIndex_.emplace(j, myData.bayesTreeNode); // Store remaining factor in parent's gathered factors if (!eliminationResult.second->empty()) { diff --git a/gtsam/inference/EliminationTree-inst.h b/gtsam/inference/EliminationTree-inst.h index ac25495f6..63cbe222b 100644 --- a/gtsam/inference/EliminationTree-inst.h +++ b/gtsam/inference/EliminationTree-inst.h @@ -218,13 +218,13 @@ namespace gtsam { // Add roots in sorted order { FastMap keys; - for(const sharedNode& root: this->roots_) { keys.insert(std::make_pair(root->key, root)); } + for(const sharedNode& root: this->roots_) { keys.emplace(root->key, root); } typedef typename FastMap::value_type Key_Node; for(const Key_Node& key_node: keys) { stack1.push(key_node.second); } } { FastMap keys; - for(const sharedNode& root: expected.roots_) { keys.insert(std::make_pair(root->key, root)); } + for(const sharedNode& root: expected.roots_) { keys.emplace(root->key, root); } typedef typename FastMap::value_type Key_Node; for(const Key_Node& key_node: keys) { stack2.push(key_node.second); } } @@ -258,13 +258,13 @@ namespace gtsam { // Add children in sorted order { FastMap keys; - for(const sharedNode& node: node1->children) { keys.insert(std::make_pair(node->key, node)); } + for(const sharedNode& node: node1->children) { keys.emplace(node->key, node); } typedef typename FastMap::value_type Key_Node; for(const Key_Node& key_node: keys) { stack1.push(key_node.second); } } { FastMap keys; - for(const sharedNode& node: node2->children) { keys.insert(std::make_pair(node->key, node)); } + for(const sharedNode& node: node2->children) { keys.emplace(node->key, node); } typedef typename FastMap::value_type Key_Node; for(const Key_Node& key_node: keys) { stack2.push(key_node.second); } } diff --git a/gtsam/inference/VariableSlots.h b/gtsam/inference/VariableSlots.h index ebdf7ecea..edc1b1840 100644 --- a/gtsam/inference/VariableSlots.h +++ b/gtsam/inference/VariableSlots.h @@ -109,8 +109,7 @@ VariableSlots::VariableSlots(const FG& factorGraph) // we're combining. Initially we put the max integer value in // the array entry for each factor that will indicate the factor // does not involve the variable. - iterator thisVarSlots; bool inserted; - std::tie(thisVarSlots, inserted) = this->insert(std::make_pair(involvedVariable, FastVector())); + auto [thisVarSlots, inserted] = this->insert({involvedVariable, FastVector()}); if(inserted) thisVarSlots->second.resize(factorGraph.nrFactors(), Empty); thisVarSlots->second[jointFactorPos] = factorVarSlot; diff --git a/gtsam/inference/graph-inl.h b/gtsam/inference/graph-inl.h index ceae2e3ab..dc2e3d569 100644 --- a/gtsam/inference/graph-inl.h +++ b/gtsam/inference/graph-inl.h @@ -126,13 +126,13 @@ predecessorMap2Graph(const PredecessorMap& p_map) { std::tie(child,parent) = child_parent; if (key2vertex.find(child) == key2vertex.end()) { v1 = add_vertex(child, g); - key2vertex.insert(std::make_pair(child, v1)); + key2vertex.emplace(child, v1); } else v1 = key2vertex[child]; if (key2vertex.find(parent) == key2vertex.end()) { v2 = add_vertex(parent, g); - key2vertex.insert(std::make_pair(parent, v2)); + key2vertex.emplace(parent, v2); } else v2 = key2vertex[parent]; diff --git a/gtsam/inference/graph.h b/gtsam/inference/graph.h index 988c79b74..9bb181467 100644 --- a/gtsam/inference/graph.h +++ b/gtsam/inference/graph.h @@ -59,7 +59,7 @@ namespace gtsam { public: /** convenience insert so we can pass ints for TypedSymbol keys */ inline void insert(const KEY& key, const KEY& parent) { - std::map::insert(std::make_pair(key, parent)); + std::map::emplace(key, parent); } }; diff --git a/gtsam/linear/VectorValues.cpp b/gtsam/linear/VectorValues.cpp index cfa0ed9a2..b59a4b273 100644 --- a/gtsam/linear/VectorValues.cpp +++ b/gtsam/linear/VectorValues.cpp @@ -43,7 +43,7 @@ namespace gtsam { #ifdef TBB_GREATER_EQUAL_2020 values_.emplace(key, x.segment(j, n)); #else - values_.insert(std::make_pair(key, x.segment(j, n))); + values_.insert({key, x.segment(j, n)}); #endif j += n; } @@ -56,7 +56,7 @@ namespace gtsam { #ifdef TBB_GREATER_EQUAL_2020 values_.emplace(v.key, x.segment(j, v.dimension)); #else - values_.insert(std::make_pair(v.key, x.segment(j, v.dimension))); + values_.insert({v.key, x.segment(j, v.dimension)}); #endif j += v.dimension; } @@ -70,7 +70,7 @@ namespace gtsam { #ifdef TBB_GREATER_EQUAL_2020 result.values_.emplace(key, Vector::Zero(value.size())); #else - result.values_.insert(std::make_pair(key, Vector::Zero(value.size()))); + result.values_.insert({key, Vector::Zero(value.size())}); #endif return result; } @@ -267,7 +267,7 @@ namespace gtsam { #ifdef TBB_GREATER_EQUAL_2020 result.values_.emplace(j1->first, j1->second + j2->second); #else - result.values_.insert(std::make_pair(j1->first, j1->second + j2->second)); + result.values_.insert({j1->first, j1->second + j2->second}); #endif return result; @@ -329,7 +329,7 @@ namespace gtsam { #ifdef TBB_GREATER_EQUAL_2020 result.values_.emplace(j1->first, j1->second - j2->second); #else - result.values_.insert(std::make_pair(j1->first, j1->second - j2->second)); + result.values_.insert({j1->first, j1->second - j2->second}); #endif return result; @@ -349,7 +349,7 @@ namespace gtsam { #ifdef TBB_GREATER_EQUAL_2020 result.values_.emplace(key_v.first, a * key_v.second); #else - result.values_.insert(std::make_pair(key_v.first, a * key_v.second)); + result.values_.insert({key_v.first, a * key_v.second}); #endif return result; } diff --git a/gtsam/linear/VectorValues.h b/gtsam/linear/VectorValues.h index bb5bbc794..478cfd770 100644 --- a/gtsam/linear/VectorValues.h +++ b/gtsam/linear/VectorValues.h @@ -80,7 +80,7 @@ namespace gtsam { public: typedef Values::iterator iterator; ///< Iterator over vector values typedef Values::const_iterator const_iterator; ///< Const iterator over vector values - typedef std::shared_ptr shared_ptr; ///< shared_ptr to this class + typedef std::shared_ptr shared_ptr; ///< shared_ptr to this class typedef Values::value_type value_type; ///< Typedef to pair typedef value_type KeyValuePair; ///< Typedef to pair typedef std::map Dims; ///< Keyed vector dimensions @@ -186,7 +186,7 @@ namespace gtsam { #if ! defined(GTSAM_USE_TBB) || defined (TBB_GREATER_EQUAL_2020) return values_.emplace(std::piecewise_construct, std::forward_as_tuple(j), std::forward_as_tuple(args...)); #else - return values_.insert(std::make_pair(j, Vector(std::forward(args)...))); + return values_.insert({j, Vector(std::forward(args)...)}); #endif } @@ -195,7 +195,7 @@ namespace gtsam { * @param value The vector to be inserted. * @param j The index with which the value will be associated. */ iterator insert(Key j, const Vector& value) { - return insert(std::make_pair(j, value)); + return insert({j, value}); } /** Insert all values from \c values. Throws an invalid_argument exception if any keys to be @@ -210,7 +210,7 @@ namespace gtsam { #ifdef TBB_GREATER_EQUAL_2020 return values_.emplace(j, value); #else - return values_.insert(std::make_pair(j, value)); + return values_.insert({j, value}); #endif } diff --git a/gtsam/nonlinear/ISAM2.cpp b/gtsam/nonlinear/ISAM2.cpp index 7f2dfa6e8..579231151 100644 --- a/gtsam/nonlinear/ISAM2.cpp +++ b/gtsam/nonlinear/ISAM2.cpp @@ -321,7 +321,7 @@ void ISAM2::recalculateIncremental(const ISAM2UpdateParams& updateParams, const int group = result->observedKeys.size() < affectedFactorsVarIndex.size() ? 1 : 0; for (Key var : result->observedKeys) - constraintGroups.insert(std::make_pair(var, group)); + constraintGroups.emplace(var, group); } // Remove unaffected keys from the constraints