[v4,04/17] ipa: libipa: vector: Add copy constructor and assignment operator
diff mbox series

Message ID 20241119121928.30939-5-laurent.pinchart@ideasonboard.com
State New
Headers show
Series
  • Improve linear algebra helpers in libipa
Related show

Commit Message

Laurent Pinchart Nov. 19, 2024, 12:19 p.m. UTC
It is useful to assign a value to an existing vector. Define a copy
constructor and a copy assignment operator.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
---
Changes since v3:

- Default both functions

Changes since v2:

- Make copy constructor constexpr
- Drop #include <algorithm>
---
 src/ipa/libipa/vector.cpp | 13 +++++++++++++
 src/ipa/libipa/vector.h   |  4 ++++
 2 files changed, 17 insertions(+)

Patch
diff mbox series

diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp
index 5851b9ae2ed3..a9779fa2b8e2 100644
--- a/src/ipa/libipa/vector.cpp
+++ b/src/ipa/libipa/vector.cpp
@@ -46,6 +46,19 @@  namespace ipa {
  * The size of \a data must be equal to the dimension size Rows of the vector.
  */
 
+/**
+ * \fn Vector::Vector(const Vector &other)
+ * \brief Construct a Vector by copying \a other
+ * \param[in] other The other Vector value
+ */
+
+/**
+ * \fn Vector &Vector::operator=(const Vector &other)
+ * \brief Replace the content of the Vector with a copy of the content of \a other
+ * \param[in] other The other Vector value
+ * \return This Vector value
+ */
+
 /**
  * \fn T Vector::operator[](size_t i) const
  * \brief Index to an element in the vector
diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h
index 5fb7ad7c95dd..1022550e6170 100644
--- a/src/ipa/libipa/vector.h
+++ b/src/ipa/libipa/vector.h
@@ -46,6 +46,10 @@  public:
 			data_[i] = data[i];
 	}
 
+	constexpr Vector(const Vector &other) = default;
+
+	Vector &operator=(const Vector &other) = default;
+
 	const T &operator[](size_t i) const
 	{
 		ASSERT(i < data_.size());