[config] check for std::numeric_limits<T>::lowest() availability

Hi, 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. What will be the right way to do that? Any chance <boost/limmits.hpp> manage with that? Best, _____________________ Vicente Juan Botet Escribá http://viboes.blogspot.com/

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?
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.

----- Original Message ----- From: "John Maddock" <boost.regex@virgin.net> To: <boost@lists.boost.org> 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

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.
Patch added - but macro changed to BOOST_NO_NUMERIC_LIMITS_LOWEST.
BTW, on cygwin gcc-4.3.4 I get the following error related to nl_types.h file.
It is normal that the default cygwin installation miss this file?
It appears that cygwin has started to claim to be XSI conformant, but without providing all the required headers, also fixed in Trunk.
Beside the macro, I was thinking in adding a specific boost::numeric_limits traits, including the missing features.
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.
That looks kind of confusing to me that it only offers lowest(), in any case this is one for the mailing list to decide if it should be added. Cheers, John.

----- Original Message ----- From: "John Maddock" <boost.regex@virgin.net> To: <boost@lists.boost.org> Sent: Sunday, September 26, 2010 11:36 AM Subject: Re: [boost] [config]checkforstd::numeric_limits<T>::lowest()availability
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.
Patch added - but macro changed to BOOST_NO_NUMERIC_LIMITS_LOWEST.
Yes, this seems a better name.
BTW, on cygwin gcc-4.3.4 I get the following error related to nl_types.h file.
It is normal that the default cygwin installation miss this file?
It appears that cygwin has started to claim to be XSI conformant, but without providing all the required headers, also fixed in Trunk.
I will recheck on my installation.
Beside the macro, I was thinking in adding a specific boost::numeric_limits traits, including the missing features.
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.
That looks kind of confusing to me that it only offers lowest(), in any case this is one for the mailing list to decide if it should be added.
Yes, I was tempted to add all the other members. What others think of this minor addition? Thanks, Vicente

Hi, I believe this functionality already exists as boost/numeric/conversion/bounds.hpp and boost/numeric/conversion/detail/bounds.hpp specifically, is this what you're looking for? Regards, Jeroen

----- Original Message ----- From: "Jeroen Habraken" <vexocide@gmail.com> To: <boost@lists.boost.org> Sent: Sunday, September 26, 2010 2:20 PM Subject: Re: [boost][config]checkforstd::numeric_limits<T>::lowest()availability
Hi,
I believe this functionality already exists as boost/numeric/conversion/bounds.hpp and boost/numeric/conversion/detail/bounds.hpp specifically, is this what you're looking for?
Regards, Jeroen
Hi, Yes, this is exactly the functionality I was looking for. I will adapt my code to use this when numeric_limits<T>::lowest() is not available. Thanks a lot, Vicente
participants (3)
-
Jeroen Habraken
-
John Maddock
-
vicente.botet