mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-30 00:50:37 +08:00
[modernize] Modernize AutoDiff and NumericDiff CostFunctions to C++17
Modernize the construction and initialization logic of AutoDiffCostFunction, NumericDiffCostFunction, AutoDiffFirstOrderFunction, NumericDiffFirstOrderFunction, DynamicAutoDiffCostFunction, DynamicNumericDiffCostFunction, and CostFunctionToFunctor by utilizing C++17 features: - Simplify constructor delegation using if constexpr, removing the need for internal InitTag structures. - Use std::is_constructible_v for cleaner SFINAE in variadic constructors. - Add static_assert to catch improper usage of DYNAMIC residuals/parameters at compile-time. - Add Ownership support to AutoDiffFirstOrderFunction, DynamicAutoDiffCostFunction, and DynamicNumericDiffCostFunction. - Simplify CostFunctionToFunctor::operator() using variadic parameter packs. - Use this->num_residuals() for consistent and clear access to base class state. - Minor code quality improvements and removal of redundant template parameters. Change-Id: Id760a26ba2ceca4fb2939ef7632f2f1d9cc430c9
This commit is contained in:
@@ -263,7 +263,7 @@ class NumericDiffCostFunction final
|
||||
functor_.get(),
|
||||
residuals,
|
||||
options_,
|
||||
SizedCostFunction<kNumResiduals, Ns...>::num_residuals(),
|
||||
this->num_residuals(),
|
||||
parameters_reference_copy.data(),
|
||||
jacobians);
|
||||
|
||||
@@ -279,7 +279,7 @@ class NumericDiffCostFunction final
|
||||
const NumericDiffOptions& options)
|
||||
: functor_(std::move(functor)), ownership_(ownership), options_(options) {
|
||||
if constexpr (kNumResiduals == DYNAMIC) {
|
||||
SizedCostFunction<kNumResiduals, Ns...>::set_num_residuals(num_residuals);
|
||||
this->set_num_residuals(num_residuals);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user