Boost logo

Boost :

From: Jens Maurer (Jens.Maurer_at_[hidden])
Date: 2001-04-24 12:08:12


Ed Brey wrote:
>
> From: "Paul A. Bristow" <pbristow_at_[hidden]>
>
> > // math_constants.hpp <<< math constants header file - the interface.
> > namespace boost
> > {
> > namespace math_constants
> > {
> > extern const long double pi;
> > } // namespace math_constants
> > } // namespace boost

I like the template-based interface proposed earlier better,
because it allows e.g. interval or boost::rational<int> constants.

> How is constant folding accomplished, given that the definition appears
> to be out-of-line?

Allowing constant folding (or not) is a quality-of-implementation issue
and should not affect the interface. (In particular, implementors
may choose to define the constants inline, but that's not what I'd
do for the generic boost implementation.)

> > cout << "pi is " << boost::math_constants::pi << endl;
> > using boost::math_constants::pi; // Needed for all constants used.
> > // recommended as useful documentation! whereas:
> > // using namespace boost::math_constants; // exposes ALL names in
> > math_constants.
> > // that could cause some name collisions!
>
> Pulling all math constants into the global namespace is indeed asking
> for trouble in general, although it would be nice to allow it as it can
> be practical within a function.

"using namespace" directives within a function scope are ok, and may
save some typing within the function. Name collisions are entirely
the responsibility of the function's author.

Jens Maurer


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