c++ - The function template specialization when using tempates as argument -
i want write function template deal vectors, lists, sets, ... , want write specialization function deal map separately , when wrote following code , compiler reports errors.
could 1 me how modify it?
#include <iostream> #include <string> #include <map> #include <unordered_map> using namespace std; // test() vectors, lists, sets, ... template <template <typename...> class t> void test() { t<string, int> x; //... } // specialize test() map template <> void test <map<> class t>() { t<string, int> x; //... } int main() { test<map>(); test<unordered_map>(); }
the template specialization should be:
template <> void test <std::map>() { std::map<string, int> x; }
i changed template parameter map<> class t
invalid syntax std::map
. , changed t<string, int>
std::map<string, int>
because name t
doesn't exist in specialization.
Comments
Post a Comment