Boost logo

Boost :

From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2001-05-03 01:44:02


With your helpful question (answered with a further question below at end)
I am nearer to a solution, though not necessarily an efficient one.

Paul

> -----Original Message-----
> From: Peter Schmitteckert (boost) [mailto:boost_at_[hidden]]
> Sent: Wednesday, May 02, 2001 11:34 AM
> To: boost_at_[hidden]
> Subject: Re: [boost] Math Constants Library formal review results
>
>
> Salut,
>
> On Tuesday 01 May 2001 20:14, you wrote:
> > I have investigated this further but see snags.
> >
> > namespace boost
> > {
> > namespace math
> > {
> > // Example from // B Stroustrup ISBN 0 201 70073 5, p 854
> > template<class T> class X
> > {
> > static T d; // Must be separately defined.
> > // static T const d; // const not allowed by MSVC
> > };
> > template<class T>T X<T>::d = 0; // template NOT specialised.
> > template<>int X<int>::d = 0; // Specialised for int.
> [...]
>
> I have one question:
> My g++ v2.95.4 (and 2.95.3) allows static const members to be
> initialized in
> the the class declaration:
>
> template< typename F> class Q
> {
> public:
> static const F zz = 17;
> }
>
> and it works fine. Is this a g++ extension? Ed Brey shows it is an
extension.

Stroustrup C13.1 p 854 says "static members must be separately defined "

MSVC++ 6 SP5 says "error C2258, illegal pure syntax, must be = 0;"

ISO std 14.5.1.3 doesn't say more.

template<class T>T constants<T>::pi = (T)3.1459L; // works BUT

need to instantiate as

constants<const double>::pi;

rather than <double> - or you can alter it!
>
>
> BTW,
> template<typename T>
> class Q
> {
> public:
> static const T pi;
> }
>
> template<>
> const double Q<double>::pi = 3.1415;
>
> works under MS VC++ 6 (SP5). I've just tested it

Agreed. But I found you can then alter it!!!! pi = 999.;

However further experiments show that

                template<class T> class constants
                {
                        static const T pi;
                }; // template constants

                template<class T>T constants<T>::pi = (T)3.1459L;

std::cout << "Pi is " << boost::math::constants<const double>::pi << endl;
// OK

while

std::cout << "Pi is " << boost::math::constants<double>::pi << endl; //
fails C2373
with a most obscure error message, referencing the template in the .hpp
file, not the point of use.

This looks OK, except how do we allow the physicists and chemists to just
use pi to write

double area = pi * r * r; ????

with a typedef and/or using statement? Suggestions
please!!!!!!!!!!!!!!!!!!!!

Thanks

Paul


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