От: | remark | http://www.1024cores.net/ | |
Дата: | 02.03.10 11:00 | ||
Оценка: | 336 (27) |
template<int idx> struct prio;
template<int idx> struct prio : prio<idx - 1> {};
template<> struct prio<0> {};
template<typename T>
string
foo(T, prio<0>)
{
return "general";
}
template<typename T>
typename enable_if<is_arithmetic< T >, string >::type
foo(T, prio<1>)
{
return "arithmetic";
}
template<typename T>
typename enable_if<is_integral< T >, string >::type
foo(T, prio<2>)
{
return "integral";
}
template<typename T>
string foo(T t)
{
return foo(t, prio<100>());
}
int main()
{
cout << "int: " << foo(1) << endl;
cout << "string: " << foo(string()) << endl;
cout << "float: " << foo(1.f) << endl;
}
int: integral
string: general
float: arithmetic