考虑代码:
template<template<typename,typename> class Container>
class A {
template<class U, class Allocator>
void Foo(Container<U, Allocator>*, U);
};
Run Code Online (Sandbox Code Playgroud)
现在我想专门研究A容器是已知值和比较器的映射的情况,并Foo在这种情况下创建 的定义(没有专门化Foo)。我试过这个:
template<typename V, typename Comp> template<class U, class Allocator>
void A<std::map<typename, V, Comp, typename>>::Foo(map<U, V, Comp, Allocator>*, U ) {...}
Run Code Online (Sandbox Code Playgroud)
但我得到编译错误:C3200: 'std::map<int,V,Comp,int>' : invalid template argument for template parameter 'Container', expected a class parameter.
我在网上查了一下,只发现了类似的问题,但我找不到一种方法来仅指定模板模板的部分模板参数列表。有办法做到吗?
编辑:唯一的问题是当给予模板类部分专业化时,使其表现为具有剩余参数的模板。这里尝试将 a 视为map<*,Known1,Known2,*>只有 2 个参数的模板(实际上可以用作 的模板模板参数A)。
编辑2:我必须使用的编译器是GCC 4.1.2,它不支持模板别名,据我所知,这是一个解决方案。