Reputation: 337
I was reading the answer given here: https://stackoverflow.com/a/23550519/1938163
and I'm wondering why the last line is a template struct's partial specialization
template<typename T> MyClass { public: };
template <typename T> struct Foo {void foo() {}};
template<> struct Foo<int> {void foo() { std::cout << "fooint";} };
// Why is this a partial specialization?
template<typename T> struct Foo< MyClass<T> > {void foo() {std::cout << "foo myclass";} };
I thought that a partial specialization consisted in replacing parameter arguments completely like the following
template <typename T, typename G> struct FooBar {};
template <typename G> struct FooBar<int, G>{}; // Partial specialization
Upvotes: 0
Views: 87
Reputation: 7637
Full specialization is when template parameters are all replaced by concrete types and the template parameter list is empty. MyClass<T>
is not concrete; and
template<typename T> struct Foo<MyClass<T>> { ... };
it is still parametrized by T
, and the template parameter list still contains T
. For instance,
template<> struct Foo<MyClass<int>> { ... };
would be a full specialization of Foo
that is more specialized than Foo<MyClass<T>>
.
Upvotes: 1