Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2004-01-07 04:11:20


"Daniel Frey" <daniel.frey_at_[hidden]> wrote

> > Speed s = 2 m / s;

> This is one of the pitfalls! I haven't found a solution, but I'd like to
> point out that it is a problem which needs to be addressed. Units often
> have very brief identifiers which than clash too easily with the
> variables one usually uses. And you don't want to write

> unit::Speed s = 2 * unit::m / unit::s;

My syntax in my physical_quantities type for this is:

q_velocity::m_div_s s(2);

one could quibble about the naming:

q_speed::m_per_s s(2);
q_speed::m_ovr_s s(2);

IOW the units are part of the type declaration.
The q_ prefix is to prevent name collisions.
Unless I'm missing something it is also as legible if not more so and
if operator *() is actually a runtime multiplication in the top example
 over which there seems to be some confusion, better in raw performance
terms,
(no runtime multiplication involved in my declaration).
which I had thought was a critical factor to many.

Alternatively if operator *() does not mean multiplication in the top
example,
then it is rather a misuse of the operator IMO.

regards
Andy Little


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