|
Boost : |
Subject: Re: [boost] [config] check forstd::numeric_limits<T>::lowest()availability
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-09-22 10:52:37
----- Original Message -----
From: "John Maddock" <boost.regex_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, September 22, 2010 10:06 AM
Subject: Re: [boost] [config] check forstd::numeric_limits<T>::lowest()availability
>
>>I would like to use std::numeric_limits<T>::lowest() when the standard
>>library provides it. As this is a
>>specific function on C++0X, I was looking for a macro on Boost.Config that
>>allows to use it conditionally,
>>unfortunatelly I have not found any.
>
> Because, no one has asked for it yet :-)
>
> Do you have a patch?
I can add a macro
# define BOOST_NO_LIMITS_LOWEST
which must be defined except for the libraries providing this
template<class T> class std::numeric_limits {
public:
static constexpr T lowest() throw();
};
Of course constexpr must be managed by the already existing macro BOOST_NO_CONSTEXPR.
I have followed the "Adding New Defect Macros" and thisnk that I have reached to create the new macro stuff. See attached patches.
I guess that this macro should be defined in all the config/stdlib files except when this is provided. I have changed only thre files as I can not test others.
BTW, on cygwin gcc-4.3.4 I get the following error related to nl_types.h file.
...updating 4 targets...
gcc.compile.c++ ../../../bin.v2/libs/config/test/config_test.test/gcc-4.3.4/debug/config_test.o
In file included from /usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/ext/hash_set:64,
from boost_has_hash.ipp:16,
from config_test.cpp:652:
/usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/backward/backward_warning.h:33:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated.
In file included from config_test.cpp:682:
boost_has_nl_types_h.ipp:12:22: error: nl_types.h: No such file or directory
It is normal that the default cygwin installation miss this file?
>>What will be the right way to do that? Any chance <boost/limmits.hpp>
>>manage with that?
>
> No, boost/limits.hpp just provides a replacement when the std version isn't
> available, and we can't extend numeric_limits ourselves, so yes a config
> macro would be the way to go.
>
> John.
Beside the macro, I was thinking in adding a specific boost::numeric_limits traits, including the missing features.
// boost/numeric_limits.hpp
namespace boost {
namespace detail {
template <class T, bool = is_arithmetic<T>::value>
struct numeric_limits {
static T lowest() throw() {return (std::numeric_limits<T>::min) ();}
};
template <class T>
struct numeric_limits<T,true> {
static T lowest() throw() {return (std::numeric_limits<T>::min) ();}
};
template <>
struct numeric_limits<float,true> {
static float lowest() throw() {return -(std::numeric_limits<float>::max) ();}
};
template <>
struct numeric_limits<double,true> {
static double lowest() throw() {return -(std::numeric_limits<double>::max) ();}
};
template <>
struct numeric_limits<long double,true> {
static long double lowest() throw() {return -(std::numeric_limits<long double>::max)();}
};
}
#if defined(BOOST_NO_LIMITS_LOWEST)
template <class T>
struct numeric_limits : detail::numeric_limits<typename remove_cv<T>::type> {};
#else
template <class T>
struct numeric_limits {
static T lowest() throw() {return std::numeric_limits<T>::lowest();}
};
#endif
}
Let me know if this could be useful for others and be included in Boost. If yes I could send you a patch with tests and documentation included.
Best,
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk