summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qvarlengtharray.h
Commit message (Collapse)AuthorAgeFilesLines
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QVarLengthArray: Move unique_ptr<void, free_deleter> to QVLABaseBaseMarc Mutz2022-05-131-4/+6
| | | | | | | | | | | | | | | | | This avoids repeated re-instantiations of unique_ptr with local deleters, removing that instantiation from the top of the list in Clang -ftime-trace QtWidgets builds: **** Templates that took longest to instantiate: 2627 ms: std::__1::unique_ptr<void, free_deleter> (835 times, avg 3 ms) Amends e297e80fd0ec6ce4c97ee1b40426c76377b45ecc. Pick-to: 6.3 Task-number: QTBUG-97601 Task-number: QTBUG-99039 Change-Id: I1281f6cf9248a3796d9dfdc653f19f5a67dc3bda Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVarLengthArray: add missing (size, value) ctorMarc Mutz2022-04-131-0/+9
| | | | | | | | | | | 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>
* QVarLengthArray: simplify SFINAE on resize(n, v)Marc Mutz2022-04-131-6/+6
| | | | | | | | | | | | 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 a00a1d8806cfbf17e04b88d1b4ff4a9cf5b6294a. Change-Id: I846b96bdeec3def221346897181d3d4d3a55316d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QByteArray/QVarLengthArray: add missing resize(n, v) overloadsMarc Mutz2022-04-061-5/+22
| | | | | | | | | | | | | | | | | | QList and QString had them, so add them to QByteArray and QVarLengthArray, too. In the QVLA case, we need to jump though a hoop or two to avoid having to duplicate all the reallocation logic. Nothing a few template tricks cannot solve. [ChangeLog][QtCore][QByteArray] Added resize(n, ch) overload. [ChangeLog][QtCore][QVarLengthArray] Added resize(n, v) overload. Fixes: QTBUG-102270 Change-Id: I0d281ae5b574f440f682e4a62427b434dcf5b687 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QVarLengthArray: avoid std::aligned_storage (deprecated in C++23)Marc Mutz2021-12-151-1/+9
| | | | | | | | | | | | | | | | | Add some scaffolding to prevent us from running into BC issues due to the underspecified nature of std::aligned_storage. Qt 5.15 uses a union { char[], double, qint64 } instead of std::aligned_storage, so doesn't need the fix. References: - https://github.com/cplusplus/papers/issues/197 - wg21.link/p1413 Task-number: QTBUG-99122 Pick-to: 6.3 6.2 Change-Id: I212be7000376c2db33b8cb244a6e862cc4dad544 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QVarLengthArray: don't allow syncqt to export base classesMarc Mutz2021-12-151-0/+5
| | | | | | | | Check, in tst_qvarlengtharray, that the forwarding header still works. Pick-to: 6.3 Change-Id: Ia03cf48457f538287880bb676aea3fa44aeb255f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QVarLengthArray: assert that the range passed to erase() is validMarc Mutz2021-12-111-0/+2
| | | | | | | | | | | | | | | | We already checked that the two iterators, indvidually, are valid, but we didn't check that the range formed by them is valid, namely that the end iterator is reachable from the start iterator. Add an assert, because if the range isn't valid, we run into UB in the std::move() algorithm two lines later. Qt 5.15 uses std::copy() here, which has the same precondition, so the assertion would make sense there, too. Pick-to: 6.2 5.15 Change-Id: I90b7e846455ff86383a8971bea908036684961d8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QVLA: separate control from inline storage [11/11]: qHash()Marc Mutz2021-12-111-2/+6
| | | | | | | | | | | | | A previous attempt to make qHash() a hidden friend ran into an ICE on Clang, so to simplify the implementation, QVLABase::hash() is public for now. Use QtPrivate::QNothrowHashable_v to simplify the noexcept clauses. Fixes: QTBUG-84785 Change-Id: Ibb520bde7b1d6dc45846bd8e1fa27c39c401b96a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVLA: separate control from inline storage [10/N]: range-insert()Marc Mutz2021-12-111-5/+10
| | | | | | | | | Also added a QVLABase::resize_impl() because insert(it, n, v) was the only function moved down into QVLABase to call resize(). Task-number: QTBUG-84785 Change-Id: I5dd0092216d73b28b957a01845325d744a5c0ba9 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVLA: separate control from inline storage [9/N]: range-append()Marc Mutz2021-12-111-4/+6
| | | | | | | Task-number: QTBUG-84785 Change-Id: Ieca9b3b8608b9500393d2d9d1910380799aba2ea Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QVLA: separate control from inline storage [8/N]: emplace()Marc Mutz2021-12-111-4/+7
| | | | | | | | | | Moving emplace() takes care of the bulk of insert()-like operations in QVarLengthArray. What's missing now is just the pseudo-ranged insert(i, n, x) and append(ptr, n) operations. Task-number: QTBUG-84785 Change-Id: I8be7f50ecab3de79b617436c46d3feec065b4f88 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVLA: separate control from inline storage [7/N]: erase{,_if}()Marc Mutz2021-12-111-2/+2
| | | | | | | | | | | Implement erase()/erase_if() using removeAll()/removeIf() These functions are now on QVLABase, so we no longer instantiate a different sequential_erase{,_if}() per Prealloc. Task-number: QTBUG-84785 Change-Id: I339759bc02b0e3104f7d1273ce6d5e09b493610c Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVLA: separate control from inline storage [6/N]: emplace_back()Marc Mutz2021-12-111-1/+12
| | | | | | | | Move emplace_back() down from QVarLengthArray to QVLABase. Task-number: QTBUG-84785 Change-Id: I29020737007f245c3b52fd7960369262510c0d52 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVLA: separate control from inline storage [5/N]: Move reallocate()Marc Mutz2021-12-111-12/+15
| | | | | | | | | | | This is the core of QVarLengthArray. To move it down into QVLABase, we need to pass Prealloc and this->array as additional function arguments. Task-number: QTBUG-84785 Change-Id: I082fa4ef957fcde7b8fcc3ca421621aa01ba5d59 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVLA: separate control from inline storage [4/N]: cleanup castsMarc Mutz2021-12-111-9/+10
| | | | | | | | | | Remove some reinterpret_casts that became useless when we ported 'ptr' to be a 'void*'. Task-number: QTBUG-84785 Change-Id: I886304da50e18152abc664d2adf094617c37887f Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVLA: separate control from inline storage [3/N]: Extract Further Base ClassMarc Mutz2021-12-111-10/+17
| | | | | | | | | | | | | It turns out that some functionality (most prominently, the verify() function that contains the asserts), depends on nothing but the size member, so Extract QVLABaseBase, a non-template class, to hold the data members, and the size()- and capacity()-related member functions. Task-number: QTBUG-84785 Change-Id: Ic21855fd6147b67507c122b6f091b44a3ba997f5 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVLA: separate control from inline storage [2/N]: Move Up Methods [3/3]Marc Mutz2021-12-111-3/+22
| | | | | | | | | | | | Move the remaining methods to the QVLABase base class that can be moved, being those which do not depend on QVLAStorage::array. Include the relational operators this time around. Task-number: QTBUG-84785 Change-Id: I0f22b076791496833cba033c1be2a69ec8b129a1 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVLA: separate control from inline storage [2/N]: Move Up Methods [2/3]Marc Mutz2021-12-111-22/+62
| | | | | | | | | | | | | Move all methods to the QVLABase base class that can be moved, being those which do not depend on QVLAStorage::array. Skip relational operators for the time being, but move the methods which are defined out-of-line now. Task-number: QTBUG-84785 Change-Id: I355c0581f74d79d9bae37861b32d795ddcb2fb69 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVLA: separate control from inline storage [2/N]: Move Up Methods [1/3]Marc Mutz2021-12-111-41/+151
| | | | | | | | | | | | | | | | | | Move all methods to the QVLABase base class that can be moved, being those which do not depend on QVLAStorage::array. Skip relational operators for the time being, as well as the methods which are defined out-of-line. Keep the old definitions around as long as qdoc cannot, yet, associate derived-class \fn with base-class definitions, via using-declarations. We don't want to export the QVLABase class in the docs. Task-number: QTBUG-84785 Change-Id: Ic61e6029e07faca5be99d7e2e197d5bc7fe74c4e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QVarLengthArray: deprecate prepend()Marc Mutz2021-12-111-0/+6
| | | | | | | | | | | | | | | | All Qt 6 containers have "fast" prepend these days. Except QVLA. Instead of enabling "fast" prepend for QVLA, slowing down idiomatic QVLA use, simply deprecate prepend(). There appear to be no users of this function in qtbase outside tests. [ChangeLog][QtCore][Deprecation Notices][QVarLengthArray] Deprecated prepend() because QVarLengthArray is the only Qt container without a "fast" prepend. If you require that functionality, even though it's a linear operation, then use insert(cbegin(), ~~~) instead. Change-Id: I39ff1dd7d4de7fc08d5380a5a7450dd8c8996fe2 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVarLengthArray: widen append(p, n)'s contractMarc Mutz2021-12-101-1/+1
| | | | | | | | | | | | | | | It's a bit weird that the (counted-)range-append() allows n < 0, but requires p != nullptr even when n == 0. Fix by allowing p == nullptr iff n == 0. [ChangeLog][QtCore][QVarLengthArray] The counted-range-append() function (append(ptr, n)) now accepts ptr == nullptr, provided n == 0, too (was: triggered assertion). Pick-to: 6.2 Change-Id: Ifb97170a930e97cb8f4194282cada0faf820cc53 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVarLengthArray: fix UB (precondition violation) in range-erase()Marc Mutz2021-12-101-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When the range-erase() function is called with an empty, valid range, it passed equal iterators to both the first and the last arguments of std::move(f, l, d) (the algorithm, not the cast). This is UB, since it violates the algorithm's precondition that d ∉ [f,l). For non-empty ranges, f > d, thus d < f, hence d ∉ [f,l), so everything is ok _there_. Fix the empty range case by returning early. Reviewers may question the precondition, expecting that std::move(f, l, f) just be a no-op, but the algorithm, as specified, performs self-move-assignments in that case, which need not be supported. In fact, the Hinnant criterion, itself only applicable if one calls for self-swap-safety, asks for self-move-assignment-safety only for objects in the moved-from state. QVarLengthArray, itself, meets only the Hinnant criterion; self-move-assignment of non-empty QVLAs invokes UB. So, the UB here is real. Qt 5.15 uses std::copy() here, which has the same precondition as std::move(), and the same fix applies there, too. [ChangeLog][QtCore][QVarLengthArray] Fixed a bug where range-erase() could invoke undefined behavior when called with an empty range. Pick-to: 6.2 5.15 Change-Id: I656aa09d025168d6d9ef088ad4c6954d216f0d54 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QVLA: separate control from inline storage [1/N]: Extract Base ClassesMarc Mutz2021-12-091-35/+54
| | | | | | | | | | | | | | | | | | In this first patch of the series, we move the fields (a, s, ptr) and (array) into each their base class, separating concerns: The QVLABase class is independent of Prealloc, while the QVLAStorage class is independent of T (only depends on Prealloc, alignof(T) and sizeof(T), and that can probably be reduced even further in later patches, since we ought to need only alignof(T) and sizeof(T) * Prealloc, and alignment can be substituted with std::max_align_t). Doing so while keeping all member functions on QVLA, however, means we need to sprinkle 'this->' in front of every data member access. C'est la vie. Task-number: QTBUG-84785 Change-Id: Iafbf97f41b9743b6dc2bfc13f3486d73e854b7cf Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVarLengthArray: make reallocation strongly exception safeMarc Mutz2021-12-091-26/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The old code had several bugs: - it immediately clobbered *this with new state, before having copied over the elements from the old to the new buffer - when buffer relocation threw, it would keep the new (partially-filled) buffer and throw away the old - it unconditionally used std::move() for non-relocatable types, making it impossible to restore the original buffer when a move throws Instead of clobbering *this with new state, do all the work on the side and change *this only once the reallocation has happened successfully. Also use q_uninitialized_relocate_n() and unique_ptr in the implementation to simplify the code. The former got the necessary update to use std::move_if_noexcept() instead of an unconditional std::move() for the non-relocatable case. [ChangeLog][QtCore][QVarLengthArray] The append()-like functions are now strongly exception safe. This means reallocation will now use copies instead of moves, unless the value_type has a noexcept move constructor. Fixes: QTBUG-99039 Change-Id: I031251b8d14ac045592d01caed59d4638c3d9892 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVarLengthArray: implement append() via emplace_back()Marc Mutz2021-12-091-12/+5
| | | | | | | | Less code duplication, means less functions to move into the upcoming QVLABase. Change-Id: I67a817c971a4e5a81ae45ff30282878be1bde2aa Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVarLengthArray: inline some trivial reallocate() wrappersMarc Mutz2021-12-091-15/+3
| | | | | | | | | | | These functions don't deserve to be defined outside the class body, as they're trivial wrappers around reallocate(). Cleans up the header somewhat, in preparation of the upcoming QVLABase/QVLAStorage split. Change-Id: Ib4062eca4214a67e67f472a7c1e4bf4d9813c8a4 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVarLengthArray: use C++14 4-arg std::equal()Marc Mutz2021-12-091-6/+1
| | | | | | | | | Simplifies the code, since we now need neither the manual size check, nor the warning fix (checked iterator macro) for MSVC. Change-Id: Ic267c66eb4568d2db8d9c9ccad0ce7e1a5cc3373 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVarLengthArray: fix size update on failed append()Marc Mutz2021-12-081-6/+5
| | | | | | | | | | | | | If the in-place constructor throws, the old code had already updated the container's size(). Fix by delaying the update to after the in-place construction. [ChangeLog][QtCore][QVarLengthArray] Fixed a bug whereby a failed append() would leave the container with an inconsistent size(). Pick-to: 6.2 5.15 Change-Id: Ief1e668d945149bd8ba96c8af1398baaa7876880 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVarLengthArray: remove unneeded copy in replace()Marc Mutz2021-12-071-3/+2
| | | | | | | | | | | | | | | QVarLengthArray is neither implicitly shared, nor does it feature a magic resize() on out-of-bounds. Therefore, data() doesn't detach(), so 't' remains stable. The only reason for the copy, then, would be if T wasn't self-assignment-safe, but we don't support such types. Remove the copy. Change-Id: I8dd12e1c9b8131ae17d641354fe362554062b78d Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVarLengthArray: don't mix iterator/const_iterator in offset calcMarc Mutz2021-12-071-4/+4
| | | | | | | | | | | | The functions aren't const so begin() will return a mutable iterator. The function arguments, however, are const_iterators. It doesn't matter for QVLA, which isn't implicitly shared, but code hygiene suggests to use cbegin() instead, to compare const_iterators to const_iterators. Change-Id: I9bfa993780ee4b68d13f6b6410772b0f1ccedad3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVarLengthArray: port internal users from at() to op[]Marc Mutz2021-12-071-2/+2
| | | | | | | | | In preparation of splitting the class into QVLABase and QVLAStorage. Task-number: QTBUG-84785 Change-Id: Ic0da6c2e110a5b979b78989616b9a2cb0f27463b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVarLengthArray: merge remove(idx [,n]) into one functionMarc Mutz2021-12-071-6/+1
| | | | | | | | remove(i) is the same as remove(i, 1), and the extra 'n' argument is of trivial type, so it's ok to default it instead of overloading. Change-Id: Id926cd63fde518e002684a41e055edc1004247a4 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVarLengthArray: centralize index checkingMarc Mutz2021-12-071-13/+22
| | | | | | | | | Factor the assertions relating to sizes and indexes into an inline function, verify(). This hopefully reduces the string data generated for assertions to the bare minimum. Change-Id: Iad5c2e587ad189e7e1a62b9ca61ada4282c44f51 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QVarLengthArray: make static if's constexprMarc Mutz2021-12-021-5/+5
| | | | | | | | | | | Cleaner. Probably also more efficient at compile time, who knows? Also more consistent, since _some_ static if's were already constexpr'ed. Change-Id: I9657f7cf2166975f562db52e9f90630aaf412986 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVarLengthArray: More Self-Encapsulate FieldMarc Mutz2021-12-011-3/+5
| | | | | | | | | | | Two more instances where we can use public API instead of accessing the data members directly. Amends 9d79e5f26ca58e7ddbb6367de044d05192107a4d. Task-number: QTBUG-84785 Change-Id: I2037339383836b0d292b3362fe1d6b056638e81a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QVarLengthArray: simplify default ctorMarc Mutz2021-12-011-1/+4
| | | | | | | | | | | | Instead of calling the QVLA(qsizetype) ctor and letting the optimizer and inliner have a field day on them, simply set the trivial values for a, s, and ptr manually. Mark it as noexcept. Task-number: QTBUG-84785 Change-Id: I011826eacdaf63a4c37b21465e5fe4a6e70a1ab7 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVarLengthArray: simplify copy ctor implementationMarc Mutz2021-11-301-2/+2
| | | | | | | | | | | | std::tie(a, s, ptr) = {Prealloc, 0, (T*)array} is exactly the effects of the default ctor, so just delegate to it, before calling copyAppend(). Also clean up the copy ctor declaration (superfluous inline keyword, and template arguments). Change-Id: Iefc758a47996382fee10b1e081e44f008b146287 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QVarLengthArray: fix insert() type/alias mismatch between decl and implMarc Mutz2021-11-261-1/+1
| | | | | | | | | | | | | | | | | The declaration of insert(it, n, t) used qsizetype for n, while the definition used size_type. That works by chance, because the size_type typedef comes only after the insert(it, n, t) declaration. It was detected when size_type became a typedef in a base class of QVarLengthArray in my local branch. Just use the same type name in the implementation as in the declaration. In 5.15, the same issue exists (with s/qsizetype/int/). Pick-to: 6.2 5.15 Change-Id: I64235eeaeaed3d43f4c070ca536474fae94c1b5d Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QVLA: Self-Encapsulate FieldsMarc Mutz2021-11-221-97/+97
| | | | | | | | | | | | | | | | Use member functions to access some (combinations of) fields in preparation of moving said fields to base classes: s + ptr → end() s → size() ptr → data() (or begin(), depending on context) a → capacity() Fixed a const-incorrectness issue detected by the change. Task-number: QTBUG-84785 Change-Id: I2218d57559208c9d77b8860d419979e92f140e13 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QVarLengthArray: Add explicit assertions for implicit assumptionsRobert Löhning2021-10-291-0/+2
| | | | | | | Change-Id: I4dfbf6174483b4af91f31a05c18cfec2aaec6e1f Pick-to: 6.2 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QVarLengthArray: Reduce memory allocations in emplace()Robert Löhning2021-10-231-1/+2
| | | | | | | | | | | | | | | | Currently, we allocate memory for elements one by one which can get pretty slow when adding many elements. [ChangeLog][QtCore][QVarLengthArray] Reduced number of memory allocations in emplace() by allocating more memory at once. Fixes: QTBUG-97489 Pick-to: 6.2 Change-Id: Idfb5b5946b047d5215c8ed00770574249f9f5d40 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove checks for features available in C++17Ievgenii Meshcheriakov2021-10-021-2/+0
| | | | | | | | | | This patch removes most of the checks that are made using C++20 __cpp_* macros for features available in C++17 and earlier. Library feature check macros (__cpp_lib_*) are unaffected. Change-Id: I557b2bd0d4ff09b13837555e9880eb28e0355f64 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QVarLengthArray: add support for emplacementMarc Mutz2021-08-161-5/+11
| | | | | | | | | | | | | Take the rvalue insert() function and turn it into the emplace() function. Reformulate rvalue-insert using emplace(). Lvalue insert() is using a different code path, so leave that alone. This way, we don't need to go overboard with testing. [ChangeLog][QtCore][QVarLengthArray] Added emplace(), emplace_back(). Change-Id: I3e1400820ae0dd1fe87fd4b4c518f7f40be39f8b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QVarLengthArray: fix aliasing error in insert(it, n, v)Marc Mutz2021-06-281-1/+1
| | | | | | | | | | | | | | | | | Taking the copy after the resize is completely pointless: the copy is there to ensure that `t`, being a reference potentially aliasing an element in [begin(), end()[ before the resize(), isn't invalidated by the resize(), so it must be taken before resize(). Add a comment so the next rewrite doesn't cause this to be mixed up again. [ChangeLog][QtCore][QVarLengthArray] Fixed an aliasing bug affecting insertions of objects aliasing existing elements. Pick-to: 6.2 6.1 6.0 5.15 5.12 Change-Id: I26bc449fa99bf8d09a19147a12a69ac4314cc61d Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* QVLA: add a Q_ASSERTGiuseppe D'Angelo2021-01-201-0/+1
| | | | | | | | | | GCC's -fanalyzer complains that `ptr` might be null. It's actually never null (by class invariant). Change-Id: I5660b1e766b2cfde3f042b8e87168987e7618591 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Sequential general purpose containers: add erase/erase_ifGiuseppe D'Angelo2020-12-011-0/+30
| | | | | | | | | | | | | | | | | | | | This is refactor/revisit for Qt 6 of the original commit [1] by Marc, limited to QList and QVLA. [1] see 11aa9a2276ba5367adbbd96d0ba13111d58145f8 [ChangeLog][QtCore][QList] Added erase() and erase_if(), for consistent container erasure. Added removeIf() as a method, complementing removeOne() / removeAll(). [ChangeLog][QtCore][QVarLengthArray] Added erase() and erase_if(), for consistent container erasure. Added removeIf() as a method, complementing removeOne() / removeAll(). Change-Id: I2499504e221431ead754dd64cc8a4d4e9f116183 Done-by: Marc Mutz Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QVLA: modernize some codeGiuseppe D'Angelo2020-11-261-25/+16
| | | | | | | | | | Use if constexpr instead of plain if; use C++17 algorithms instead of hand-rolled loops. Change-Id: Ifa092f892199b9b21bad04b2d72d5e3117a1b377 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* QVLA: always use new to create new objectsGiuseppe D'Angelo2020-11-261-14/+3
| | | | | | | | | | | Even for non-complex types, it makes no sense to use the assignment operator instead of placement new when constructing new objects. Pick-to: 6.0 5.15 Change-Id: I5f15fe4b3397cf52d1d35e6c4dcc513b94b3cf14 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Don't allow storing types that throw in the destructor in our containersLars Knoll2020-11-171-0/+2
| | | | | | | | | | | | | | | | | | | | | | Types that throw in their destructors are strongly discouraged in C++, and even the STL doesn't define what happens if such types are stored in their containers. Make this more explicit for Qt and disallow storing those types in our containers. This will hopefully preempty any potential future bug reports about us not handling such a case. It also helps simplify some code in QList and other cases and makes it possible to explicitly mark more methods as noexcept. Some care needs to be taken where to add the static asserts, so that we don't disallow forward declarations of types stored in containers. Place the static assert into the destructor of the container where possible or otherwise into the templated d-pointer. Change-Id: If3aa40888f668d0f1b6c6b3ad4862b169d31280e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>