The code below illustrates the usage of template specialization, and partial template specialization, with a traits mechanism.
The MyTraits class template converts its input type, T, to a new type, MyTraits<T>::type, according to these rules:

It should be noted, that most versions of Microsoft's C++ compiler (VC++), do not support partial template specialization. Only Visual C++ Toolkit 2003 claims to provide this facility. In contrast, partial template specialization is fully supported by the GCC compiler, for some time now.

#include <iostream>
#include <stdexcept>
#include <vector>
#include <list>

using namespace std;


template<typename T>
struct MyTraits
{
   typedef double type;
};


template<>
struct MyTraits<int>
{
   typedef short type;
};

template<typename S>
struct MyTraits<vector<S> >
{
   typedef typename vector<S>::value_type type;
};


int main(int argc, char* argv)
{
   MyTraits<char>::type x;         // x is a double
   MyTraits<int>::type y;          // y is a short
   MyTraits<vector<int> >::type z; // z is an integer

   return 0;
}