From f90dd023cf8ec464e113ed4ef068383b5d8f13a3 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 10 May 2025 21:07:30 +0200 Subject: [PATCH] QQueue: add enqueue signature to enqueue elements by moving Using the QQueue shim one could only use `enqueue` by copying. Adding a signature to copy to allow elements to be moved. Change-Id: Idfbabb6fc01265285f128c5657ccb4050e902720 Reviewed-by: Thiago Macieira --- src/corelib/tools/qqueue.cpp | 1 + src/corelib/tools/qqueue.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/corelib/tools/qqueue.cpp b/src/corelib/tools/qqueue.cpp index 74ab49b3bf9..a0ebf7e32ff 100644 --- a/src/corelib/tools/qqueue.cpp +++ b/src/corelib/tools/qqueue.cpp @@ -48,6 +48,7 @@ /*! \fn template void QQueue::enqueue(const T& t) + \fn template void QQueue::enqueue(T&& t) Adds value \a t to the tail of the queue. diff --git a/src/corelib/tools/qqueue.h b/src/corelib/tools/qqueue.h index 4863499f2a8..b41be9555ef 100644 --- a/src/corelib/tools/qqueue.h +++ b/src/corelib/tools/qqueue.h @@ -16,6 +16,7 @@ public: // compiler-generated special member functions are fine! inline void swap(QQueue &other) noexcept { QList::swap(other); } // prevent QList<->QQueue swaps inline void enqueue(const T &t) { QList::append(t); } + inline void enqueue(T &&t) { QList::append(std::move(t)); } inline T dequeue() { return QList::takeFirst(); } inline T &head() { return QList::first(); } inline const T &head() const { return QList::first(); }