diff options
author | Kai Koehne <kai.koehne@theqtcompany.com> | 2015-03-18 09:28:59 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@theqtcompany.com> | 2015-03-23 08:13:42 +0000 |
commit | d3659bf88bac8dbfcdc6c957bdcc25e29bef0f04 (patch) | |
tree | 93b7823a2fc198d47441610592238b039101b2ab /src/corelib/tools/qvarlengtharray.h | |
parent | 5c379f3ff0471c51827577d047c93bab88ad44ce (diff) |
QVarLengthArray: Add initializer_list constructor
Implement an initializer_list constructor, which was probably
just forgotten so far. Technically this is a SC incompatible change,
since
QVarLengthArray<int> array = {10};
will now create an array with one element 10, instead of an empty array
with a reserved size of 10. Anyhow, keeping the inconsistency with the
STL / other Qt containers here would certainly do more harm than good
in the long run.
Task-number: QTBUG-45047
Change-Id: I4675880f93e141181250939942fa32300916b0e3
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/corelib/tools/qvarlengtharray.h')
-rw-r--r-- | src/corelib/tools/qvarlengtharray.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 54d97d8762..32f621c809 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -42,6 +42,9 @@ #include <string.h> #include <stdlib.h> #include <algorithm> +#ifdef Q_COMPILER_INITIALIZER_LISTS +#include <initializer_list> +#endif QT_BEGIN_NAMESPACE @@ -62,6 +65,14 @@ public: append(other.constData(), other.size()); } +#ifdef Q_COMPILER_INITIALIZER_LISTS + QVarLengthArray(std::initializer_list<T> args) + : a(Prealloc), s(0), ptr(reinterpret_cast<T *>(array)) + { + append(args.begin(), args.size()); + } +#endif + inline ~QVarLengthArray() { if (QTypeInfo<T>::isComplex) { T *i = ptr + s; |