Structured bindings make it more clean and readable to iterate through a map with a range based for loop like below
for (auto [key, value] : map) {
cout << key << " : " << value << endl;
}
But can structured bindings be used in lambda expressions like the following?
std::for_each(map.begin(), map.end(), [](auto [key, value]) {
cout << key << " : " << value << endl;
});
From what it looks like the above code does not work with the online C++ compiler I found here https://wandbox.org/permlink/sS6r7JZTB3G3hr78.
If it does not work then is there a good reason the above is not supported? Or is it just something that has not been proposed yet? The template will only be instantiated on use, so the structured bindings' "unbinding" process can occur where the instantiation is requested (i.e. when the function is called)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…