
Boost : 
From: Andy Little (andy_at_[hidden])
Date: 20050508 08:19:59
"Tobias Schwinger" <tschwinger_at_[hidden]> wrote
> Andy Little wrote:
>> FWIW thi would work fine for me:
>>
>> typedef std::math::constants<T> math;
>> 2 * math::pi * r ;
>
> This looks nice at first glance.
Thanks ......................................... :)
> Besides getting rid of the empty parentheses, there are the following
> disadvantages:
^^^
I Assume you mean In spite of ?
>  modularity/extensibility (once constants<T> is defined you can't add
> constants to it)
In practise you can. constants struct 's members are really just global
constants. Your compiler wont know the difference, because it only instantiates
what you ask for, add a new type and it wont know its there till you use it, and
will then assume its always been there. However not conforming I guess. A
derivation for the newer constants would be conforming.
template <typename T>
struct constants2 : constants<T>{
static T const & andys_constant;
}
template <typename T>
T const & constants2<T>::andys_constant = T(2005);
typedef std::math::constants2<double> math;
2 * math::pi * r ;
>  portability (the code above won't compile with BCC)
Whats the error. AFAIK its correct C++ is it not ? If its correct C++ then I
think this is not a strong argument.
>  there is no way to pass constants as a type template argument.
( IOW use a function ..? )
Well .. is that an essential ?..Do you have a use case demonstrating this need?
AFAIK constants are always pretty specific to their own particularly algorithms.
Whatever ... I still like std::math::constants<T>::pi much better than
std::pi<T>() :)
regards
Andy Little
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk