Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ STL容器上的模板参数_C++_Templates - Fatal编程技术网

C++ STL容器上的模板参数

C++ STL容器上的模板参数,c++,templates,C++,Templates,我想实现一个使用不同键值容器的包装器类,比如map、unordered_map 我希望用户可以这样使用代码: MyWrapper<std::map> w1; MyWrapper<std::tr1::unordered_map> w2; MyWrapper w1; myw2; 我使用“模板参数”来实现这一点, 但是map和无序_-map的模板参数是不同的 // but this Wrapper is for std::map only.... template<

我想实现一个使用不同键值容器的包装器类,比如map、unordered_map

我希望用户可以这样使用代码:

MyWrapper<std::map> w1;
MyWrapper<std::tr1::unordered_map> w2;
MyWrapper w1;
myw2;
我使用“模板参数”来实现这一点, 但是map和无序_-map的模板参数是不同的

// but this Wrapper is for std::map only....
template< template<typename,typename,typename,typename> class CONTAINER>
class MyWrapper
{
     CONTAINER<string, string,
            std::less<string>,
            std::allocator<std::pair<const string, string> > > c_;
};

MyWrapper<std::map> w1;
MyWrapper<std::tr1::unordered_map> w1; // not compiled!!!
//但此包装器仅适用于std::map。。。。
模板<模板类容器>
类MyWrapper
{
集装箱c_2;;
};
myw1;
MyWrapper w1;//未编译!!!
有没有办法让一个类可以传递map或unordered_map作为模板参数??
谢谢

您可以使用c++11和可变模板来执行您想要的操作:

template< template<typename, typename...> class CONTAINER>
template