Since C++ lambdas have unique unnamed types, something like this doesn't work:
auto select_lambda() {
if (someCondition())
return []() { return 1; };
else
return []() { return 2; };
}
They can be wrapped into an std::function:
std::function<int()> select_lambda() { /* same body */ }
But this has a significant overhead. Is there a better way to achieve something similar? I had some preliminary ideas but none which I got working yet.