Boost logo

Boost :

From: Ed Brey (edbrey_at_[hidden])
Date: 2001-10-24 14:33:28

From: "Peter Dimov" <pdimov_at_[hidden]>

> namespace math
> {
> float const pi_f = ...;
> double const pi = ...;
> long double const pi_l = ...;
> }

I like this. The only disadvantage is that someone using, say floats, can't get access to unqualified, minimally named constants with a simple using statement. However, if we can assume use of anything besides double is rare, this is OK.

> Note: no 'constants' subnamespace. I know that 'pi' is a constant, thanks.
> :-)

The value of the constants namespace is not to help those who slept through trig, but to allow easy access to all the math constants through a using directive, without there being so many items pulled in that a significant risk of collision appeared.

This value is limited by two points, however: (1) It will probably be uncommon when more than small handful of constants is needed, so the convenience of the directive is small. (2) There probably will be a small number of names within "math", so the chance of collision given a using directive will still be quite small.

Given these thoughts, I agree that the "constants" namespace can go.

> Will this do?

Yes, to the non-generic part of the problem. It is still desirable to have a generic interface, but it is allowed to be completely different. For example, I expect that the strong sentiment for a parentheses-free solution doesn't exist in the domain of generic coding. In my opinion the numeric_limits' pattern is best here:

namespace math {
    template<typename T>
    struct constant {
        T pi();

This would be in addition to the math::pi interface.

Boost list run by bdawes at, gregod at, cpdaniel at, john at