Modernize CostFunction and FirstOrderFunction constructors

- Add constructors taking std::unique_ptr and ceres::Ownership to
  AutoDiffCostFunction, NumericDiffCostFunction, and their dynamic
  and first-order counterparts.
- Standardize delegating constructor style to use parentheses.
- Standardize ownership check in destructors.
- Fix documentation typos and example code in headers.
- Add comprehensive tests for Ownership and unique_ptr constructors.

Change-Id: I573abd695cdd89905997b573620e8d99d1cacca2
This commit is contained in:
Sameer Agarwal
2026-03-18 14:09:38 -07:00
parent 3abe9326f1
commit 3d1b494dce
9 changed files with 183 additions and 87 deletions
@@ -460,4 +460,16 @@ TEST(NumericDiffCostFunction, UniquePtrCtor) {
NumericDiffCostFunction<EasyFunctor, CENTRAL, 3, 5, 5>>();
}
TEST(NumericDiffCostFunction, Ownership) {
EasyFunctor functor;
{
NumericDiffCostFunction<EasyFunctor, CENTRAL, 3, 5, 5> cost_function(
&functor, DO_NOT_TAKE_OWNERSHIP);
double parameters_data[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
double* parameters[2] = {parameters_data, parameters_data + 5};
double residuals[3];
cost_function.Evaluate(parameters, residuals, nullptr);
}
}
} // namespace ceres::internal