summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2024-02-14 09:52:22 +0100
committerMarc Mutz <marc.mutz@qt.io>2024-02-15 17:44:36 +0000
commitaf051f9be230f06eba587c25d56837fb48fcc9ee (patch)
treed36b547eec6c83b4dd43895c8cf56f440715f483 /tests/auto/corelib/tools
parente703feea40108cdd11f8f0270cc82c2aa0e691cd (diff)
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 <typename T> constexpr qsizetype preallocated_size_v; template <typename T, qsizetype N> constexpr qsizetype preallocated_size_v<QVarLengthArray<T,N>> = N; first. [ChangeLog][QtCore][QVarLengthArray] Added PreallocatedSize nested constant, equal to the Prealloc template argument. Change-Id: I928eaa5e62967445cdd7b0c2759567483fdb8997 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp10
1 files changed, 10 insertions, 0 deletions
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<QString>(); }
void sizeConstructor_NonCopyable() { sizeConstructor<NonCopyable>(); }
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<int>::PreallocatedSize == 256);
+ // Otherwise, whatever was given as template argument:
+ static_assert(QVarLengthArray<int, 42>::PreallocatedSize == 42);
+ static_assert(QVarLengthArray<int, 1'000'000>::PreallocatedSize == 1'000'000);
+}
+
#if QT_DEPRECATED_SINCE(6, 3)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED