Boost logo

Boost :

From: Lewis Hyatt (lhyatt_at_[hidden])
Date: 2007-03-29 10:56:06


Ben FrantzDale wrote:
> On 3/28/07, Lewis Hyatt <lhyatt_at_[hidden]> wrote:
>> ...
>> Also, quantity<> should pass through operator++ and operator-- in
>> addition to the other arithmetic operators.
>>
>
> I strongly disagree. Those operators make no sense for dimensioned
> quantities; it would be like allowing "12.34 meters + 1".

It is a common idiom that operator++ means "increment by one 'step', in
whatever way is appropriate." For instance, boost::progress_timer
provides operator++. But no one is confused as to its meaning--it is
clear that the increment is perfomed in the natural units of the object
(namely, progress ticks) rather than in absolute numbers. In the
boost::units case, it makes perfect sense that the increment of a
dimensionful quantity is in the appropriate units. For instance:

for(quantity<SI::electric_potential> V = 1 * SI::volt; V !=
10*SI::volt; ++V) {
                cout << "voltage is now at " << V << endl;
        }

I think this is perfectly natural, and should compile. Disallowing this
will force users of more complex types to create temporary objects in
cases where operator++ would render them unnecessary; I think this is
too restrictive.

-Lewis


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