Here is an example of how to create a new type where the template parameter (int) is exchanged (line by line):
#include <vector> #include <string> template <typename container, typename newt> struct replace; template <typename p1, typename alloc, template<typename,typename > class containerTemplate, typename newt> struct replace<containerTemplate<p1,alloc>,newt> { public: typedef containerTemplate<newt,alloc> result; }; int main() { replace<std::vector<int>,std::string>::result vs; vs.push_back("a string"); }
This way you can pass std :: unordered_map as a template parameter to your function and replace char with any other type you want. You may need to customize your example to your needs. But the principle must be clear.
EDIT: More general for containers, less general for replacement:
template <class Container> struct replace; template <template <class...> class Container, class... Ts> struct replace<Container<Ts...>> { typedef Container<std::string> result; };
source share