@@ -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());
@@ -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
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(+)