Fixed emplace to align with std

release/4.3a0
Fan Jiang 2020-06-02 17:36:20 -04:00
parent 1fe876aba6
commit 5bf8dc4174
3 changed files with 10 additions and 9 deletions

View File

@ -97,17 +97,13 @@ namespace gtsam {
}
/* ************************************************************************* */
VectorValues::iterator VectorValues::emplace(Key j, const Vector& value) {
std::pair<VectorValues::iterator, bool> VectorValues::emplace(Key j, const Vector& value) {
#ifdef TBB_GREATER_EQUAL_2020
std::pair<iterator, bool> result = values_.emplace(j, value);
#else
std::pair<iterator, bool> 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;
}
/* ************************************************************************* */

View File

@ -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<VectorValues::iterator, bool> 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.

View File

@ -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);
}