#include <map>
#include <functional>
#include <string>
#include <iostream>

using ::std::string;

template<typename Key, typename Value, template <typename...> class Map>
struct ForEachOf {
     void operator()(const Map<Key, Value>& map, std::function<void (Key, Value)> func) {
        for(const auto& pair : map) {
            func(pair.first, pair.second);
        }
    }
};

int main(void) {
	std::map<int, string> m { {1, "foo"}, {3, "bar"}};
	ForEachOf<int, string, std::map> forEachOf;
    forEachOf(m, [](int key, string value) {
        ::std::cout << key << value;
    });
}
