On Wed, 30 Nov 2011 15:00:28 -0800 Matthias Schabel
This will have the added benefit of allowing conversions but disallowing operations that don't make sense... Some code:
#include <iostream>
#include
#include #include #include #include
using namespace boost::units;
int main() { quantitycelsius::temperature dTC(10.*celsius::temperature()); quantityfahrenheit::temperature dTF(10.*fahrenheit::temperature()); quantitysi::temperature dTK(10.*si::kelvin);
std::cout << dTC << std::endl; std::cout << dTF << std::endl; std::cout << dTK << std::endl;
quantity
celsius::temperature > TC(0*absolutecelsius::temperature()); quantity fahrenheit::temperature > TF(32.*absolutefahrenheit::temperature()); quantity si::temperature > TK(0.*absolutesi::temperature()); std::cout << TC << std::endl; std::cout << TF << std::endl; std::cout << TK << std::endl;
std::cout << quantity
celsius::temperature >(TF) << std::endl; std::cout << quantity celsius::temperature >(TK) << std::endl; std::cout << quantity
fahrenheit::temperature >(TC) << std::endl; std::cout << quantity fahrenheit::temperature >(TK) << std::endl; // std::cout << TC+quantity
celsius::temperature >(TF) << std::endl; // fails because you cannot add two absolute temperatures std::cout << TC+quantitycelsius::temperature(dTF) << std::endl; std::cout << TF+quantityfahrenheit::temperature(dTC) << std::endl; return 0; }
Not being a current user of boost units I was curious about above code and just thought I'd try it (it looked totally straightforward and I was thinking hmm maybe I should be using boost units at times) - However it didn't compile (msvc 2010 and boost 1.48) - It wasn't exactly hard to change it so it would compile - just played around a little and ended up adding :-
#include