|
Boost : |
From: Paul A Bristow (pbristow_at_[hidden])
Date: 2006-02-11 06:25:55
Can anyone help me insert a compile time check on the validity ( > 0) of
std::numeric_limits<FPT>::epsilon().
In this code (in floating_point_comparison.hpp)
template<typename FPT>
bool
operator()(FPT left, FPT right)
{ // ((left-right)/left) / epsilon)
BOOST_STATIC_ASSERT(std::numeric_limits<FPT>::is_specialized); // OK.
BOOST_STATIC_ASSERT(numeric_limits<FPT>::is_iec559); // OK
BOOST_STATIC_ASSERT((DBL_EPSILON > 0)); // OK too.
BOOST_STATIC_ASSERT(DBL_EPSILON); // OK, but I am trying to check for UDT
FPT
BOOST_STATIC_ASSERT(numeric_limits<FPT>::epsilon()); // Fails to compile
BOOST_STATIC_ASSERT(numeric_limits<FPT>::epsilon() > (FPT)0); // as does
this.
// error C2975: 'x' : invalid template argument for
'boost::STATIC_ASSERTION_FAILURE', expected compile-time constant expression
(I could just return false but this would help the user much).
return ...;
}
epsilon should be a constant known at compile time?
But is the compile unable to know this?
Other suggestions on how to achieve a compile-time warning here?
Thanks
Paul
-- Paul A Bristow Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB Phone and SMS text +44 1539 561830, Mobile and SMS text +44 7714 330204 mailto: pbristow_at_[hidden] http://www.hetp.u-net.com/index.html http://www.hetp.u-net.com/Paul%20A%20Bristow%20info.html
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk