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.