|
Boost Users : |
Subject: [Boost-users] [Units][Interval] Using both together
From: Anubis (kerub_at_[hidden])
Date: 2009-07-03 13:30:44
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
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