Boost logo

Boost Users :

Subject: [Boost-users] boost::units - converting from one derived_dimension to another across systems (imperial to metric)
From: Matt Vinson (matt.vinson_at_[hidden])
Date: 2018-11-14 12:04:04


I am having trouble converting from one derived_dimension to another across systems (imperial to metric).  I'd like to convert, say, lb/in to, say, kg/m.  I thought I would do the following but get a compiler error #:
*.h--------------------------------------------------------------------------------
namespace dimensional_analysis {
    namespace lineal_force {        //lb/in
        typedef boost::units::derived_dimension<
            boost::units::us::pound_force_base_unit, 1,
            boost::units::us::inch_base_unit, -1
        >::type lb_per_inch_dimension;
        typedef boost::units::unit<
            lb_per_inch_dimension,
            dimensional_analysis::lengths::ip_system
        > lb_per_inch_unit;
        typedef boost::units::quantity<lb_per_inch_unit, double> lb_per_inch_quantity;
        BOOST_UNITS_STATIC_CONSTANT(lbpin, lb_per_inch_quantity);
         //kg/m
        typedef boost::units::derived_dimension<
            boost::units::si::kilogram_base_unit, 1,
            boost::units::si::meter_base_unit, -1
        >::type kg_per_meter_dimension;
        typedef boost::units::unit<
            kg_per_meter_dimension,
            boost::units::si::system
        > kg_per_meter_unit;
        typedef boost::units::quantity<kg_per_meter_unit, double> kg_per_meter_unit_quantity;
        BOOST_UNITS_STATIC_CONSTANT(kgpm, kg_per_meter_unit_quantity);
    }//lineal_force
}//dimensional_analysis
*.cp ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Do I need these?
BOOST_UNITS_DEFINE_CONVERSION_FACTOR(dimensional_analysis::lineal_force::kg_per_meter_unit, dimensional_analysis::lineal_force::lb_per_inch_unit, double, 0.0559974); // exact conversion
BOOST_UNITS_DEFAULT_CONVERSION(dimensional_analysis::lineal_force::kg_per_meter_unit, dimensional_analysis::lineal_force::lb_per_inch_unit);

//This does not compile#
const auto conv_factor_try0 = conversion_factor(dimensional_analysis::lineal_force::kg_per_meter_unit::unit_type(), dimensional_analysis::lineal_force::lb_per_inch_unit::unit_type());
# *\boost_1_68_0\boost\units\detail\conversion_impl.hpp(340): error C2672: 'conversion_factor': no matching overloaded function found (compiling source file...*.cpp)
Any help is appreciated



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