
Answering to myself: On Mar 12, 3:04 pm, alfC <alfredo.cor...@gmail.com> wrote:
Hi, Sometimes it is difficult to make boost::units quantities with other libraries. For example to have boost::accumulators mean work with units, one has to specialize division by integer for quantities.
In this example the accumulators and units compiles out of the box but gives an incorrect answer.
I found the solution, just add #include<boost/units/limits.hpp> in this way the min/max function can initialize the default maximum/ minimum value, which is given by the numeric limits of the type. Anyway, I would suggest to the authors of boost.units to include limits.hpp by default in the core library in order *to avoid this surprises*. Or better yet, make the author of boost.accumulators to support boost.units. By the way I made boost accumulators to work with min, max (see above) and mean by adding the below code. Variance, etc. is more difficult to implement because boost.accumulators assumes that t*t is always of type t. namespace boost {namespace numeric{namespace functional{ using namespace boost::units; template<class Unit, typename Y> struct quantity_tag{}; template<class Unit, typename Y> struct tag<quantity<Unit,Y> >{ typedef quantity_tag<Unit,Y> type; }; template<typename Left, typename Right> struct average<Left, Right, quantity_tag<typename Left::unit_type, typename Left::value_type>, void>{ typedef Left result_type; result_type operator()(Left & left, Right & right) const{ return left/(typename Left::value_type)right; } }; }}} Thanks, Alfredo