Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-81941

QFuture should support move-only types

    XMLWordPrintable

Details

    • User Story
    • Resolution: Done
    • P2: Important
    • 6.0.0
    • None
    • Core: QtConcurrent
    • 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

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            tpochep Timur Pocheptsov
            kandeler Christian Kandeler
            Maurice Kalinowski Maurice Kalinowski
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes