[PATCH v3 04/17] ipa: libipa: vector: Add copy constructor and assignment operator
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Tue Nov 19 09:38:33 CET 2024
Hi Barnabás,
On Mon, Nov 18, 2024 at 11:30:12PM +0000, Barnabás Pőcze wrote:
> 2024. november 18., hétfő 23:16 keltezéssel, Laurent Pinchart írta:
>
> > 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 at ideasonboard.com>
> > Reviewed-by: Milan Zamazal <mzamazal at redhat.com>
> > ---
> > Changes since v2:
> >
> > - Make copy constructor constexpr
> > - Drop #include <algorithm>
> > ---
> > src/ipa/libipa/vector.cpp | 13 +++++++++++++
> > src/ipa/libipa/vector.h | 12 ++++++++++++
> > 2 files changed, 25 insertions(+)
> >
> > diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp
> > index d414ba97e41e..80f1758578f0 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 be568eadfeac..35fc9539dc99 100644
> > --- a/src/ipa/libipa/vector.h
> > +++ b/src/ipa/libipa/vector.h
> > @@ -46,6 +46,18 @@ public:
> > data_[i] = data[i];
> > }
> >
> > + constexpr Vector(const Vector &other)
> > + : data_(other.data_)
> > + {
> > + }
> > +
> > + Vector &operator=(const Vector &other)
> > + {
> > + data_ = other.data_;
> > +
> > + return *this;
> > + }
>
> Why not `... = default` in both cases? It seems to me that
> the compiler generated functions would be appropriate.
I will give it a try in v4.
> > +
> > const T &operator[](size_t i) const
> > {
> > ASSERT(i < data_.size());
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list