[09/13] libcamera: vector: Convertor Constructor
diff mbox series

Message ID 20260407-kbingham-awb-split-v1-9-a39af3f4dc20@ideasonboard.com
State New
Headers show
Series
  • ipa: simple: Convert to libipa AWB implementation
Related show

Commit Message

Kieran Bingham April 7, 2026, 10:01 p.m. UTC
Extend the Vector class with a constructor to support casting to the
storage type when the given parameters are compatible.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 include/libcamera/internal/vector.h | 8 ++++++++
 src/libcamera/vector.cpp            | 7 +++++++
 2 files changed, 15 insertions(+)

Patch
diff mbox series

diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h
index 16b6aef0b38f4b094d83449b5cdb1ba48b17c2bf..d29547f170e37c15f85e46abca82f89c8995115d 100644
--- a/include/libcamera/internal/vector.h
+++ b/include/libcamera/internal/vector.h
@@ -51,6 +51,14 @@  public:
 		std::copy(data.begin(), data.end(), data_.begin());
 	}
 
+	template<typename U, std::enable_if_t<std::is_arithmetic_v<U> &&
+					      !std::is_same_v<T, U>> * = nullptr>
+	constexpr Vector(const Vector<U, Rows> &other)
+	{
+		for (unsigned int i = 0; i < Rows; i++)
+			data_[i] = static_cast<T>(other[i]);
+	}
+
 	const T &operator[](size_t i) const
 	{
 		ASSERT(i < data_.size());
diff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp
index 4dad1b9001c5df97f71031724729563cae0962c3..397e370fd023caef069095dc5abebe2d6d76848a 100644
--- a/src/libcamera/vector.cpp
+++ b/src/libcamera/vector.cpp
@@ -52,6 +52,13 @@  LOG_DEFINE_CATEGORY(Vector)
  * The size of \a data must be equal to the dimension size Rows of the vector.
  */
 
+/**
+ * \fn Vector::Vector(const Vector<U, Rows> &other)
+ * \brief Construct a vector by converting another vector's element type
+ * \tparam U The source vector element type
+ * \param[in] other The vector to convert from
+ */
+
 /**
  * \fn T Vector::operator[](size_t i) const
  * \brief Index to an element in the vector