Provide DynamicAutoDiffCostFunction deduction guide The deduction guide allows to avoid repeating the CostFunctor type. Change-Id: I2285de37071006a97f89988baa9b7054d82dae86
diff --git a/include/ceres/dynamic_autodiff_cost_function.h b/include/ceres/dynamic_autodiff_cost_function.h index c21d051..ce0f802 100644 --- a/include/ceres/dynamic_autodiff_cost_function.h +++ b/include/ceres/dynamic_autodiff_cost_function.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2019 Google Inc. All rights reserved. +// Copyright 2023 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -269,6 +269,16 @@ Ownership ownership_; }; +// Deduction guide that allows the user to avoid explicitly specifying the +// template parameter of DynamicAutoDiffCostFunction. The class can instead be +// instantiated as follows: +// +// new DynamicAutoDiffCostFunction{new MyCostFunctor{}}; +// +template <typename CostFunctor> +DynamicAutoDiffCostFunction(CostFunctor* functor, Ownership ownership) + -> DynamicAutoDiffCostFunction<CostFunctor>; + } // namespace ceres #endif // CERES_PUBLIC_DYNAMIC_AUTODIFF_COST_FUNCTION_H_
diff --git a/internal/ceres/dynamic_autodiff_cost_function_test.cc b/internal/ceres/dynamic_autodiff_cost_function_test.cc index 7b2239c..1cf83a5 100644 --- a/internal/ceres/dynamic_autodiff_cost_function_test.cc +++ b/internal/ceres/dynamic_autodiff_cost_function_test.cc
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2022 Google Inc. All rights reserved. +// Copyright 2023 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -803,4 +803,9 @@ EXPECT_EQ(residual, target_value); } +TEST(DynamicAutoDiffCostFunctionTest, DeductionTemplateCompilationTest) { + // Ensure deduction guide to be working + (void)DynamicAutoDiffCostFunction(new MyCostFunctor()); +} + } // namespace ceres::internal