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

QScopeGuard: Make it a non-template class (7.0)

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Won't Do
    • Not Evaluated
    • None
    • 7.0 (Next Major Release)
    • Core: Other
    • None
    • All
    • b08ddd2c4 (dev), f732833ea (6.6), 6c4fc23b9 (tqtc/lts-6.2), 9fbf832e2 (6.5)

    Description

      1. Make QScopeGuard a non-template class.
      2. Make private T m_func field of a std::function<void()> type, initialized to {} by default.
      3. Get rid of bool m_invoke field, it's enough to check whether m_func is set or not.
      4. Provide a c'tor taking std::function<void()> type.
      5. Optionally provide a template c'tor taking T and assigning it to m_func.
      6. Provide a default c'tor.

      Rationale:

      Currently it's not possible to do:

      bool condition = ...;
      const auto cleanup = condition ? qScopeGuard([] { qDebug() << "Here"; }) : QScopeGuard();
      

      since there is no default c'tor. Even when doing artificial:

      const auto cleanup = condition ? qScopeGuard([] { qDebug() << "Here"; ) : QScopeGuard([] {});
      

      the compiler complains about the not matching types for the left and right operands of "? :" operator.

      Besides, there is really no reason for this class to be a class template.

      Attachments

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

        Activity

          People

            mmutz Marc Mutz
            jkobus Jarek Kobus
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes