fork(1) download
  1. #include <map>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. template<typename T, typename F>
  6. void ForEachOf(T&& map, F&& func) {
  7. for(auto& pair : map) {
  8. func(pair.first, pair.second);
  9. }
  10. }
  11.  
  12. int main(void) {
  13. std::map<int, std::string> m { {1, "foo"}, {3, "bar"}};
  14. ForEachOf({ {1, "foo"}, {3, "bar"}}, [](auto key, auto value) {
  15. ::std::cout << key << value;
  16. });
  17. }
  18.  
Compilation error #stdin compilation error #stdout 0s 3460KB
stdin
Standard input is empty
compilation info
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'
     });
      ^
stdout
Standard output is empty