
Hello Matthias, Saturday, January 13, 2007, 8:20:43 AM, you wrote: [snip]
To get things started, here are a few questions I have :
1) At the moment, the library enforces strict construction; that is, quantities must be fully defined at construction :
quantity<double,SI::length> q1(1.5*SI::meters);
is acceptable, but
quantity<double,SI::length> q2(1.5);
is not. Basically, construction of quantities (other than copy construction) is restricted to products/divisors of scalars and units, scalars and quantities, and/or units and quantities. This entails some redundancy, but also avoids errors in generic code where the unit system may change. In addition, I think it makes the intent of the code clearer. Direct construction from a value_type is supported, but through a static member function:
quantity<double,SI::length> q3 = quantity<double,SI::length>::from_value(1.5);
Obviously, in my opinion, this sort of stuff should be restricted to libraries where it is necessary and shouldn't be ubiquitous in user code. I know that there is a camp in favor of implicit unit conversions (which can be supported in the library through a #define, though I think this causes more problems than it is worth), and I have some further thoughts on this below, but I'd like input from the non-implicit crowd as to whether this is a reasonable approach.
[snip] I haven't read any docs or seen the library. Just a thought on spot. May be a cast-like synax would be more natural here? quantity< double, SI::length > q1 = quantity_cast< SI::length >(1.5); quantity< int, SI::length > q2 = quantity_cast< SI::length >(100); And construction with no explicit casting but via explicit constructor should be possible too: quantity< double, SI::length > q1(1.5); quantity< int, SI::length > q2(100); Therefore simply doing this will not work: quantity< int, SI::length > q2 = 100; I think, it is sufficient to make generic code safe. And this IMO should go implicitly: // Conversion from int to double via assignment q1 = q2; // And via construction quantity< double, SI::length > q3 = quantity_cast< SI::length >(100); And quantity conversion should require explicit casting: quantity< double, SI::centigrade > q4; quantity< double, SI::kelvin > q5; q5 = quantity_cast< SI::kelvin >(q4); I don't know, may be there already is something like that in the library. PS: And another couple of cents. Maybe the representation type of "quantity" template should be optional defaulted to double or, the better way, to the type that is natural for the quantity type. I.e., for "SI::length" the "double" would be natural. -- Best regards, Andrey mailto:andysem@mail.ru