Boost logo

Boost :

From: Lewis Hyatt (lhyatt_at_[hidden])
Date: 2007-03-29 15:17:30


Matthias Schabel wrote:
>> While quantity_reinterpret_cast may not be perfectly analogous to
>> reinterpret_cast, it represents the reinterpretation of a raw number
>> as being of a different type, and so I think it's a pretty good name.
>> Just as importantly, I can't think of anything better. Do you have
>> any other ideas? quantity_unsafe_cast? quantity_arbitrary_cast? :)
>
> Sorry, I think I muddied the waters here - I agree that
> quantity_reinterpret_cast should be reserved for those cases where
> access to the raw data is necessary. I was just saying that we can
> write things like
>
> quantity<SI::length,double> q;
> quantity<SI::length,int> r;
> quantity<CGS::length,double> s;
> quantity<CGS::length,int> t;
>
> q = quantity<SI::length,double>(r);
> q = quantity<SI::length,double>(s);
> q = quantity<SI::length,double>(t);
>
> already, so the only non-degenerate use case of quantity_cast is to
> take a raw value and return a quantity:
>
> q = quantity_cast< quantity<SI::length,double> >(1.5);

I think you are right that quantity_cast becomes unnecessary, and in the
last usage there, the user should have to specify the units or use
quantity_reinterpret_cast.

One more thought, instead of:

        q = quantity<SI::length,double>(r);

what about a syntax like
        
        q.convert_from(r)

to emphasize that this is performing a safe unit conversion, and to
avoid having to repeat the type name?

-lewis


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