Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2006-06-07 17:33:17

"David Greene" <greened_at_[hidden]> wrote in message
> Andy Little wrote:
>>>I don't see why kg as the "SI unit for mass" requires all this
>>>prefix_offset stuff. You'd just use pqs::mass:kg, right?
>> grammes and milligrammes are common units too. The output of socalled
>> coherent
>> quatities is automated so that its not necessary to customise each units
>> ouput.
>> The prefix_offset is necessary to stick the correct prefix on, usually for
>> mass,
>> but also for anything that starts with mass, like 'mass_flow'.
> Here's my expectation. Tell me if I'm wrong:
> pqs::mass:g grams(10);
> pqs::mass:kg kilograms(10);
> cout << grams << endl;
> cout << kilograms << endl;
> cout << kilograms + grams << endl;
> I'd expect to see something like this:
> 10 g
> 10 kg
> 10.01 kg
> How does this involve prefix_offset at all? What's the point of it?
> How is mass different than, say, length in this regard?

Try this one:

    mass::kg m(1); // 1 kg == 1000 g
    acceleration::m_div_s2 a(1); // 1 meter per second squared
    force::N f = m * a;

    The value of f should be 1000 Newtons right?

Careful.. its a trick question!

> If prefix_offset is not exposed to the user at all, then I submit
> that it serves no useful function in the library and only makes
> the implementation (and extensions) unnecessarily difficult.

The output of a quantity is ultimately based on the class template signature.
That is what the compiler sees. The prefix offset is necessary to construct and
apply the units from that data. Its complicated! As I said before I'm just the
messenger !

Andy Little

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