summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qarraydatapointer.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-09-25 11:08:51 -0700
committerThiago Macieira <thiago.macieira@intel.com>2023-10-25 12:01:58 -0700
commitf4101f9953ec63ee09e73b4b72bf6ed561d7568f (patch)
tree662ad587c009908f448ca33a4af610f4270cb792 /src/corelib/tools/qarraydatapointer.h
parent2fd0996324304c4c055059a980b6f9b32b843574 (diff)
QString/QBA: add lvalue and rvalue overloads to first/last/sliced/chopped
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 <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/tools/qarraydatapointer.h')
-rw-r--r--src/corelib/tools/qarraydatapointer.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h
index 201f3e665d..2fbd6c7505 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; }