Changeset 574
- Timestamp:
- 07/02/08 11:58:00 (5 months ago)
- Files:
-
- trunk/libx42pp/include/x42util.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libx42pp/include/x42util.h
r540 r574 36 36 }; 37 37 38 template< typename T, size_t num_bits = sizeof( T ) * CHAR_BIT >38 template< typename T, size_t T_num_bits = sizeof( T ) * CHAR_BIT > 39 39 struct integer_traits 40 40 { 41 41 private: 42 template< size_t num_bits >42 template< size_t num_bits, int dummy > 43 43 struct signed_max 44 44 { 45 static const T val = (T)(signed_max< num_bits - 1 >::val << 1) | 0x1;45 static const T val = (T)(signed_max< num_bits - 1, dummy >::val << 1) | 0x1; 46 46 }; 47 47 48 template< >49 struct signed_max< 2 >48 template< int dummy > 49 struct signed_max< 2, dummy > 50 50 { 51 51 static const T val = (T)0x1; 52 52 }; 53 53 54 template< >55 struct signed_max< 1 >54 template< int dummy > 55 struct signed_max< 1, dummy > 56 56 { 57 57 //can't have a 1-bit signed value 58 58 }; 59 59 60 template< >61 struct signed_max< 0 >60 template< int dummy > 61 struct signed_max< 0, dummy > 62 62 { 63 63 //can't have a 0-bit signed value 64 64 }; 65 65 66 template< size_t num_bits >66 template< size_t num_bits, int dummy > 67 67 struct signed_min 68 68 { 69 static const T val = (T)((signed_min< num_bits - 1 >::val) << 1);69 static const T val = (T)((signed_min< num_bits - 1, dummy >::val) << 1); 70 70 }; 71 71 72 template< >73 struct signed_min< 2 >72 template< int dummy > 73 struct signed_min< 2, dummy > 74 74 { 75 75 static const T val = (T)0x2; 76 76 }; 77 77 78 template< >79 struct signed_min< 1 >78 template< int dummy > 79 struct signed_min< 1, dummy > 80 80 { 81 81 //can't have a 1-bit signed value 82 82 }; 83 83 84 template< >85 struct signed_min< 0 >84 template< int dummy > 85 struct signed_min< 0, dummy > 86 86 { 87 87 //can't have a 0-bit signed value 88 88 }; 89 89 90 template< size_t num_bits >90 template< size_t num_bits, int dummy > 91 91 struct unsigned_max 92 92 { 93 static const T val = (T)(unsigned_max< num_bits - 1 >::val << 1) | 0x1;93 static const T val = (T)(unsigned_max< num_bits - 1, dummy >::val << 1) | 0x1; 94 94 }; 95 95 96 template< >97 struct unsigned_max< 1 >96 template< int dummy > 97 struct unsigned_max< 1, dummy > 98 98 { 99 99 static const T val = (T)0x1; 100 100 }; 101 101 102 template< >103 struct unsigned_max< 0 >102 template< int dummy > 103 struct unsigned_max< 0, dummy > 104 104 { 105 105 //can'g have a 0-bit unsigned value … … 108 108 public: 109 109 static const bool is_signed = (((T)-1) < 0); 110 static const T max_val = is_signed ? signed_max< num_bits >::val : unsigned_max< num_bits>::val;111 static const T min_val = is_signed ? signed_min< num_bits>::val : (T)0;110 static const T max_val = is_signed ? signed_max< T_num_bits, 0 >::val : unsigned_max< T_num_bits, 0 >::val; 111 static const T min_val = is_signed ? signed_min< T_num_bits, 0 >::val : (T)0; 112 112 113 static const T bit_width = num_bits;113 static const T bit_width = T_num_bits; 114 114 }; 115 115
