Reputation: 247
Consider the code:
template<template<typename,typename> class Container>
class A {
template<class U, class Allocator>
void Foo(Container<U, Allocator>*, U);
};
Now I want to specialize A
in the case the Container is a map where the Value and Comparator are known, and create a definition of Foo
in this case (no specialization of Foo
). I tried this:
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 ) {...}
But I get the compiling error:C3200: 'std::map<int,V,Comp,int>' : invalid template argument for template parameter 'Container', expected a class parameter.
I have looked online and only found similar issues, but I couldn't find a way to specify only partial template parameter list of a template template. Is there a way to do it?
EDIT: The only problem is when giving a template class partial specialization is to make it behave as a template with the remaining parameters.
Here it's an attempt to think of a map<*,Known1,Known2,*>
as a template of only 2 arguments (which can realy be used as the template template parameter of A
) .
EDIT 2: The compiler I have to use is GCC 4.1.2 that has no support for template aliasing, which, as I understood, is a solution.
Upvotes: 4
Views: 3023
Reputation: 303870
The problem is that A
takes a template template parameter that takes two types:
template<template<typename,typename> Container>
class A {
But std::map
doesn't take two types. It takes four:
template<
class Key,
class T,
class Compare = std::less<Key>,
class Allocator = std::allocator<std::pair<const Key, T> >
> class map;
So that's one problem. You will have to generalize your template to the following (also note the missing class
keyword):
template <template <typename...> class Container>
class A { ... };
But even with that, at most you could completely explicitly specialize a member function, you can't partially specialize it:
template <>
template <>
void A<std::map>::Foo<>(std::map<U, V>*, U) { ... }
Upvotes: 5