In below code I do not specify any capture mode, yet some_static is visible inside closure. So the question is whether it is actually captured, or maybe somehow referenced in other way.
Bonus question is whether compiler is allowed to turn such lambda into a free function instead of closure - that would be possible as no capture list is specified.
std::vector<std::function<bool(int)>> filters;
int main()
{
static int some_static = 1;
filters.emplace_back([](int){
return some_static == 2;
});
}
Aucun commentaire:
Enregistrer un commentaire