From: Deane Yang (deane_yang_at_[hidden])
Date: 2006-08-27 00:09:24
Andy Little wrote:
> "Deane Yang" <deane_yang_at_[hidden]> wrote in message
>> Andy Little wrote:
>>>> Can the dimension checking part of the library be used without the SI
>>>> unit system? For most other unit systems I use, I mainly need
>>>> dimension checking and not conversions between different units, such
>>>> as km or m? Thus just a quantity with dimensions would be useful to
>>>> catch programming errors.
>>> Yes. In the signature fixed_quantity<Unit, ValueType>, the Unit parameter
>>> be so modelled that it only allows base units to be used, and in this case
>>> is no conversion overhead BTW, a multiply is simply a multiply of the numeric
>>> values for example). By default Quan wont work across Unit models (IOW the
>>> class template names of units must match), which means that attempting to do
>>> calculations between Units with different class template names will fail at
>>> compile time. By this means you can guarantee that you can prevent any
>>> conversions. (FWIW there is also the option to allow unit conversions but
>>> them explicit, prompted by Deane Yang easrlier in this thread.)
>> I guess I wasn't particularly clear earlier in this thread, because
>> fixed_quantity appears to be what I want. I'm sorry for not RTFM (I did
>> try to read the documentation once, but my memory is not what it used to
>> be), but I have two quick questions:
>> 1) Does operator*(fixed_quantity<Unit1, ValueType1> x,
>> fixed_quantity<Unit2, ValueType2> y) work and, if so, what is the result
>> type, assuming that operator*(ValueType1 v, ValueType2 w) returns a
> OK. The following relates to the CVS version currently on the two_param-branch,
> but much applies to previous versions of Quan/PQS.
> Dealing with the ValueTypes first, the result type of ValueType1 * ValueType2
> is encoded in the compile time expression:
> binary_operation<ValueType1,times, ValueType2>::type.
> The implementation provides a specialisation for inbuilt types, and this follows
> the promotion/conversion rules on the respective calc in the C++ standard.
> We have also been recently testing with boost::numeric::interval and (with the
> appropriate specialisations) this seems to be working now and I believe that
> other numeric UDT ValueTypes will now work OK.
Does this mean that if ValueType1, ValueType2, and ValueType3 are UDT's
and I do something like:
typedef ValueType3 type;
then everything will work properly?
> The dimension of the result is found by adding the respective dimensions of the
> operands. ...
Oops. I guess fixed_quantity has to have one of the physical dimensions
represented in SI units, eh? Never mind.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk