Boost logo

Boost :

From: Matthias Troyer (troyer_at_[hidden])
Date: 2006-08-23 05:26:19


On Aug 22, 2006, at 4:54 PM, Andy Little wrote:

>
> "Matthias Troyer" <troyer_at_[hidden]> wrote in message
> news:733C7C06-D235-453C-A2CA-CCF3F7DFA165_at_itp.phys.ethz.ch...
>>
>> On Aug 20, 2006, at 8:36 PM, Andy Little wrote:
>>
>>>
>>> "Matthias Troyer" <troyer_at_[hidden]> wrote
>>>
>>>> OK, this sounds reasonable enough, except that I'm still confused
>>>> what exactly an anonymous quantity is.
>>>
>>> I realise I didnt answer this question.
>>>
>>> In the calculation:
>>>
>>> force * distance;
>>>
>>> The programmer might be dealing with a force acting at a moment, or
>>> the energy
>>> required to move an object.
>>> There is no way to tell from the calculation which. (One could
>>> apply some
>>> angular tag to torque, but after experimenting with this I found it
>>> rather vague
>>> and fussy).
>>>
>>> Therefore, as there is no way to tell which quantity is intended I
>>> don't try, so
>>> the result is an anonymous quantity.
>>>
>>> One could apply various rules (for instance length * length -->
>>> area), but as I
>>> can't apply a rule easily to the above case, I opted to apply the
>>> same rule to
>>> every case of dimensionful multiplication and division, which was
>>> to return an
>>> anonymous quantity and leave it to the programmer to decide which
>>> quantity they
>>> were dealing with.
>>
>> As far as I understand, the named quantities just use special symbols
>> then? Actually Nm is a valid unit for both energy and torque, but you
>> sometimes want it printed as J and sometimes as Nm, and you use named
>> quantities to force this? Is this correct?
>
> Yes.
>
> The ability to identify a particular quantity must have a variety
> of uses. Quan
> provides a means to get at the name:
>
> #include <quan/torque.hpp>
> #include <quan/energy.hpp>
> #include <iostream>
> int main()
> {
> typedef quan::meta::get_named_quantity_traits<
> quan::torque::N_m::unit
>> ::type torque_traits;
>
> typedef quan::meta::get_named_quantity_traits<
> quan::energy::J::unit
>> ::type energy_traits;
>
> std::cout << torque_traits::abstract_quantity_name() <<'\n';
> std::cout << energy_traits::abstract_quantity_name() <<'\n';
>
> }
> /*
> output:
> torque
> energy
> */
>
> I could imagine that being useful to look up some custom data in a
> map or to
> access a database for example.

I have a question here: what is the purpose of these named quantities
  - is it to output J instead of kgm^2s^2 for energy and Nm instead
of kgm^2s^2 for torque?
  - is it to prevent adding energy and torque?

Matthias


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk