diff --git a/cpp/NonlinearFactorGraph-inl.h b/cpp/NonlinearFactorGraph-inl.h index b7ddb4d67..a7bdff8e8 100644 --- a/cpp/NonlinearFactorGraph-inl.h +++ b/cpp/NonlinearFactorGraph-inl.h @@ -8,6 +8,7 @@ #pragma once +#include #include "GaussianFactorGraph.h" #include "NonlinearFactorGraph.h" @@ -18,11 +19,8 @@ namespace gtsam { double NonlinearFactorGraph::error(const Config& c) const { double total_error = 0.; // iterate over all the factors_ to accumulate the log probabilities - typedef typename FactorGraph >::const_iterator - const_iterator; - for (const_iterator factor = this->factors_.begin(); factor - != this->factors_.end(); factor++) - total_error += (*factor)->error(c); + BOOST_FOREACH(typename NonlinearFactorGraph::sharedFactor factor, this->factors_) + total_error += factor->error(c); return total_error; } @@ -34,12 +32,9 @@ namespace gtsam { // create an empty linear FG boost::shared_ptr linearFG(new GaussianFactorGraph); - typedef typename FactorGraph >::const_iterator - const_iterator; // linearize all factors - for (const_iterator factor = this->factors_.begin(); factor - < this->factors_.end(); factor++) { - boost::shared_ptr lf = (*factor)->linearize(config); + BOOST_FOREACH(typename NonlinearFactorGraph::sharedFactor factor, this->factors_) { + boost::shared_ptr lf = factor->linearize(config); linearFG->push_back(lf); } return linearFG; @@ -50,4 +45,5 @@ namespace gtsam { const Config& config) const { return *linearize_(config); } -} + +} // namespace gtsam