Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2007-03-07 12:38:08


Ok, I see. This is a bit more complex. ;)
Can you influence a type passed to numeric_limits? If yes you can do this:

template<class T>
struct use_decimal_limits{};

namespace std
{
        template<class T>
        class numeric_limits< use_decimal_limits<T> >
                : boost::enable_if<boost::decimal::is_decimal_type<T>
>::type {
        
        ...
        };
}

In the scenario upon the enable_if is not required, but is a compile time
check.

But on the other hand if is_decimal_type<T> deals with double and float
anyway you can specialize numeric_limits for those types without any
enable_if derivation. Probably you need to specialize the template all
const, volatile, long double etc.:

template<class T>
struct my_numeric_limits_impl
{
        static T min() { return boost::decimal::decimal_limits<T>::min(); }
};

namespace std
{
        template<>
        class numeric_limits<float> : public my_numeric_limits_impl<float>
        {};

        template<>
        class numeric_limits<double> : public my_numeric_limits_impl<double>
        {};

}

Maybe someone will suggest some better ways

-----Original Message-----
From: james.jones_at_[hidden] [mailto:james.jones_at_[hidden]]

Sent: Mittwoch, 7. März 2007 18:10
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [enable_if] using enable_if to
extendstd::numeric_limits?

From: "Ovanes Markarian" <om_boost_at_[hidden]>
> Sorry,
>
> I ment enable_if< is_decimal_type<T> >::type. The ::type will be
> expanded to either void or a derivable type.

Maybe I'm misunderstanding, but how can I derive std::numeric_limits from
enable_if, since std::numeric_limits is already defined? I can't do this:

namespace std {
template <typename T>
class numeric_limits :
    private boost::enable_if<boost::decimal::is_decimal_type<T> >::type {
public:
    static T min() { return boost::decimal::decimal_limits<T>::min(); } }; }

and I can't do this:

namespace std {
template <typename T>
class numeric_limits<T> :
    private boost::enable_if<boost::decimal::is_decimal_type<T> >::type {
public:
    static T min() { return boost::decimal::decimal_limits<T>::min(); } }; }

because this is not a specialization.

-
James Jones Administrative Data Mgmt.
Webmaster 375 Raritan Center Pkwy, Suite A
Data Architect Edison, NJ 08837
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net