From af051f9be230f06eba587c25d56837fb48fcc9ee Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 14 Feb 2024 09:52:22 +0100 Subject: QVarLengthArray: re-publish Prealloc as a nested PreallocatedSize This gives users of the class easy access to the Prealloc template argument, without having to write a pattern-matcher like template constexpr qsizetype preallocated_size_v; template constexpr qsizetype preallocated_size_v> = N; first. [ChangeLog][QtCore][QVarLengthArray] Added PreallocatedSize nested constant, equal to the Prealloc template argument. Change-Id: I928eaa5e62967445cdd7b0c2759567483fdb8997 Reviewed-by: Volker Hilsheimer --- .../auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/auto/corelib/tools') diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp index dcee8fd705..6a92663bc4 100644 --- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp +++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp @@ -66,6 +66,7 @@ private slots: void sizeConstructor_QString() { sizeConstructor(); } void sizeConstructor_NonCopyable() { sizeConstructor(); } void append(); + void preallocatedSize(); #if QT_DEPRECATED_SINCE(6, 3) void prepend(); #endif @@ -194,6 +195,15 @@ void tst_QVarLengthArray::append() v2.append(5); } +void tst_QVarLengthArray::preallocatedSize() +{ + // The default is 256: + static_assert(QVarLengthArray::PreallocatedSize == 256); + // Otherwise, whatever was given as template argument: + static_assert(QVarLengthArray::PreallocatedSize == 42); + static_assert(QVarLengthArray::PreallocatedSize == 1'000'000); +} + #if QT_DEPRECATED_SINCE(6, 3) QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED -- cgit v1.2.3