Boost logo

Boost Users :

From: james.jones_at_[hidden]
Date: 2007-03-07 16:28:54


From: "Ovanes Markarian" <om_boost_at_[hidden]>
> Ok, I see. This is a bit more complex. ;)
> Can you influence a type passed to numeric_limits? If yes you can do this:

Thought about that, but it's suboptimal - see my response to me22 for more on this. Basically, I'd like any existing usage of numeric_limits<double> to be able to be replaced by numeric_limits<DecimalType> without any other changes.

It wouldn't be *too* bad to do this:

template< class T, class Enable = void >
decimal_limits {};

template <>
decimal_limits <double> : public std::numeric_limits <double> {};

template <>
decimal_limits <float> : public std::numeric_limits <float> {};

template <class T>
decimal_limits <T, enable_if<is_decimal_type<T> > >
{
        // my decimal_limits implementation
};

However, this would require users of my library to replace all references to numeric_limits with decimal_limits, so this is also less than ideal.

Suppose the user has the following code:

        template<typename T = double>
        int
        f(const T& x)
        {
                x = abs(x);
                int i = 0;
                while(x > std::numeric_limits<T>::epsilon())
                        ++i;
                return i;
        }

Ideally, the user should be able to do this:

        f<new_decimal_type> (some_new_decimal_value);

and it should work with no modifications to the original function.

-
James Jones Administrative Data Mgmt.
Webmaster 375 Raritan Center Pkwy, Suite A
Data Architect Edison, NJ 08837


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