Boost logo

Boost :

From: Lewis Hyatt (lhyatt_at_[hidden])
Date: 2007-03-29 11:08:39

> 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.

OK, I take it back, this shouldn't be supported. Code like this would be
very confusing:

for(quantity<SI::electric_potential> V = 1 * SI::kilo * SI::volt;
     V != 10 * SI::kilo * SI::volt;
     ++V) cout << V << endl;

I guess in that case people might assume the ++ means add 1 kV, instead
of 1V. Since the "natural" unit of increase depends on context, and
people may not always know what the underlying units system is (eg, is
mass in grams or kilograms?), this shouldn't be allowed.


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