Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-07-12 22:57:58


Hi,

I've just uploaded a version of cast.hpp to the vault which contains some
tricks which are designed to make numeric_cast<> work without generating
"comparison between signed and unsigned" warnings. These tricks work for GCC
2.95.2, but I've been unable to get them to work with MSVC6. I *think* they
are strictly correct and legal, but have some slight doubt about the last
specialization of the following:

    template <bool same_sign>
    struct greater_than_type_max;

    template<>
    struct greater_than_type_max<true>
    {
        template <class X, class Y>
        static bool check(X x, Y y_max)
            { return x > y_max; }
    };

    template <>
    struct greater_than_type_max<false>
    {
        template <class X, class Y>
        static bool check(X x, Y)
            { return x >= 0 && static_cast<X>(static_cast<Y>(x)) == x; }
    };

I think these tricks would probably also work with Metrowerks Codewarrior. I
think there might be trouble with Borland, though. MSVC6, fortunately, has
some #pragmas that I can use so that's not a big issue.

Comments welcome!

-Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk