Boost logo

Boost Users :

Subject: Re: [Boost-users] [units] Creating specific unit quantities
From: Matthias Schabel (boost_at_[hidden])
Date: 2011-03-08 13:24:45


> Is the following set of statements correct. si::length has a length_dimension and is part of the si::system.

Yes

> boost::units::si::meter_base_unit::unit_type has a length_dimension and is part of the si::system.

No - it has length_dimension and is a part of its own system made up of meter_base_unit only.

> boost::units::us::foot_base_unit::unit_type has a length_dimension and is part of the us system.

No - it has length_dimension and is a part of its own system made up of foot base_unit only

> Since an explicit conversion is needed I definitely don't understand the differences between the following three statements. I've included examples to show my limited understanding.
>
> implicit conversion of quantity<Unit,Y> to quantity<Unit,Z> is allowed if Y and Z are implicitly convertible.
>
> quantity<si::length, int> to quantity<si::length, double>

Yes

>
> explicit conversion between quantity<Unit1,Y> and quantity<Unit2,Z> is allowed if Unit1 and Unit2 have the same dimensions and if Y and Z are implicitly convertible.
>
> quantity<us::foot_base_unit::unit_type, int> to quantity<si::length, double>
> Both have the same length dimension.

Yes

>
> implicit conversion between quantity<Unit1,Y> and quantity<Unit2,Z> is allowed if Unit1 reduces to exactly the same combination of base units as Unit2 and if Y and Z are convertible.

You should look at how systems are defined, for example in <boost/units/base_unit.hpp> and <boost/units/systems/si/base.hpp>. Essentially, if you create a unit from a base_unit, the resulting unit exists in a system of its own containing only that base_unit. The reason for this is that multiple systems can share some of the same base_units : both SI and CGS have seconds as the base unit of time. Thus, if you didn't propagate information about the system, it would be possible to "forget" what system you were operating in. In general, when using Boost.Units you should assume that any conversions between units must be explicit.

Matthias



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net