Michael Powell wrote:
> On Tue, Aug 30, 2011 at 6:29 AM, Michael Powell
> <
mwpowellnm@gmail.com>wrote:
>
>>
>>
>> On Tue, Aug 30, 2011 at 2:04 AM, Thomas Taylor
>> <
thomas.taylor@univie.ac.at
>> > wrote:
>>
>>> Could you please review the following patch for inclusion in
>>> boost::units?
>>>
>>> *WHY*: Obviously this only defines a conversion for boost::units::one to
>>> a numerical 1. When trying to convert at runtime (aiming for a
>>> runtime/dynamic
>>> unit instead of the compiletime/static unit provided) I use the
>>> following function:
>>>
>>> template <typename U1, typename U2>
>>> double unit_dispatch2t(U1 const& u1, U2 const& u2) {
>>> return bu::conversion_factor(u1,u2);
>>> }
>>>
>>> where U1 and U2 are boost::unit::unit derivatives.
>>>
>>> Without a conversion operator the compiler chickens out by claiming to
>>> not be able to convert boost::units::one to (in my case) double. The
>>> added conversion operator allows successfull compilation, thus allowing
>>> actual runtime units (my application needs to handle calculations where
>>> some units
>>> are known at compiletime and some only at runtime (e.g. the user wants
>>> the calculation to be done in meters or millimeters)).
>>>
>>
>> Oh, the runtime question. Here's how we've decided to approach this.
>>
>> I'll just tell you, I find the compile-time safety attractive. For
>> runtime, we've decided that calculations should be done in a base unit.
>>
>> For anything else, we *convert to* a view unit, for display or report or
>> what not.
>>
>
> I should clarify too, in this type of use case, we still know what the
> compile-time units should necessarily be. The runtime I like to think of
> is the user selecting: system, and possibly also unit. Which is what your
> aiming for here?