fork(1) download
  1. #include <map>
  2. #include <functional>
  3. #include <string>
  4. #include <iostream>
  5.  
  6. using ::std::string;
  7.  
  8. template<typename Key, typename Value, template <typename, typename> class Map>
  9. struct ForEachOf {
  10. void operator()(const Map<Key, Value>& map, std::function<void (Key, Value)> func) {
  11. for(const auto& pair : map) {
  12. func(pair.first, pair.second);
  13. }
  14. }
  15. };
  16.  
  17. template<typename key, typename value>
  18. using mymap = std::map<key, value>;
  19.  
  20. int main(void) {
  21. mymap<int, string> m { {1, "foo"}, {3, "bar"}};
  22. ForEachOf<int, string, mymap> forEachOf;
  23. forEachOf(m, [](int key, string value) {
  24. ::std::cout << key << value;
  25. });
  26. }
  27.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
1foo3bar