Boost logo

Boost Users :

Subject: [Boost-users] [units] implicit type conversions to specific unit quantity
From: Michael Powell (mwpowellhtx_at_[hidden])
Date: 2015-08-15 12:32:57


I'd like to convert from an SI length quantity to a US inches
quantity. I believe the following snippet will do what I want it to,
but wanted to clarify if that was the case:

I am referencing the online docs, but needed some clarity in actually
how to go about using it in practice:

using boost::units::si::meter_base_unit;
using boost::units::us::inch_base_unit;

// i.e. 0.3048 * 12 (inches/feet, feet/meter)
BOOST_UNITS_DEFINE_CONVERSION_FACTOR(inch_base_unit, meter_base_unit,
double, 3.6576);


quantity<inch_unit> to_inches_length_quantity(quantity<length> const & L) {
    const quantity<inch_unit::unit_type> result_(L);
    return result_;

Just besides that, there isn't a cleaner way of doing it? Some have
mentioned going as far as creating a whole other system for my
calculator's purposes, for example.

Thank you...

Best regards,

Michael Powell

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at