#include <map>
#include <string>
#include <iostream>
template<typename T, typename F>
void ForEachOf(T&& map, F&& func) {
for(auto& pair : map) {
func(pair.first, pair.second);
}
}
int main(void) {
std::map<int, std::string> m { {1, "foo"}, {3, "bar"}};
ForEachOf({ {1, "foo"}, {3, "bar"}}, [](auto key, auto value) {
::std::cout << key << value;
});
}
I2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKdGVtcGxhdGU8dHlwZW5hbWUgVCwgdHlwZW5hbWUgRj4Kdm9pZCBGb3JFYWNoT2YoVCYmIG1hcCwgRiYmIGZ1bmMpIHsKICAgIGZvcihhdXRvJiBwYWlyIDogbWFwKSB7CiAgICAgICAgZnVuYyhwYWlyLmZpcnN0LCBwYWlyLnNlY29uZCk7CiAgICB9Cn0KCmludCBtYWluKHZvaWQpIHsKCXN0ZDo6bWFwPGludCwgc3RkOjpzdHJpbmc+IG0geyB7MSwgImZvbyJ9LCB7MywgImJhciJ9fTsKICAgIEZvckVhY2hPZih7IHsxLCAiZm9vIn0sIHszLCAiYmFyIn19LCBbXShhdXRvIGtleSwgYXV0byB2YWx1ZSkgewogICAgICAgIDo6c3RkOjpjb3V0IDw8IGtleSA8PCB2YWx1ZTsKICAgIH0pOwp9Cg==
prog.cpp: In function 'int main()':
prog.cpp:16:6: error: no matching function for call to 'ForEachOf(<brace-enclosed initializer list>, main()::<lambda(auto:1, auto:2)>)'
});
^
prog.cpp:6:6: note: candidate: template<class T, class F> void ForEachOf(T&&, F&&)
void ForEachOf(T&& map, F&& func) {
^
prog.cpp:6:6: note: template argument deduction/substitution failed:
prog.cpp:16:6: note: couldn't deduce template parameter 'T'
});
^