Is there any equivalent to structured binding inside the init-capture list in lambda?
I know this is invalid, but is there any way to declare 'i' and 's' without declaring outside of the lambda?
std::pair<int, std::string> p { 1, "two" };
auto f = [[i, s] = p] mutable -> std::pair<int, std::string> {
++i;
s += '_';
return {i, s};
};
auto print = [&]{
const auto& x = f();
std::cout << x.first << ": " << x.second << '\n';
};
print();
print();
print();
Output:
1: _
2: __
3: ___