|
Boost Users : |
Subject: Re: [Boost-users] [units] How to use units with UDT's: was How tomake is_arithmetic true for a UDT
From: John Maddock (boost.regex_at_[hidden])
Date: 2012-07-17 13:33:26
> 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.
1) Define a trait (maybe you already have?) that handles the promotions.
2) Provide defaults for built in types.
3) Document it, and provide an example, plus some concept checks.
The defaults could even be smart - for example if numeric_limits is
specialized for a type, then:
* If the an integer type is arbitrary precision (unbounded in numeric_limits
speak), then there's no need to promote.
* If the type is convertible to double, then you could use that conversion.
But what happens for integers with lots of digits - for example do you
"promote" long long to double? If so you're gaining range but throwing away
digits which may not be what the user wants.
Not sure how much this helps, John.
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