[Units][Interval] Using both together
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<Unit,Y> quantity(int aValue) { boost::units::quantity<Unit,Y>::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 <boost/numeric/interval.hpp> //! 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<class T, class Checking = boost::numeric::interval_lib::checking_base<T> > 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 <boost/units/interval_support.hpp> // or whichever name typedef boost::numeric::interval_lib::change_checking< boost::numeric::interval<MY_QUANTITY_TYPE>, boost::units::interval_support::checking_base<MY_QUANTITY_TYPE>
::type my_unit_interval_type;
HTH to easily use boost::units and boost::interval in the future, Thomas Taylor
participants (1)
-
Anubis