|
Boost Users : |
Subject: Re: [Boost-users] [units] How to use units with UDT's: was How to make is_arithmetic true for a UDT
From: Matthias Schabel (boost_at_[hidden])
Date: 2012-07-17 13:21:15
>> Well I finally managed to string enough neurons together to write
>>
>> // Specialization of autoprefix_norm for boost::units::measurement<Y>
>> // See io.hpp
>> // This is required to get autoprefix to work with this class.
>> template<class Y>
>> typename autoprefix_norm_impl<boost::units::measurement<Y>, true>::type
>> autoprefix_norm(const boost::units::measurement<Y> & arg)
>> {
>> return autoprefix_norm_impl<Y, true>::call(arg);
>> }
>>
>> and that does the trick :-))
>
> Hold on a second, doesn't that just tell Units to treat all T's as if they're double? Or is the type measurement your type?
>
> In any case autoprefix_norm_impl<T, true>::type appears to be always double, what happens if the UDT can't fit in a double?
>
> There's also a distinct lack of documentation on this, this page: http://www.boost.org/doc/libs/1_50_0/doc/html/boost_units/Reference.html mentions autoprefix_norm, but doesn't say what an overload should actually do :-(
I'll let Steven address the autoprefixing stuff as that is his work...
>> quantity<length, measurement<double> >
>> biglen(measurement<double>(12345.0,123.0)*meters); autoscaled = 12.345(+/-0.123) km
>>
>> so many thanks.
>>
>> But I'm still not clear when I could need the non-narrowing conversion in Boost.units quantity.hpp.
>
> Nor me, there's no docs on this at all.
>
> I think it would help a great deal if the Units guys could chime in here and/or and a section on using Units with UDT's.
Unfortunately, conversions and UDTs are a particularly difficult area since it is difficult to know in all cases how one should promote the UDT or construct an appropriately promoted UDT. For example, converting integer feet to integer meters doesn't work, so the resulting quantity needs to be a double. We can special case these types of conversions, but there is no obvious way to know a priori how to do the promotion for an arbitrary UDT... Suggestions, of course, are always welcome.
Matthias
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net