|
Boost Users : |
Subject: [Boost-users] [units] division with absolute temperature
From: João Leal (joaoruileal_at_[hidden])
Date: 2016-04-18 05:32:38
Hello,
I'm trying to use absolute temperature in some expressions.
Unfortunately I'm having some issues with the compilation.
For instance, if I divide an absolute temperature by itself I would expect
to get 1 dimensionless, however that will cause a compilation error.
#include <iostream>
#include <boost/units/absolute.hpp>
#include <boost/units/io.hpp>
#include <boost/units/quantity.hpp>
#include <boost/units/systems/si.hpp>
#include <boost/units/systems/si/io.hpp>
int main(int argc, char** argv) {
using namespace boost::units;
quantity<si::temperature> rT(273.15 * si::kelvin); // relative
temperature
quantity<si::dimensionless> v;
v = rT / rT;
std::cout << v << std::endl; // 1 dimensionless
quantity<absolute<si::temperature> > aT(273.15 *
absolute<si::temperature>()); // absolute temperature
//v = aT / aT; // uncommenting this line will cause compilation errors
//std::cout << v << std::endl; // 1 dimensionless
return 0;
}
If I uncomment the line with v = aT / aT, in ubuntu 15.10 with boost 1.58
and gcc 5.2.1, I get the error:
(...)
/usr/include/boost/units/operators.hpp:81:5: error: no match for
âoperator/â (operand types are
âboost::units::absolute<boost::units::unit<boost::units::list<boost::units::dim<boost::units::temperature_base_dimension,
boost::units::static_rational<1l> >, boost::units::dimensionless_type>,
boost::units::homogeneous_system<boost::units::list<boost::units::si::meter_base_unit,
boost::units::list<boost::units::scaled_base_unit<boost::units::cgs::gram_base_unit,
boost::units::scale<10l, boost::units::static_rational<3l> > >,
boost::units::list<boost::units::si::second_base_unit,
boost::units::list<boost::units::si::ampere_base_unit,
boost::units::list<boost::units::si::kelvin_base_unit,
boost::units::list<boost::units::si::mole_base_unit,
boost::units::list<boost::units::si::candela_base_unit,
boost::units::list<boost::units::angle::radian_base_unit,
boost::units::list<boost::units::angle::steradian_base_unit,
boost::units::dimensionless_type> > > > > > > > > > > >â and
âboost::units::absolute<boost::units::unit<boost::units::list<boost::units::dim<boost::units::temperature_base_dimension,
boost::units::static_rational<1l> >, boost::units::dimensionless_type>,
boost::units::homogeneous_system<boost::units::list<boost::units::si::meter_base_unit,
boost::units::list<boost::units::scaled_base_unit<boost::units::cgs::gram_base_unit,
boost::units::scale<10l, boost::units::static_rational<3l> > >,
boost::units::list<boost::units::si::second_base_unit,
boost::units::list<boost::units::si::ampere_base_unit,
boost::units::list<boost::units::si::kelvin_base_unit,
boost::units::list<boost::units::si::mole_base_unit,
boost::units::list<boost::units::si::candela_base_unit,
boost::units::list<boost::units::angle::radian_base_unit,
boost::units::list<boost::units::angle::steradian_base_unit,
boost::units::dimensionless_type> > > > > > > > > > > >â)
BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,
(typeof_::make<X>()/typeof_::make<Y>()))
(...)
I could add something like
namespace boost {
namespace units {
template<class Unit, class X, class Y>
struct divide_typeof_helper<quantity<absolute<Unit>, X>,
quantity<absolute<Unit>, Y> > {
typedef typename divide_typeof_helper<X, Y>::type value_type;
typedef typename divide_typeof_helper<Unit, Unit>::type unit_type;
typedef quantity <unit_type, value_type> type;
};
}
}
but that would not work in more complex examples, e.g.:
#include <boost/units/systems/si/codata/physico-chemical_constants.hpp>
(...)
using namespace boost::units::si::constants::codata;
typedef boost::mpl::divides<boost::units::energy_dimension,
boost::units::amount_dimension>::type Ea_dimension;
typedef boost::units::unit<Ea_dimension, boost::units::si::system> Ea;
quantity<Ea> ea(0);
auto x = ea / (R * aT);
Any help would be most appreciated,
João Leal
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