Hello all!
First let me congratule Matthias and Steven for the great units library.
Just recently I have kicked out my own attempt at something like it and
switched to boost::units.
However I ran into trouble using both boost::units and boost::interval
because a single int cannot be static casted to a quantity.
So one could either provide a function like:
static boost::units::quantity quantity(int aValue) {
boost::units::quantity::from_value(aValue); }
Probably not the best idea as any value would get casted to a quantity
without notice, therefore totally ruining the concept of from_value.
Or as I have implemented a specific checking policy for boost::interval:
#include
//! The checking policy for boost::interval, if it uses boost::unit
/*!
Look into boost/numeric/interval/checking.hpp to see other possible base
checking policies for template parameter Checking
*/
namespace boost { namespace units { namespace interval_support {
template
struct checking_base : Checking
{
static T empty_lower()
{
return (std::numeric_limits<T>::has_quiet_NaN ?
std::numeric_limits<T>::quiet_NaN() : T::from_value(1));
}
static T empty_upper()
{
return (std::numeric_limits<T>::has_quiet_NaN ?
std::numeric_limits<T>::quiet_NaN() : T::from_value(0));
}
};
}}}
And actually use it like this:
#include // or whichever name
typedef
boost::numeric::interval_lib::change_checking<
boost::numeric::interval,
boost::units::interval_support::checking_base
::type
my_unit_interval_type;
HTH to easily use boost::units and boost::interval in the future,
Thomas Taylor