Boost logo

Boost :

From: Ed Brey (edbrey_at_[hidden])
Date: 2001-10-25 16:44:38


From: "Fernando Cacciola" <fcacciola_at_[hidden]>
> >
> > Of course, there is still the option of simply providing a bunch of simple
> double constants for non-generic uses, and then a separate simple function
> interface for generic uses, like this
> >
> > template<typename T>
> > struct constants {}
> >
> > template<>
> > struct constants<double> {
> > static double pi() {return 3.14;}
> > }
> >
> There is a problem with this: it doesn't allow you to add new constants.
> IMO, the design must contemplate the case of adding new constants with as
> much the same interface as possible.

The user can add his own constants in a similar structure in his own namespace. He can't add them safely to the boost namespace under any circumstance, because boost might later define something using the same name, and there would be a conflict.

Specialization is another issue. Something like:

template<>
 struct constants<my_rational> {
     static double pi() {return rational(22,7);}
}

in boost::math would be fine. Of course, I find the concept of representing an irrational number using a rational class kind of amusing, but I suppose it might have practical value.


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