Boost logo

Boost :

From: Paul A. Bristow (boost_at_[hidden])
Date: 2002-10-16 04:22:10


Herve Bronnimann [hbr_at_[hidden]] and Sylvain Pion suggested using a template
method for presenting the smallest interval containing math constants:

> The template solution has advantages : it can simply refuse to compile if you
> try to ask a digits/radix pair of values which you have not planned.
> With the initial switch I proposed, you can only get a run-time error.
>
> The template solution is also more easily extensible as said : you don't
> need to have only one big statement in only one file, you can spread the
> various versions over several files.
>
> So I guess you could write your constants like :
>
> template <class T, int radix = std::numeric_limits<T>::radix,
> int digits = std::numeric_limits<T>::digits>
> class pi;
>
> template <>
> class pi<float, 2, 24>
> {
        static const float lower = 3.1415925025939941406250F;
        static const float upper = 3.1415927410125732421875F;
        static const float nearest =
3.14159265358979323846264338327950288419716939937510F;

};

Sadly this seems not supported by MSVC 7.0:

"error C2864: 'lower' : only const static integral data members can be
initialized inside a class or struct" - NO FLOATING POINT!

though it works OK for GCC 2.95 and 3.2.

Can any language lawyers advise if this is really a language restriction, or
simply not implemented by MSVC 7.0?

Is it supported by MSVC 7.1?

Workarounds?

Thanks for any advice.

Dr Paul A Bristow, hetp Chromatography
Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK
+44 1539 561830 Mobile +44 7714 33 02 04
mailto:pbristow_at_[hidden]


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