|
Boost : |
From: Deane Yang (deane_yang_at_[hidden])
Date: 2004-01-22 21:52:57
Daniel Frey wrote:
>
> The problem with constants is generic programming. Consider:
>
> template< typename T > T area( const T& r ) {
> return pi * r * r;
> }
>
> Now think of different T's, mixed arithmetics, loss of precision, no
> conversion from double to T (e.g. boost::rational, Roguewave's
> RWDecimal<>, ...). You need a pi in the above example which is truly
> generic. *That* is what I'm working on, the syntax pi vs. pi() is just
> syntactic sugar (although I strongly prefer pi over pi()). More on that
> when I finished the restructuring due to the unit libraries :)
>
You can do that? That would be absolutely awesome.
But are you really trying to coordinate with the unit libraries?
If so, shouldn't the function be something like
template< typename length_units, typename area_units>
area_units area( const length_units& r )
{
return pi * r * r;
}
Can you really implement "pi" so that it is able to look inside "r"
and figure out what numeric type "pi" should be?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk