Boost logo

Boost :

From: Ed Brey (brey_at_[hidden])
Date: 2001-04-27 08:11:05


From: <k.hagan_at_[hidden]>
> I'm losing track of what has and hasn't been suggested. Have we
> considered specialising a class template with a static member?
>
> template<class T> class math
> {
> static T const pi;
> };

I don't remember it being mentioned on the list, but I experimented with
it a while back. A problem I noticed is that the value cannot be
specified inline in the template definition, causing most compilers to
be unable to inline the constant in code or perform constant folding.
Also, there is the question of whether a linker can exclude unused
constants from the executable. None of these are issues when using
inline functions.

On the other hand, using a constant for a constant instead of a function
feels more natural. The lure of inline functions comes from a practical
matter addressing today's compilers' limitations. Is there any
realistic hope that compilers before too long would be able to handle a
member function or constant equally well, such that the boost library
could be practical in specifying a "cleaner" interface? I noticed that
gcc supports an extension allowing definition of a static const
float-point type within the class definition, just like what allowed
with ints. However, I'm not familiar enough with gcc to know how to
easily examine the code it generates to see what does with code that it
tuned to make use of its extension.


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