Details
-
User Story
-
Resolution: Done
-
P2: Important
-
None
-
None
-
21
-
Qt6_Foundation_ Sprint 4, Qt6_Foundation_ Sprint 5
-
44ceb56
Description
For instance, we cannot asynchronously run functions returning unique_ptr:
#include <QtConcurrent> #include <memory> static std::unique_ptr<int> allocateInt() { return std::make_unique<int>(); } int main() { const auto future = QtConcurrent::run(&allocateInt); return *future.result(); }
In file included from /usr/include/qt/QtCore/QtCore:91, from /usr/include/qt/QtConcurrent/QtConcurrentDepends:3, from /usr/include/qt/QtConcurrent/QtConcurrent:3, from /tmp/untitled2/main.cxx:1: /usr/include/qt/QtCore/qfuture.h: In instantiation of ‘T QFuture<T>::result() const [with T = std::unique_ptr<int>]’: /tmp/untitled2/main.cxx:9:27: required from here /usr/include/qt/QtCore/qfuture.h:209:31: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = int; _Dp = std::default_delete<int>]’ 209 | return d.resultReference(0); | ^
The STL version of this code works fine:
#include <future> #include <memory> static std::unique_ptr<int> allocateInt() { return std::make_unique<int>(); } int main() { auto handle = std::async(std::launch::async, allocateInt); return *handle.get(); }
Attachments
For Gerrit Dashboard: QTBUG-81941 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
292010,75 | QFuture - add ability to move results from QFuture | dev | qt/qtbase | Status: MERGED | +2 | 0 |
297139,9 | Make continuations work with move-only types | dev | qt/qtbase | Status: MERGED | +2 | 0 |