From f4101f9953ec63ee09e73b4b72bf6ed561d7568f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 25 Sep 2023 11:08:51 -0700 Subject: QString/QBA: add lvalue and rvalue overloads to first/last/sliced/chopped MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Those ought to have been the original implementation, when they were added in commit 38096a3d7040edac4f769270d2402ff4e39d7694, for Qt 6.0. Because these classes are exported, we need to provide the previous only implementations for MSVC. All other compilers would provide inline or emit local, out-of-line copies. Change-Id: Ifeb6206a9fa04424964bfffd178836a2ae56157d Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qarraydatapointer.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/corelib/tools/qarraydatapointer.h') diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h index 201f3e665dd..2fbd6c75059 100644 --- a/src/corelib/tools/qarraydatapointer.h +++ b/src/corelib/tools/qarraydatapointer.h @@ -413,6 +413,26 @@ public: size = dst - begin(); } + QArrayDataPointer sliced(qsizetype pos, qsizetype n) const & + { + QArrayDataPointer result(n); + std::uninitialized_copy_n(begin() + pos, n, result.begin()); + result.size = n; + return result; + } + + QArrayDataPointer sliced(qsizetype pos, qsizetype n) && + { + if (needsDetach()) + return sliced(pos, n); + T *newBeginning = begin() + pos; + std::destroy(begin(), newBeginning); + std::destroy(newBeginning + n, end()); + setBegin(newBeginning); + size = n; + return std::move(*this); + } + // forwards from QArrayData qsizetype allocatedCapacity() noexcept { return d ? d->allocatedCapacity() : 0; } qsizetype constAllocatedCapacity() const noexcept { return d ? d->constAllocatedCapacity() : 0; } -- cgit v1.2.3