I defined a function like this, in which there is a template template class
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); } } }; std::map<int, string> m { {1, "foo"}, {3, "bar"}}; ForEachOf<int, string, std::map> forEachOf; forEachOf(m, [](int key, string value) { cout << key << value; }); However, above code is not able to compile. the error is like:
error: template template argument has different template parameters than its corresponding template template parameter ForEachOf<int, string, std::map> forEachOf; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__tree:1119:5: note: too many template parameters in template template argument template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map; note: previous template template parameter is here template<typename Key, typename Value, template <typename, typename> class Map> Then How to pass std::map as the template template parameter here?
std::maphas four template parameters, not two.T, and makefuncaccepttypename T::key_typeandtypename T::mapped_type