
Boost : 
From: Daniel Frey (daniel.frey_at_[hidden])
Date: 20040123 03:41:02
Deane Yang wrote:
> 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;
> }
If you'd like to use a unit library, then you are right. My example was
just a rationale for the constant library for the "normal" programmer
that currently often doesn't know about unitlibraries. But this just
gave me another small idea which is IMHO possible to implement: Both
implementations can share a single 'pi' when it's defined correctly :)
> Can you really implement "pi" so that it is able to look inside "r"
> and figure out what numeric type "pi" should be?
This is exactly what I'm working on at the moment, and using __typeof__
it is possible.
I'm also trying to make the constant library independent of the unit
library, that means I'll try to post an example for Matthias' YANL (the
idealGasLawfunction he posted), but I will not depend on YANL. It is my
hope that the constant library (which doesn't define the constants
itself, it's just a framework for others to define their constants in
the right way) is then used by the different unit libraries around here.
I think I can show the complete idealGasLawexample after this weekend.
Regards, Daniel
 Daniel Frey aixigo AG  financial solutions & technology SchloßRaheStraße 15, 52072 Aachen, Germany fon: +49 (0)241 93673742, fax: +49 (0)241 93673799 eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk