|
Boost : |
From: Michael D. Borghardt (michael_at_[hidden])
Date: 2004-01-05 04:55:41
How about this to handle unsigned to signed conversion?
template <>
struct greater_than_type_max<false, false>
{
template <class X, class Y>
static inline bool check(X x, Y y_max)
{ return (sizeof(Y) > sizeof(X) ? static_cast<Y>(x) > y_max : x >
static_cast<X>(y_max));}
// { return static_cast<X>(static_cast<Y>(x)) != x; } // this is the
original line
};
I created the matrix below with test cases and I have tested the following
so far
The orginal line fails tests 6-9,17,19,20,26,33,34,36,37,39,40 where each
uses the sources MAX value
columns represent the source and the rows represent the target
char unsigned char signed char short unsigned short signed short int
unsigned int signed int long unsigned long signed long float double
char 33 PASS 15 17 21 27 34 41
unsigned char 12 13 18 22 28 35 42
signed char 6 16 19 23 29 36 43 1,2
short PASS PASS 20 PASS 30 37 44
unsigned short PASS PASS 10 24 31 38 45 25
signed short PASS PASS PASS 9 32 39 46
int PASS PASS PASS PASS PASS 40 PASS 5
unsigned int PASS PASS PASS PASS PASS 11 14
signed int PASS PASS PASS PASS PASS PASS 7
long PASS PASS PASS PASS PASS PASS PASS PASS
unsigned long PASS PASS PASS PASS PASS PASS PASS PASS 3,4
signed long PASS PASS PASS PASS PASS PASS PASS PASS PASS 8
float PASS PASS PASS PASS PASS PASS PASS PASS PASS 26
double PASS PASS PASS PASS PASS PASS PASS PASS PASS PASS
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk