I want to use boost::units for some SI metrics. However our code mostly deals with millimeters and instead of using
quantity value = 1*milli*m
I am using the following approach:
// your namespace name for units
namespace outernamespace {
namespace millimeter_system {
typedef boost::units::scaled_base_unit>> millimeter_base_unit;
typedef boost::units::make_system::type system;
typedef boost::units::unit length;
BOOST_UNITS_STATIC_CONSTANT(millimeter, length);
BOOST_UNITS_STATIC_CONSTANT(millimeters, length);
}
typedef boost::units::quantity 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 m = 0.004 * meter;
if (mm < static_cast(m)) {
std::cout << 'lt ' << std::endl;
}
else {
std::cout << 'geq ' << std::endl;
}
}