Details
-
Suggestion
-
Resolution: Won't Do
-
Not Evaluated
-
None
-
7.0 (Next Major Release)
-
None
-
-
b08ddd2c4 (dev), f732833ea (6.6), 6c4fc23b9 (tqtc/lts-6.2), 9fbf832e2 (6.5)
Description
- Make QScopeGuard a non-template class.
- Make private T m_func field of a std::function<void()> type, initialized to {} by default.
- Get rid of bool m_invoke field, it's enough to check whether m_func is set or not.
- Provide a c'tor taking std::function<void()> type.
Optionally provide a template c'tor taking T and assigning it to m_func.
- 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
For Gerrit Dashboard: QTBUG-114200 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
481666,3 | tst_QScopeGuard: test if and how guard in optional<> works | dev | qt/qtbase | Status: MERGED | +2 | 0 |
490544,2 | tst_QScopeGuard: test if and how guard in optional<> works | 6.5 | qt/qtbase | Status: MERGED | +2 | 0 |
490545,2 | tst_QScopeGuard: test if and how guard in optional<> works | 6.6 | qt/qtbase | Status: MERGED | +2 | 0 |
490547,2 | tst_QScopeGuard: test if and how guard in optional<> works | tqtc/lts-6.2 | qt/tqtc-qtbase | Status: MERGED | +2 | 0 |