From 5bf8dc4174a214761714586de6b24efb842a5a4e Mon Sep 17 00:00:00 2001 From: Fan Jiang Date: Tue, 2 Jun 2020 17:36:20 -0400 Subject: [PATCH] Fixed emplace to align with std --- gtsam/linear/VectorValues.cpp | 8 ++------ gtsam/linear/VectorValues.h | 2 +- gtsam/linear/linearAlgorithms-inst.h | 9 +++++++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/gtsam/linear/VectorValues.cpp b/gtsam/linear/VectorValues.cpp index e74d3776d..eb92228e5 100644 --- a/gtsam/linear/VectorValues.cpp +++ b/gtsam/linear/VectorValues.cpp @@ -97,17 +97,13 @@ namespace gtsam { } /* ************************************************************************* */ - VectorValues::iterator VectorValues::emplace(Key j, const Vector& value) { + std::pair VectorValues::emplace(Key j, const Vector& value) { #ifdef TBB_GREATER_EQUAL_2020 std::pair result = values_.emplace(j, value); #else std::pair result = values_.insert(std::make_pair(j, value)); #endif - if(!result.second) - throw std::invalid_argument( - "Requested to emplace variable '" + DefaultKeyFormatter(j) - + "' already in this VectorValues."); - return result.first; + return result; } /* ************************************************************************* */ diff --git a/gtsam/linear/VectorValues.h b/gtsam/linear/VectorValues.h index eed212eda..e11e98cce 100644 --- a/gtsam/linear/VectorValues.h +++ b/gtsam/linear/VectorValues.h @@ -179,7 +179,7 @@ namespace gtsam { * j is already used. * @param value The vector to be inserted. * @param j The index with which the value will be associated. */ - iterator emplace(Key j, const Vector& value); + std::pair emplace(Key j, const Vector& value); /** Insert a vector \c value with key \c j. Throws an invalid_argument exception if the key \c * j is already used. diff --git a/gtsam/linear/linearAlgorithms-inst.h b/gtsam/linear/linearAlgorithms-inst.h index 1afaf79d1..57d26f5dc 100644 --- a/gtsam/linear/linearAlgorithms-inst.h +++ b/gtsam/linear/linearAlgorithms-inst.h @@ -98,8 +98,13 @@ namespace gtsam // Insert solution into a VectorValues DenseIndex vectorPosition = 0; for(GaussianConditional::const_iterator frontal = c.beginFrontals(); frontal != c.endFrontals(); ++frontal) { - VectorValues::const_iterator r = - collectedResult.emplace(*frontal, solution.segment(vectorPosition, c.getDim(frontal))); + auto result = collectedResult.emplace(*frontal, solution.segment(vectorPosition, c.getDim(frontal))); + if(!result.second) + throw std::invalid_argument( + "Requested to emplace variable '" + DefaultKeyFormatter(*frontal) + + "' already in this VectorValues."); + + VectorValues::const_iterator r = result.first; myData.cliqueResults.emplace(r->first, r); vectorPosition += c.getDim(frontal); }