[PATCH v3 04/17] ipa: libipa: vector: Add copy constructor and assignment operator

Laurent Pinchart laurent.pinchart at ideasonboard.com
Tue Nov 19 17:41:17 CET 2024


On Tue, Nov 19, 2024 at 02:07:24PM +0000, Barnabás Pőcze wrote:
> 2024. november 19., kedd 9:38 keltezéssel, Laurent Pinchart írta:
> > 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.
> 
> Sorry, I have just now realized that these functions should already be implicitly
> defined with the ` = default` definition, so there is probably no need to define
> them at all unless I am missing something.

You're right. I'll just drop this patch.

> > > > +
> > > >  	const T &operator[](size_t i) const
> > > >  	{
> > > >  		ASSERT(i < data_.size());

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list