Is it possible to specialize on some (not all) class template parameters?

Generally you can specialize just some template parameters of a class template, this is called "partial specialization". When doing this you create a new, specialized version of the template that "overrides" the general version In your case it seems that you only want to specialize a part of the template, the Foo() method, but this is not possible. You have to specialize the whole TC class: specialization for T=int template class TC { public: void Foo(); }; // implementation of Foo() for the specialized template template void TC::Foo() { //Want this defined for all U but only when T is int.

}.

Generally you can specialize just some template parameters of a class template, this is called "partial specialization". When doing this you create a new, specialized version of the template that "overrides" the general version. In your case it seems that you only want to specialize a part of the template, the Foo() method, but this is not possible.

You have to specialize the whole TC class: // specialization for T=int template class TC { public: void Foo(); }; // implementation of Foo() for the specialized template template void TC::Foo() { //Want this defined for all U but only when T is int. }.

For classes, yes. For functions, no and yes. Partial template specialization is fine for classes, but for global functions it's a little more tricky.

For classes, you simply omit the specialized arguments from the template parameter list and include it in the class definition: // General template class for a vector template struct Vector { T eN; }; // Specialization for N=3 template // omit the N struct Vector // and include it here { T e3; static Vector cross(const Vector& a, const Vector& b) { return Vector( a. E1 * b. E2 - a.

E2 * b. E1, a. E2 * b.

E0 - a. E0 * b. E2, a.

E0 * b. E1 - a. E1 * b.

E0 ); } }; For global functions, you can't do that. You can either define a function that is fully general, or fully specialized -- partial specialization of functions is disallowed. However, you can partially specialize a function by creating it as a proxy for a static function of a partially specialized class.E.g.

Template void foo(A a, B b) { foo_impl::fun(a, b); } template struct foo_impl { static void fun(A a, B b) { // real implementation here } }; You can then specialize foo_impl in any way you want, and that will be reflected in foo.

If you wish only to specialize part of the class, you need the original class to provide hooks. It's generally describes as Traits or Policies depending on the implementation. A Traits class is a class that references some properties, and sometimes methods, for a given type and is not passed explicitly.An example in the STL is std::iterator_traits.

A Policy class is a class passed as a template parameter that is used to implement a number of functionality. An example in the STL is std::less in std::set.In general, the use of a Policy class is explicit while the use of a Traits is implicit... and thus I prefer the former to the latter. If your class does not use these hooks, then report to sth answer on partial specialization and note that the partial means that some parameters are still template, and not that you only wish to specialize a part of the class, for indeed you have to redefine everything.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions