Boost logo

Boost Users :

Subject: Re: [Boost-users] units
From: Nathan Crookston (nathan.crookston_at_[hidden])
Date: 2013-09-22 10:35:22


On Sun, Sep 22, 2013 at 12:38 AM, Robert Ramey <ramey_at_[hidden]> wrote:
> Nathan Crookston wrote:
>> Hi Robert,
>>
>> It's a little confusing
>
> it refers to my test case or the units library?

"It" being the units library -- specifically how systems relate to the
unit and quantity and determines what's printed.

> I concede that I don't get the "system" concept. It's hardly mentioned
> in the documentation. I sort of had the feeling that all the units
> had to be part of the same "system" in order to automatically
> converted.

Yeah, I didn't really get it (I still might not completely get it),
but generally conversions are defined in terms of base_units. When
you want to store a value as a particular type (as opposed to
converting to si units, for example), you need to have a system which
can represent that particular type.

> hmmm - so this doesn't use the header ?
> #include <boost/units/base_units/us/gallon.hpp>

It does, I just moved it up where it could be used by the make_system
metafunction.

> OK - but now how would I output in meters^3/second ? It seems that the
> output is coupled to the way the unit is setup. I would have expected
> that the format of the output display could be delayed until the actual
> output operation is performed - just like i can on input.

To display in si, you can do what you did before -- create a
consumption_rate_unit based on the si system -- perhaps you could have
a us_consumption_rate and an si_consumption_rate_unit. Usage could be
something like: cout <<
static_cast<quantity<si_consumption_rate_unit,float> >(value /* type
quantity<us_consumption_rate,float> */);

HTH,
Nate


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