c++ - Millimeters in boost::units -
i want utilize boost::units si metrics. our code deals millimeters , instead of using
quantity<length> value = 1*milli*meter;
we prefer like
quantity<length> value = 1*millimeter;
however not sure how define "millimeter" (without using #define).
secondly, overhead in using prefixed units?
update: needs run without c++11 features (i.e. no udl)
i using next approach:
// namespace name units namespace outernamespace { namespace millimeter_system { typedef boost::units::scaled_base_unit<boost::units::si::meter_base_unit, boost::units::scale<10, boost::units::static_rational<-3>>> millimeter_base_unit; typedef boost::units::make_system<millimeter_base_unit>::type system; typedef boost::units::unit<boost::units::length_dimension, system> length; boost_units_static_constant(millimeter, length); boost_units_static_constant(millimeters, length); } typedef boost::units::quantity<millimeter_system::length> quantity_millimeter; using millimeter_system::millimeter; using millimeter_system::millimeters; } // demonstration of usage void foo() { using namespace outernamespace; using namespace boost::units; using namespace boost::units::si; quantity_millimeter mm = 5 * millimeter; quantity<boost::units::si::length> m = 0.004 * meter; if (mm < static_cast<quantity_millimeter>(m)) { std::cout << 'lt ' << std::endl; } else { std::cout << 'geq ' << std::endl; } }
c++ boost boost-units
No comments:
Post a Comment