c++ - Converting units in boost.units from angular_velocity to degrees_per_second -
i need make conversion general angular_velocity degrees/second.
to illustrate problem example boostunits.cpp:
#include <boost/units/systems/si.hpp> #include <boost/units/systems/angle/revolutions.hpp> #include <boost/units/systems/angle/degrees.hpp> #include <boost/units/conversion.hpp> #include <boost/units/pow.hpp> #include <iostream> #include <iterator> #include <algorithm> int main() { boost::units::quantity< boost::units::si::angular_velocity> m_speed( (30.0*boost::units::si::radians_per_second) ); std::cout << "m_speed: " << m_speed << std::endl; uint32_t result = static_cast<uint32_t>( boost::units::quantity<boost::units::si::angular_velocity,uint32_t>( m_speed*boost::units::degree::degrees/boost::units::si::seconds ).value() ); std::cout << " result: "<< result << std::endl; return(0); }
produces compiler output:
g++ boostunits.cpp /usr/local/include/boost/units/detail/conversion_impl.hpp: in static member function ‘static boost::units::quantity<unit2, t2> boost::units::conversion_helper<boost::units::quantity<unit1, t1>, boost::units::quantity<unit2, t2> >::convert(const boost::units::quantity<unit1, t1>&) [with unit1 = boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::degree_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::si::second_base_unit, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::radian_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::dimensionless_type> > >, boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::dimensionless_type> >, void>, t1 = double, unit2 = boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000001l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<1l, 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, 1l> > >, 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> > > > > > > > > >, void>, t2 = unsigned int]’: /usr/local/include/boost/units/quantity.hpp:193: instantiated ‘boost::units::quantity<unit, y>::quantity(const boost::units::quantity<unit2, yy>&, typename boost::disable_if<boost::mpl::and_<typename boost::units::is_implicitly_convertible<unit2, unit>::type, boost::units::detail::is_non_narrowing_conversion<yy, y>, mpl_::bool_<true>, mpl_::bool_<true>, mpl_::bool_<true> >, typename boost::units::detail::disable_if_is_same<unit, unit2>::type>::type*) [with unit2 = boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::degree_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::si::second_base_unit, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::radian_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::dimensionless_type> > >, boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::dimensionless_type> >, void>, yy = double, unit = boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000001l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<1l, 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, 1l> > >, 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> > > > > > > > > >, void>, y = unsigned int]’ boostunits.cpp:16: instantiated here /usr/local/include/boost/units/detail/conversion_impl.hpp:345: error: no matching function call ‘conversion_factor(boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::degree_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::si::second_base_unit, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::radian_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::dimensionless_type> > >, boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::dimensionless_type> >, void>&, boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000001l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<1l, 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, 1l> > >, 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> > > > > > > > > >, void>&)’
what syntax achieve desired type specification , subsequent conversion? need specify degrees_per_second unit, , if so, how?
documentation: http://www.boost.org/doc/libs/1_37_0/doc/html/boost_units.html
thank in advance help.
steven wantabe provided solution on boost-users mailing list.
implemented working example below.
boostunits.cpp:
#include <boost/units/systems/si.hpp> #include <boost/units/systems/angle/revolutions.hpp> #include <boost/units/systems/angle/degrees.hpp> #include <boost/units/conversion.hpp> #include <boost/units/pow.hpp> #include <boost/units/io.hpp> #include <iostream> #include <iterator> #include <algorithm> typedef boost::units::divide_typeof_helper< boost::units::degree::plane_angle, boost::units::si::time >::type degrees_per_second; int main() { boost::units::quantity< boost::units::si::angular_velocity> m_speed( (30.0*boost::units::si::radians_per_second) ); std::cout << "m_speed rad/sec: " << m_speed << std::endl; std::cout << "m_speed deg/sec: " << static_cast< boost::units::quantity<degrees_per_second> >(m_speed) << std::endl; uint32_t result = static_cast<uint32_t>( static_cast< boost::units::quantity<degrees_per_second> >(m_speed).value()); std::cout << "int result: "<< result << std::endl; return(0); }
terminal output:
g++ boostunits.cpp ./a.out m_speed rad/sec: 30 s^-1 rad m_speed deg/sec: 1718.87 deg s^-1 int result: 1718
Comments
Post a Comment