language: C++ 4.7.2 (gcc-4.7.2)
date: 652 days 11 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
 
using namespace std;
 
template<typename T, typename R = void>
struct int_return_type {};
 
template<typename R>
struct int_return_type<int, R>
{
    typedef R type;
};
 
template<typename T, typename R = void>
struct float_return_type {};
 
template<typename R>
struct float_return_type<float, R> 
{
    typedef R type;
};
 
template<typename T>
typename int_return_type<T>::type test()
{
    cout << "T type is int" << endl;
}
 
template<typename T>
typename float_return_type<T>::type test()
{
    cout << "T type is float" << endl;
}
 
int main()
{
    test<int>();
    test<float>();
    return 0;
}