Remove ExpressionRef Move Constructor

The move constructor and move =operator are not required. They make
the code more complex and prone to bugs. The few saved assignments
are all trivial and are optimized away by the compiler or our
optimizer.

In fact, there is a bug in the current move-constructor implementation
that occurs, for example, when moving Eigen matrices around.

Change-Id: I013796495bb39f3f27677111bd0aaf49e2454e20
This commit is contained in:
Darius Rueckert
2020-01-14 16:55:21 +01:00
parent f26f954105
commit 8def196166
3 changed files with 2 additions and 64 deletions
@@ -33,6 +33,7 @@
#define CERES_PUBLIC_EXPRESSION_REF_H_
#include <string>
#include "ceres/codegen/internal/expression.h"
#include "ceres/codegen/internal/types.h"
@@ -86,23 +87,6 @@ struct ExpressionRef {
ExpressionRef(const ExpressionRef& other);
ExpressionRef& operator=(const ExpressionRef& other);
// Similar to the copy assignment above, but if 'this' is uninitialized, we
// can remove the copy and therefore eliminate one expression in the graph.
// For example:
// T c;
// c = a + b;
// will generate
// v_2 = v_0 + v_1
// instead of an additional assigment from the temporary 'a + b' to 'c'. In
// C++ this concept is called "Copy Elision". This is used by the compiler to
// eliminate copies, for example, in a function that returns an object by
// value. We implement it ourself here, because large parts of copy elision
// are implementation defined, which means that every compiler can do it
// differently. More information on copy elision can be found here:
// https://en.cppreference.com/w/cpp/language/copy_elision
ExpressionRef(ExpressionRef&& other);
ExpressionRef& operator=(ExpressionRef&& other);
// Compound operators
ExpressionRef& operator+=(const ExpressionRef& x);
ExpressionRef& operator-=(const ExpressionRef& x);