From 67fcff91826b1391d7a9e69c6ab05da4e4ee8c41 Mon Sep 17 00:00:00 2001 From: Sameer Agarwal Date: Mon, 16 Dec 2019 20:33:19 -0800 Subject: [PATCH] Make Problem movable. Add a default move constructor and move assignment operator. https://github.com/ceres-solver/ceres-solver/issues/528 Change-Id: I16ecf367a800fde564c29e2b824cd4fb44111366 --- include/ceres/problem.h | 5 ++++- internal/ceres/problem_test.cc | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/ceres/problem.h b/include/ceres/problem.h index 278d80fe4..a4a6c8ffa 100644 --- a/include/ceres/problem.h +++ b/include/ceres/problem.h @@ -189,8 +189,11 @@ class CERES_EXPORT Problem { // invocation Problem(Problem::Options()). Problem(); explicit Problem(const Options& options); + Problem(Problem&&) = default; + Problem& operator=(Problem&&) = default; + Problem(const Problem&) = delete; - void operator=(const Problem&) = delete; + Problem& operator=(const Problem&) = delete; ~Problem(); diff --git a/internal/ceres/problem_test.cc b/internal/ceres/problem_test.cc index 038600c37..b77952410 100644 --- a/internal/ceres/problem_test.cc +++ b/internal/ceres/problem_test.cc @@ -122,6 +122,24 @@ class TernaryCostFunction: public CostFunction { } }; + +TEST(Problem, MoveConstructor) { + Problem src; + double x; + src.AddParameterBlock(&x, 1); + Problem dst(std::move(src)); + EXPECT_TRUE(dst.HasParameterBlock(&x)); +} + +TEST(Problem, MoveAssignment) { + Problem src; + double x; + src.AddParameterBlock(&x, 1); + Problem dst; + dst = std::move(src); + EXPECT_TRUE(dst.HasParameterBlock(&x)); +} + TEST(Problem, AddResidualWithNullCostFunctionDies) { double x[3], y[4], z[5];