Boost logo

Boost :

From: Lewis Hyatt (lhyatt_at_[hidden])
Date: 2007-03-30 18:01:13

> The problem with the "multiplier" usage is it uses a unit name (plural,
> singular, whatever) for both type information and rvalue expressions.
> quantity<second[s]> t1 (2.0 * second[s]);
> This usage may be preferable to scientists and engineers but not C++
> programmers, I'll gar-on-tee.

What you wrote doesn't make sense, since seconds is an object, not a type.

The point is that the actual syntax is:

quantity<SI::time> t1 = 2.0 * SI::seconds;

I think this is an important abstraction, that there is a fundamental
difference between the physical dimension (time), and the particular
units used to measure it (seconds). The syntax makes this clear. The
user may be aware that SI::time is represented in seconds in the library
internals, but they don't *need* to know this to write dimensionally
correct code. (And they will find out eg when they output the value).

The fact that SI::seconds is just a static object of type SI::time is
not relevant to the fact that "time" and "seconds" have very different

This becomes more clear when you do something like

quantity<SI::time> t1 = 2.0 * SI::seconds;
quantity<SI::time> t2 = 2.0 * English::fortnights;
cout << t1 - t2 << endl;

Here, the user doesn't need to worry that t1 and t2 were specified in
different units, because they both are quantities of type
quantity<SI::time>, so it makes sense to subtract them.

The multiplicative syntax seems to me like the most natural choice to
handle this usage. As far as I can tell, you seem to be arguing that the
usage of "SI::seconds" in the definition of t1 is redundant, because
SI::time already implies that the time is measured in seconds, but
that's not really the spirit of what a quantity<> is. A quantity<>
doesn't represent something in a particular set of units (such as
seconds), but rather something that measures a particular physical
dimension (such as time). The fact that the quantity<> internally has to
choose a unit to represent that dimension is not as important as the
fact that the quantity<> does fundamentally represent a physical dimension.

Anyway, that's just my interpretation of how this library design works,
   and IMHO I think it is a good, logical design.


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