#include<iostream>
#include <boost/units/systems/si.hpp>
#include <boost/units/systems/si/io.hpp>
using namespace boost::units;
// short hand for meter
namespace t { typedef si::length m; }
namespace i { BOOST_UNITS_STATIC_CONSTANT( m, t::m ); }
// centimeter
namespace t { typedef make_scaled_unit< si::length, scale< 10, static_rational<-2> > >::type cm; }
namespace i { BOOST_UNITS_STATIC_CONSTANT( cm, t::cm ); }
// meter squared
namespace t { typedef multiply_typeof_helper< m, m>::type m_m; }
namespace i { BOOST_UNITS_STATIC_CONSTANT( m_m, t::m_m ); }
// centimeter squared
namespace t { typedef multiply_typeof_helper< cm, cm>::type cm_cm; }
namespace i { BOOST_UNITS_STATIC_CONSTANT( cm_cm, t::cm_cm ); }
// meter centimeter
namespace t { typedef multiply_typeof_helper< m, cm>::type m_cm; }
namespace i { BOOST_UNITS_STATIC_CONSTANT( m_cm, t::m_cm ); }
// override default output, which prints "c(m^2)"
namespace boost { namespace units {
inline std::string name_string(const t::m_cm&)
{ return "meter centimeter"; }
inline std::string symbol_string(const t::m_cm&)
{ return "m cm"; }
} }
// trying to overload output for centimeter squared
namespace boost { namespace units {
inline std::string name_string(const t::cm_cm&)
{ return "centimeter squared"; }
inline std::string symbol_string(const t::cm_cm&)
{ return "cm^2"; }
} }
int main(int argc, char *argv[])
{
std::cout << i::m << std::endl;
std::cout << i::cm << std::endl;
std::cout << i::m_m << std::endl;
std::cout << i::m_cm << std::endl;
//std::cout << i::cm_cm << std::endl; // this won't compile
quantity<t::m_m> a1(100*i::cm_cm);
std::cout << a1<< std::endl; // should be 0.01 m^2
quantity<t::m_m> a2(100*i::m_cm);
std::cout << a2<< std::endl; // should be 1 m^2
return 0;
}