#include #include #include #include #include #include #include #include #include #include #include #include #include namespace client { namespace bu = boost::units; namespace units { struct length_base_dimension : bu::base_dimension { }; typedef length_base_dimension::dimension_type length_dimension; namespace my { struct length_base_unit : bu::base_unit { static std::string name() { return "my length"; } static std::string symbol() { return "q"; } }; typedef bu::make_system::type system; typedef bu::unit length; BOOST_UNITS_STATIC_CONSTANT( q, length ); } namespace si { struct meter_base_unit : bu::base_unit { static std::string name() { return "Meter"; } static std::string symbol() { return "m"; } }; typedef bu::make_system::type system; typedef bu::unit length; BOOST_UNITS_STATIC_CONSTANT( meter, length ); typedef bu::scaled_base_unit > > millimeter_base_unit; } } } namespace boost { namespace units { template<> struct base_unit_info { static const char* name() { return("millimeter"); } static const char* symbol() { return("mm"); } }; } } BOOST_UNITS_DEFINE_CONVERSION_FACTOR( client::units::si::meter_base_unit, client::units::my::length_base_unit, boost::int32_t, 1000000000 ); // make conversion to my the default. BOOST_UNITS_DEFAULT_CONVERSION( client::units::si::meter_base_unit, client::units::my::length_base_unit ); int main() { namespace bu = boost::units; using namespace client::units; // OK: 1000000000 q bu::quantity l_m( 1*si::meter ); std::cout << l_m << std::endl; // XXX would expect 1 m bu::quantity l_q( 1000000000*my::q ); std::cout << l_q << std::endl; // engineering prefix may work? // XXX won't compile bu::quantity l_mm( 1*si::meter ); std::cout << l_mm << std::endl; // XXX I like to have also bu::quantity l_m( 1*si::milli*si::meter ); // ... and work with other boost::units::length_systems }