QVarLengthArray: add missing (size, value) ctor

Extend the corresponding test in tst_containerapisymmetry.

[ChangeLog][QtCore][QVarLengthArray] Added (size, value) constructor.

Fixes: QTBUG-102469
Change-Id: I4802eebe6ba1a6835e4d6f41e1d3db2a0d7c7894
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2022-04-11 17:08:42 +02:00
parent 7a7023b7b1
commit ef895869b4
3 changed files with 33 additions and 0 deletions

View File

@ -286,6 +286,15 @@ public:
inline explicit QVarLengthArray(qsizetype size);
#ifndef Q_QDOC
template <typename U = T, if_copyable<U> = true>
#endif
explicit QVarLengthArray(qsizetype sz, const T &v)
: QVarLengthArray{}
{
resize(sz, v);
}
QVarLengthArray(const QVarLengthArray &other)
: QVarLengthArray{}
{

View File

@ -105,6 +105,18 @@
\l{default-constructed value}.
*/
/*!
\fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(qsizetype size, const T &v)
\since 6.4
Constructs an array with an initial size of \a size elements filled with
copies of \a v.
\note This constructor is only available when \c T is copy-constructible.
\sa size(), squeeze()
*/
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(std::initializer_list<T> args)
\since 5.5

View File

@ -750,6 +750,18 @@ void tst_ContainerApiSymmetry::resize_impl() const
c.resize(4, V(5));
QCOMPARE(c.size(), S(4));
QCOMPARE(c.back(), V(5));
// ctor/resize symmetry:
{
Container c1(S(5), V(4));
QCOMPARE(c1.size(), S(5));
Container c2;
c2.resize(S(5), V(4));
QCOMPARE(c2.size(), S(5));
QCOMPARE(c1, c2);
}
}
template <typename Container>