Boost logo

Boost Users :

Subject: [Boost-users] Boost.Units Example: Convert between nautical mile and imperial foot
From: Carel Combrink (carel.combrink_at_[hidden])
Date: 2018-09-26 12:57:13


Hi,

I am trying to use Boost.Units to convert between different units.

I have implemented the example code for the "Radar Beam Height" [1] section
but trying to convert between nautical mile and imperial foot result in a
compiler error:

I have:
typedef boost::units::quantity<boost::units::si::length> Meters;
typedef boost::units::quantity<imperial::length> Feet;
typedef boost::units::quantity<nautical::length> NMiles;
double func()
{
    // Working
    const Meters si1(300.0*nautical::miles);
    const Meters si2(300.0*imperial::feet);
    const Feet feet1(300.0*imperial::feet);
    const Feet feet2(300.0*boost::units::si::meters);
    const NMiles mile1(300.0*nautical::miles);
    const NMiles mile2(300.0*boost::units::si::meters);

    // BROKEN
    const Feet feet3(300.0*nautical::miles);
    const NMiles mile3(300.0*imperial::feet);
}

The first few works, converting between meters and the new units, but
converting between the two does not work.

To see the issue see the code on Compiler Explorer here:
https://gcc.godbolt.org/z/MpvuMy

How can I get this working?

[1]
https://www.boost.org/doc/libs/1_68_0/doc/html/boost_units/Examples.html#boost_units.Examples.RadarBeamHeightExample

Regards,



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