diff --git a/src/corelib/tools/qcontainertools_impl.h b/src/corelib/tools/qcontainertools_impl.h index adaa254a04a..d380421170c 100644 --- a/src/corelib/tools/qcontainertools_impl.h +++ b/src/corelib/tools/qcontainertools_impl.h @@ -86,6 +86,26 @@ void q_uninitialized_relocate_n(T* first, N n, T* out) QT_WARNING_POP +/*! + \internal + + A wrapper around std::rotate(), with an optimization for + Q_RELOCATABLE_TYPEs. We omit the return value, as it would be more work to + compute in the Q_RELOCATABLE_TYPE case and, unlike std::rotate on + ForwardIterators, callers can compute the result in constant time + themselves. +*/ +template +void q_rotate(T *first, T *mid, T *last) +{ + if constexpr (QTypeInfo::isRelocatable) { + const auto cast = [](T *p) { return reinterpret_cast(p); }; + std::rotate(cast(first), cast(mid), cast(last)); + } else { + std::rotate(first, mid, last); + } +} + template void q_relocate_overlap_n_left_move(iterator first, N n, iterator d_first) { diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 618e04b41cf..6428c359c0e 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -853,12 +853,7 @@ Q_OUTOFLINE_TEMPLATE auto QVLABase::emplace_impl(qsizetype prealloc, void *ar emplace_back_impl(prealloc, array, std::forward(args)...); const auto b = begin() + offset; const auto e = end(); - if constexpr (QTypeInfo::isRelocatable) { - auto cast = [](T *p) { return reinterpret_cast(p); }; - std::rotate(cast(b), cast(e - 1), cast(e)); - } else { - std::rotate(b, e - 1, e); - } + QtPrivate::q_rotate(b, e - 1, e); return b; }