MIT-SPARK/Kimera-RPGO

const &

Closed this issue · 2 comments

We should change these methods of GenericSolver.h:

gtsam::Values calculateEstimate() { return values_; }
gtsam::Values calculateBestEstimate() { return values_; }
gtsam::Values getLinearizationPoint() { return values_; }
gtsam::NonlinearFactorGraph getFactorsUnsafe(){ return nfg_; }

to this:

inline const gtsam::Values& calculateEstimate() const { return values_; }
inline const gtsam::Values& calculateBestEstimate() const { return values_;}
etc...

btw, calculateEstimate() and calculateBestEstimate() are doing the same thing. Should they be?

Not necessarily, returning refs to members can be troublesome, what if the class is out of scope, then whoever uses these returns is dealing with undefined things.

yunzc commented

keeping both calculateEstimate() and calculateBestEstimate() because I want to keep the interface similar to that of isam2 in gtsam, which also have both of these calls (and they also do pretty much the same thing).

Adding the inline const but not the refs