Boost logo

Boost :

Subject: Re: [boost] Units of data
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-07-02 18:40:58


Zachary Turner wrote:
> On Thu, Jul 2, 2009 at 3:41 PM, Steven Watanabe<watanabesj_at_[hidden]> wrote:
>> Zachary Turner wrote:
>>> On Thu, Jul 2, 2009 at 2:07 PM, Steven Watanabe<watanabesj_at_[hidden]>
>>> Thanks. The confusion came from the fact that the syntax I was trying
>>> was being used in some of the examples. But there is something
>>> different about those examples, so that's why it wasn't working. One
>>> of the trig examples has a line:
>>> quantity<plane_angle> theta = 0.375*radians;
>>> for example. I suppose it's due to the fact that radians are the
>>> "primary" unit for this dimension?
>> The difference is that plane_angle is the same unit as radians.
>> In your case, data_capacity is defined as bits, while you are
>> assigning it a value in bytes. Since the units change, the conversion
>> is explicit.
> Well what then do you think is the "correct" or "best" way to support
> what I'm trying to do? It seems like a fairly simple use case but at
> least to me anyway it's turning out to be rather confusing and
> complicated. For example, quantity<> is defined as
> template<class Unit> class quantity;
> yet one of the valid values for Unit is boost::units::dimensionless.

I don't think that there is a boost::units::dimensionless.
There is a boost::units::si::dimensionless, though.

> So are we specifying a unit or a dimension? Clearly something that is
> dimensionless is also unitless but it seems inconsistent for values to
> be either units, or the empty dimension.
> The examples have many occurences of things such as
> quantity<si::length>, quantity<si::mass>, quantity<temperature>, all
> of which in a physical sense are dimensions. feet,yards,meters;
> kilograms, grams, ounces; fahrenheit, celsius, kelvin are all units.
> So I would expect to see quantity<fahrenheit>, quantity<ounces>,
> quantity<inches>, just based on the fact that the template argument is
> named Unit.

In general you should read boost::units::si::length as the unit of length in
the si system.

> However, all of the examples seem to define only 1 valid template
> argument for quantity per dimension per system. So if you want si
> mass then there's 1 thing you can pass to quantity<>, even though with
> all the prefixes there are a multitude of different units for mass
> that are still based on the si system.

The official SI unit of mass is kilograms.
The si system represents a unique set of units.

> I agree that the template argument to quantity should be a unit, but
> then I would expect to be able to declare a quantity<> parameterized
> with every possible unit of length measurement, quantity<feet>,
> quantity<inches>, quantity<mm>, etc. with automatic conversions
> provided between every combination.

The conversions are provided. They are not implicit.

> Maybe I'm just doing it all wrong, I'm not trying to be a PITA or
> anything, at this point I really just want it to work :(
> Maybe units of data storage capacity could be incorporated into boost
> 1.40 since they're pretty common (especially for programmers),
> although ultimately it would still be nice if I could understand how
> to use the library.

In Christ,
Steven Watanabe

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