Question

I want to use Boost.Units to represent a quantity expressed in grams per milliliter. I am trying to define the unit "milliliter". If I write

typedef boost::units::make_scaled_unit<
        boost::units::si::volume,
        boost::units::scale<10, boost::units::static_rational<-3> >
>::type liter;

typedef boost::units::make_scaled_unit<
        liter,
        boost::units::scale<10, boost::units::static_rational<-3> >
>::type milliliter;

the code compiles fine, but if I replace my own liter with boost::units::metric::liter_base_unit, then then definition of milliliter fails to compile with a "no type named 'type' in struct boost::units::make_scaled_unit" error. Could you explain me why? Can the unit in make_scaled_unit be a base unit or do I need to make a derived unit from boost::units::metric::liter_base_unit?

Was it helpful?

Solution

I've found the solution. The problem is, as I suggested, that the unit in make_scaled_unit must be a unit type, not a base unit. By replacing boost::units::metric::liter_base_unit with boost::units::metric::liter_base_unit::unit_type, it works.

The code becomes:

typedef boost::units::make_scaled_unit<
        boost::units::metric::liter_base_unit::unit_type,
        boost::units::scale<10, boost::units::static_rational<-3> >
>::type milliliter;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top