有这个代码:
template<typename T, template<typename, typename> class OuterCont, template<typename, typename> class InnerCont, class Alloc=std::allocator<T>>
class ContProxy {
OuterCont<T, InnerCont<T, Alloc>> _container;
};
typedef ContProxy<int, std::vector, std::list> IntCont;
但需要用到T*
而不是 std::list<T>
作为InnerCont
在某些情况下——像这样:
template<typename T, template<typename, typename> class OuterCont, T*, class Alloc=std::allocator<T>>
class ContProxy {
OuterCont<T, T*> _container;
};
在这种情况下是否可以使用“模板模板”参数的部分特化?
或者如何以最少的麻烦将其存档..
最佳答案
简单地根据类型 制作模板通常更容易。您无法使用模板模板真正捕获所有情况——如果有人想使用具有六个模板参数的容器怎么办?所以尝试这样的事情:
template <typename T, typename C>
struct ContProxy
{
typedef C container_type;
typedef typename C::second_type second_type;
container_type container_;
};
ContProxy<int, MyContainer<int, std::list<int>> p;
关于c++ - 部分模板模板特化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10527775/