Is it possible to use a class template as parameter in a template specialization?
I would like to be able to use something like foo<Foo<int>>()
(see #3
in source code) and have unique code for that template instance run. At the moment only ordinary specialization works (see #2
).
A previous similar question would have me believe approach #3
would work, but the code doesn't work under msvc2012 at least.
Is what I'm trying to do possible? If so, how?
Source
// Test struct.
template<class T>
struct Foo
{
T foo;
};
// #1 Ordinary template
template<class T>
T foo()
{
return T();
}
// #2 Template specialization
template<>
int foo<int>()
{
return 42;
}
// #3 Template specialization with template as parameter? Not working.
template<>
template<typename T>
Foo<T> foo<Foo<T>>()
{
return Foo<T>();
}