Can I easily iterate over the values of a map using a range-based for loop?
From C++1z/17, you can use structured bindings:
#include <iostream>
#include <map>
#include <string>
int main() {
std::map<int, std::string> m;
m[1] = "first";
m[2] = "second";
m[3] = "third";
for (const auto & [key, value] : m)
std::cout << value << std::endl;
}
std::map<float, MyClass*> foo;
for (const auto& any : foo) {
MyClass *j = any.second;
j->bar();
}
in c++11 (also known as c++0x), you can do this like in C# and Java