
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of John Maddock Sent: Thursday, July 12, 2012 10:32 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] How to make is_arithmetic true for a UDT
I am facing the need to get my User Defined Type to return true from
boost::is_arithmetic
You don't, a UDT is not an arithmetic type (according to the type system which is what type_traits honors) it's a class type.
(This is to meet a check for autoprefixing in Boost.Units)
Looks like there are two places this is used in Units - and both are implementation details - for auto- prefixing looks like you need to overload autoprefix_norm for your type. The other use is in is_non_narrowing_conversion, which you would [partially-] specialize for your type.
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 :-)) 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. I can see the need for this template<> struct is_non_narrowing_conversion<long double, double> : mpl::false_ {}; So would I need template<> struct is_non_narrowing_conversion<measurement< double>, double> : mpl::true_ {}; but template<> struct is_non_narrowing_conversion<measurement<long double>, double> : mpl::false_ {}; (though the existence of more than one FP type in the class, means that one needs to call measurement value() function to get a double, so the answer always false?). Paul --- Paul A. Bristow, Prizet Farmhouse, Kendal LA8 8AB UK +44 1539 561830 07714330204 pbristow@hetp.u-net.com