I sometimes use lamdas as you describe, but only if its body is small. I do use larger lamdas for "workaround" code, code that is a temporary fix for an upstream bug. For example:
// Workaround for https://bugs.launchpad.net/appmenu-qt5/+bug/1380702
// No keyboards shortcuts in QT apps
inline void attachMenuBarActionsToWidget(QWidget &widget)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) && defined(Q_OS_LINUX)
if ([]() -> bool {
// Return false if UBUNTU_MENUPROXY is empty (but set) or "0"
if ((qEnvironmentVariableIsSet("UBUNTU_MENUPROXY")
&& qEnvironmentVariableIsEmpty("UBUNTU_MENUPROXY"))) {
return false;
} else {
try {
auto const ubuntuMenuProxy = qgetenv("UBUNTU_MENUPROXY");
if (ubuntuMenuProxy == "0") {
return false;
}
} catch (std::exception &e) {
Q_UNUSED(e)
}
}
return true;
}()) {
workaround::attachMenuBarActionsToWidgetImp(widget);
}
#else
Q_UNUSED(widget);
#endif
}
Using lamdas helps to keep ugly workaround code in one place.