Boost logo

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: Paul A. Bristow (pbristow_at_[hidden])
Date: 2012-07-17 13:57:42


> -----Original Message-----
> From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf
Of
> Matthias Schabel
> Sent: Tuesday, July 17, 2012 6:21 PM
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] [units] How to use units with UDT's: was How to make is_arithmetic true
for a
> UDT
>
> >> 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.ht
> > ml 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.

My need is for UDTs that have more than one element, typified by the examples of mean and standard
deviation in measurement.hpp.

I hope that these work OK because all these are floating-point types (something that could be - or
perhaps already is - checked at compile time).

I'll provide feedback when I have experience using them.

With John's assistance, I have now got autoprefixing to work for my purposes by specializing
autoprefix_norm.

I think it would be worth adding this specialization to the measurement.hpp example and will do this
if you agree.
A one line example could be added to the kitchen sink example to show autoprefixing in action with
the existing UDT measurement.

It may be worth noting that this caused me some grief because the namespace of autoprefix_impl is
boost::units, but the namespace of autoprefix_norm must be specialized in *my* UDT's namespace.
Obvious in hindsight but caused some head scratching :-(

Paul

 


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