MyTraits class template converts its input type, T, to a new type,
MyTraits<T>::type, according to these rules:int type is converted to a short
vector<S> type is converted
to vector<S>::value_type which is
usually an alias for S;
double
#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;
}