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

QFutureInterface: takeResult() should either require a type to be default-constructible or return std::optional

    XMLWordPrintable

Details

    • 21
    • Qt6_Foundation_ Sprint 6
    • 9ba0715f08a64758453b941c4add22a269a30f71

    Description

      The function has the following signature now:

      template<typename T>
      T QFutureInterface<T>::takeResult()
      

      And somewhere in the function's body we have a code like this:

      if (...) {
          return {};
      }
      

      Which means that the type should be default-constructible. So, we have the following options:

      • Add static assert (std::is_default_constructible_v<T>) at the beginning of this function.
      • Return std::optional<T> instead of T.

      The documentation should be extended in both cases.

      I think that the second option is better because:

      • This is not mandatory functional requirement for the type.
      • You don't need to create a default constructed object.
      • std::optional was designed for cases like this.

      Perhaps, in the future, we could use std::expected or QExpected (once/if we have it implemented) to propagate an error message/code.

      Attachments

        Issue Links

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

          Activity

            People

              vitaly.fanaskov Vitaly Fanaskov
              vitaly.fanaskov Vitaly Fanaskov
              Maurice Kalinowski Maurice Kalinowski
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes