|
Boost : |
From: John Maddock (John_Maddock_at_[hidden])
Date: 2001-05-12 06:25:29
>a collection of
namespace math_double_constants
{
const double pi = 31459;
}
(This is probably 98% of use, so a template solution is
cosmetically unacceptable).
in math_double_constants.hpp
3 A collection of long double constants
namespace math_constants
{
const long double pi = 31459L;
}
<
Just a warning that this will generate ODR violations - each translation
unit will get it's own definition for pi - and so the linker will complain.
You would need to move the constants into a cpp file for this kind of
usage.
I'm moving towards the function template approach:
namespace boost{
template <class T> T pi();
template<> long double pi<long double>();
// etc
long double pi() { return pi<long double>(); }
}
You can't avoid the function call approach with this, but otherwise it
looks to solve most of the problems - except partial specialisation - you
can't partially specialise pi for boost::interval<T> for example, whether
that is a problem though is another matter.
- John Maddock
http://ourworld.compuserve.com/homepages/john_maddock/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk