
Matthias Schabel <boost <at> schabel-family.org> writes:
But in general we should assume that constructs like this are legit:
quantity<SI::volume> V(1.0*SI::meters*imperial::feet*CGS::centimeters);
where the system of the result type defines the conversions
imperial::feet->SI::meters CGS::centimeters->SI::meters
to get the conversion factor...this is unambiguous in all cases, AFAICS.
This is possible, but is it a good idea? In C++ expressions are context-independent; that is, x * y * z * w always has a specific type T, regardless of whether it's assigned to an int, used to construct a quantity<SI::volume>, passed to a function taking double, or passed to a function template taking X const& x, where X is a template parameter. This has the advantage that it scales well. Consider ( 1.0 * SI::meters + 1.0 * imperial::feet ) * ( 2.0 * CGS::centimeters + 1.0 * imperial::feet ) and other complex expressions. Pushing down a result type may be hard. If your result type is nautical::miles * imperial::miles, how do you decide which of the two branches needs to get the nautical::miles? And this is a relatively simple example.