MCVE = https://godbolt.org/z/K7d5PEs65
Код: Выделить всё
int main(){
int localVariable=0; //some local variable
auto lamb=[&]() {
if constexpr(s==5){localVariable=7;}
///^ may modify some local variables
return 8;
};
constexpr int gOk=lamb.operator()();
[&]() {
///vvv can edit only here
constexpr int gFail=lamb.operator()();
///^^^ can edit only here
}.operator()();
}
Мне нужен gFail< /code> должна быть переменной constexpr, тогда как Lamb иногда создает побочный эффект во время выполнения, в зависимости от значения переменной шаблона s.
Пожалуйста, дайте ссылку и обходной путь для случая Visual C++.
Подробнее здесь: https://stackoverflow.com/questions/787 ... expr-templ