Boost logo

Boost :

From: Matthias Schabel (boost_at_[hidden])
Date: 2007-03-29 16:50:02


> Hmm. I still don't understand the rationale for the extra
> multiplication
> operation. How is this any different from:
>
> quantity<SI::meter> q(2);

It's a faux operation - the multiplication of a scalar times a unit
(a class with no data members at all) decorates the scalar to produce
a quantity of the appropriate unit and value type. The problem with
using a raw value type for construction can be demonstrated here :

using namespace SI;

/// this is two meters
quantity<length> q(2);

...some months later...

using namespace CGS;

/// uh oh - this is 2 centimeters now
quantity<length> q(2);

The way it's currently implemented, you incur a conversion in the
constructor, but the code remains correct if the units are
convertible and gives a compile time error if they are not...

Matthias


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