Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2004-01-21 03:57:46


"Deane Yang" <deane_yang_at_[hidden]> wrote

> Am I right that most of this effort is aimed at avoiding
> an extra pair of parenthesis? To allow
>
> double pi = boost::constants::pi<double>;
>
> instead of requiring
>
> double pi = boost::constants::pi<double>();
>
> ?
>
> I remember when this first came up, and it was explained
> that many people could not live with the latter.
> Is the elimination of the "()" really worth all this effort
> and complexity?

Good point. Theoretically it shouldnt matter, but but but....
when it actually comes to coding it... something comes into play in my mind
and says... "No I dont want to use a function to represent a constant. " ...
Its a very annoying problem :-).

BTW having used the constants , the fact that they are so accurate gives me
a warm glow :-)

perhaps Just the simplest solution is best:

1) No macros, 'namespace' solution
2) works with templates
3) fast,optimisation not required, returns const reference.

but linker needs access to definitions somehow.

regards
Andy Little
-------------
hpp file

namespace boost{namespace math {

    template<typename Value_type>
    struct math_constants;

    template<>
    struct math_constants<long double>{
        static long double const & pi;
        static long double const & e;
        static long double const & sqrt2;
   };

 ... other specialisations

}}//boost::math
---------------------------
cpp file

 #include "xxx_constants.hpp"

    long double const &
    boost::math::math_constants<
       long double
>::pi
    = 3.141592653589793238462643383279502884197L;

 ... other definitions

-------------------------------------


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk