Re: [Boost-users] [enable_if] using enable_if to extend std::numeric_limits?
From: "Ovanes Markarian"
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
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 ::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@firstinvestors.com [mailto:james.jones@firstinvestors.com]
Sent: Mittwoch, 7. März 2007 18:10
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] [enable_if] using enable_if to
extendstd::numeric_limits?
From: "Ovanes Markarian" 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
participants (2)
-
james.jones@firstinvestors.com
-
Ovanes Markarian