$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: David Abrahams (dave_at_[hidden])
Date: 2004-01-05 06:31:53
"Michael D. Borghardt" <michael_at_[hidden]> writes:
> 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 can't quite read your code; more line breaks would help ;-)
Using sizeof is a pretty good heuristic, but it's not strictly
portable.  The number of chars in a numeric type says nothing about
its range according to the standard.
> 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
I'm sure it would be a really useful table, but the formatting didn't
quite come out.  Would you mind doing a re-post?
> 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
>
>
>
>
>
>
> _______________________________________________
> Unsubscribe & other changes: http://listarchives.boost.org/mailman/listinfo.cgi/boost
>
-- Dave Abrahams Boost Consulting www.boost-consulting.com