QVarLengthArray: simplify SFINAE on resize(n, v)

Use our usual if_x<> = true pattern to move the constraint to where it
belongs (absent C++20 requires-clauses): into the template argument
list.

Amends a00a1d8806.

Change-Id: I846b96bdeec3def221346897181d3d4d3a55316d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
bb10
Marc Mutz 2022-04-11 21:35:24 +02:00
parent acb9633efa
commit b36de79ffd
1 changed files with 6 additions and 6 deletions

View File

@ -260,6 +260,9 @@ class QVarLengthArray
using Storage = QVLAStorage<sizeof(T), alignof(T), Prealloc>;
static_assert(std::is_nothrow_destructible_v<T>, "Types with throwing destructors are not supported in Qt containers.");
using Base::verify;
template <typename U>
using if_copyable = std::enable_if_t<std::is_copy_constructible_v<U>, bool>;
public:
using size_type = typename Base::size_type;
using value_type = typename Base::value_type;
@ -393,13 +396,10 @@ public:
}
bool isEmpty() const { return empty(); }
void resize(qsizetype sz) { Base::resize_impl(Prealloc, this->array, sz); }
#ifdef Q_QDOC
void
#else
template <typename U = T>
std::enable_if_t<std::is_copy_constructible_v<U>>
#ifndef Q_QDOC
template <typename U = T, if_copyable<U> = true>
#endif
resize(qsizetype sz, const T &v)
void resize(qsizetype sz, const T &v)
{ Base::resize_impl(Prealloc, this->array, sz, &v); }
inline void clear() { resize(0); }
void squeeze() { reallocate(size(), size()); }