From d8b75f6bd0032456a3ee7d6a5a21646f65ef8e25 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Sat, 25 Jan 2025 15:50:51 -0500 Subject: [PATCH] Move constructors --- gtsam/base/VerticalBlockMatrix.h | 43 ++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/gtsam/base/VerticalBlockMatrix.h b/gtsam/base/VerticalBlockMatrix.h index 0ff8a8ae2..741d0e4bf 100644 --- a/gtsam/base/VerticalBlockMatrix.h +++ b/gtsam/base/VerticalBlockMatrix.h @@ -57,13 +57,46 @@ namespace gtsam { DenseIndex blockStart_; ///< Changes apparent matrix view, see main class comment. public: - /** Construct an empty VerticalBlockMatrix */ - VerticalBlockMatrix() : - rowStart_(0), rowEnd_(0), blockStart_(0) - { + VerticalBlockMatrix() : rowStart_(0), rowEnd_(0), blockStart_(0) { variableColOffsets_.push_back(0); - assertInvariants(); + } + + // Destructor + ~VerticalBlockMatrix() = default; + + // Copy constructor (default) + VerticalBlockMatrix(const VerticalBlockMatrix& other) = default; + + // Copy assignment operator (default) + VerticalBlockMatrix& operator=(const VerticalBlockMatrix& other) = default; + + // Move constructor + VerticalBlockMatrix(VerticalBlockMatrix&& other) noexcept + : matrix_(std::move(other.matrix_)), + variableColOffsets_(std::move(other.variableColOffsets_)), + rowStart_(other.rowStart_), + rowEnd_(other.rowEnd_), + blockStart_(other.blockStart_) { + other.rowStart_ = 0; + other.rowEnd_ = 0; + other.blockStart_ = 0; + } + + // Move assignment operator + VerticalBlockMatrix& operator=(VerticalBlockMatrix&& other) noexcept { + if (this != &other) { + matrix_ = std::move(other.matrix_); + variableColOffsets_ = std::move(other.variableColOffsets_); + rowStart_ = other.rowStart_; + rowEnd_ = other.rowEnd_; + blockStart_ = other.blockStart_; + + other.rowStart_ = 0; + other.rowEnd_ = 0; + other.blockStart_ = 0; + } + return *this; } /** Construct from a container of the sizes of each vertical block. */