Boost logo

Boost :

From: Matthias Schabel (boost_at_[hidden])
Date: 2004-01-09 10:38:14

>> Maybe the
>> solution would be to have a default converter which looks something
>> like
>> template<typename model1,typename model2>
>> convert<length_unit<model1>,length_unit<model2> >
>> which uses SI as a common base and if the unit doesn't support
>> conversion to/from SI, then the user would have to write the
>> conversion
>> function themselves... I'll have to think about this more...
> You've pretty much got the support you need already: the toBase()
> method
> in each UnitInfo.
> You can define the "convert<>" function above in term to do (something
> like - clearly this needs to fit into your template framework...)
> return model1::toBase() / model2::toBase();

This is how it works at the moment, which is fine for linear unit
transformations. However, to
convert from Kelvin to Fahrenheit, for example, we need to do an affine
transformation. What I'm thinking is that the unit_info class will
need to define both toBase() and fromBase() so that

struct unit_info<Fahrenheit>
        template<class Y> Y toBase(Y val) { return ((val-32)*(5./9.)); }
        template<class Y> Y fromBase(Y val) { return (val*(9./5.)+32); }

This would allow more or less arbitrary nonlinear unit conversions
where appropriate...

Matthias Schabel, Ph.D.
Utah Center for Advanced Imaging Research
729 Arapeen Drive
Salt Lake City, UT 84108
801-587-9413 (work)
801-585-3592 (fax)
801-706-5760 (cell)
801-484-0811 (home)
mschabel at ucair med utah edu

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