Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2006-08-22 03:54:17

"Matthias Troyer" <troyer_at_[hidden]> wrote in message
> 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?


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<
>::type torque_traits;

    typedef quan::meta::get_named_quantity_traits<
>::type energy_traits;

    std::cout << torque_traits::abstract_quantity_name() <<'\n';
    std::cout << energy_traits::abstract_quantity_name() <<'\n';


I could imagine that being useful to look up some custom data in a map or to
access a database for example.

Andy Little

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