summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Klug <stefan.klug@ideasonboard.com>2025-04-03 17:49:09 +0200
committerStefan Klug <stefan.klug@ideasonboard.com>2025-05-20 09:46:12 +0200
commitbcba580546807c4b6e138300a410f1dc63fb02b9 (patch)
tree0ec4dc4b14d2f8f897cbd1a9fba01caac464b888
parentaca9042abdf3d01f436dea147a82d37923c0eda6 (diff)
libcamera: vector: Add a Span based constructor
When one wants to create a Vector from existing data, currently the only way is via std::array. Add a Span based constructor to allow creation from std::vectors and alike. While at it, replace the manual loop with std::copy. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
-rw-r--r--include/libcamera/internal/vector.h8
-rw-r--r--src/libcamera/vector.cpp8
2 files changed, 14 insertions, 2 deletions
diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h
index a67a0947..4e9ef1ee 100644
--- a/include/libcamera/internal/vector.h
+++ b/include/libcamera/internal/vector.h
@@ -42,8 +42,12 @@ public:
constexpr Vector(const std::array<T, Rows> &data)
{
- for (unsigned int i = 0; i < Rows; i++)
- data_[i] = data[i];
+ std::copy(data.begin(), data.end(), data_.begin());
+ }
+
+ constexpr Vector(const Span<const T, Rows> data)
+ {
+ std::copy(data.begin(), data.end(), data_.begin());
}
const T &operator[](size_t i) const
diff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp
index 85ca2208..5567d5b8 100644
--- a/src/libcamera/vector.cpp
+++ b/src/libcamera/vector.cpp
@@ -45,6 +45,14 @@ LOG_DEFINE_CATEGORY(Vector)
*/
/**
+ * \fn Vector::Vector(const Span<const T, Rows> data)
+ * \brief Construct vector from supplied data
+ * \param data Data from which to construct a vector
+ *
+ * The size of \a data must be equal to the dimension size Rows of the vector.
+ */
+
+/**
* \fn T Vector::operator[](size_t i) const
* \brief Index to an element in the vector
* \param i Index of element to retrieve