language: C++ 4.7.2 (gcc-4.7.2)
date: 648 days 10 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <typeinfo>
#include <climits>
 
using namespace std;
 
class true_type {};
class false_type {};
 
template<bool> 
struct bool2type 
{ 
  typedef true_type  type; 
};
 
template<>
struct bool2type<false>
{
  typedef false_type  type;
};
 
template<int M, int L, int H>
struct within_range
{
   static const bool value = L <= M && M <=H;
   typedef typename bool2type<value>::type type;
};
 
template<int M, class booltype> 
struct IntegerType;
 
template<int Max> 
struct IntegerType<Max,typename within_range<Max, 0, 127>::type >
{
   typedef char type;
};
 
template<int Max> 
struct IntegerType<Max,typename within_range<Max, 128, 32767>::type >
{
   typedef short type;
};
 
template<int Max> 
struct IntegerType<Max,typename within_range<Max, 32768, INT_MAX>::type >
{
   typedef int type;
};
 
template <int Max>
struct Integer {
    typedef typename IntegerType<Max, true_type>::type type;
};
 
int main() {
        cout << typeid(Integer<122>::type).name() << endl;
        cout << typeid(Integer<1798>::type).name() << endl;
        cout << typeid(Integer<890908>::type).name() << endl;
        return 0;
}