Simplify instantiation of cost functions and their functors

If arguments are passed to a cost function that can be used to construct
the functor, the latter will be instantiated by the cost function using
std::make_unique to ensure exception safety. This not only avoids static
analysis warnings caused by calling new but also spelling the cost
functor type name multiple times.

Also expand deduction guides for instantiating
Dynamic(Auto|Numeric)DiffCostFunction from std::unique_ptr enabled
constructor overloads.

Finally, make CostFunction default move constructible and assignable but
only through derived classes. This in turn allows derived classes to be
movable without relying on custom implementations of corresponding
operators.

Change-Id: Idee8b9871d862bc9f9f8b5a8d0bedc52863e93c0
This commit is contained in:
Sergiu Deitsch
2023-06-10 21:01:25 +02:00
parent 8b88a9ab49
commit 91773746be
37 changed files with 613 additions and 262 deletions
+8 -7
View File
@@ -118,12 +118,13 @@ An implementation of the above three steps looks as follows:
y[0] = y_in[0];
y[1] = y_in[1];
compute_distortion.reset(new ceres::CostFunctionToFunctor<1, 1>(
new ceres::NumericDiffCostFunction<ComputeDistortionValueFunctor,
ceres::CENTRAL,
1,
1>(
new ComputeDistortionValueFunctor)));
compute_distortion = std::make_unique<ceres::CostFunctionToFunctor<1, 1>>(
std::make_unique<ceres::NumericDiffCostFunction<
ComputeDistortionValueFunctor
, ceres::CENTRAL, 1, 1
>
>()
);
}
template <typename T>
@@ -140,7 +141,7 @@ An implementation of the above three steps looks as follows:
double x[2];
double y[2];
std::unique_ptr<ceres::CostFunctionToFunctor<1, 1> > compute_distortion;
std::unique_ptr<ceres::CostFunctionToFunctor<1, 1>> compute_distortion;
};