diff --git a/include/ceres/dynamic_autodiff_cost_function.h b/include/ceres/dynamic_autodiff_cost_function.h index c21d0517f..ce0f802c3 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 @@ class DynamicAutoDiffCostFunction final : public DynamicCostFunction { 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 +DynamicAutoDiffCostFunction(CostFunctor* functor, Ownership ownership) + -> DynamicAutoDiffCostFunction; + } // 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 7b2239cdc..1cf83a59e 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 @@ TEST(DynamicAutoDiffCostFunction, EXPECT_EQ(residual, target_value); } +TEST(DynamicAutoDiffCostFunctionTest, DeductionTemplateCompilationTest) { + // Ensure deduction guide to be working + (void)DynamicAutoDiffCostFunction(new MyCostFunctor()); +} + } // namespace ceres::internal