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

using ::std::string;

template<typename Key, typename Value, template <typename, 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);
        }
    }
};

	template<typename key, typename value>
	using mymap = std::map<key, value>;

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