Re: [Boost-users] [Units] Temperature conversion problem

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

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
#include However given your email had outputs pasted in so obviously code was running at some point I wondered : Was this just a cut & paste typo? Or do you need to be careful with headers in code using boost unit to make sure that it compiles x-platform or some such?
Probably a cut-and-paste typo - I just lobbed that code into an existing project, so these headers were already included somewhere. The only necessary care with headers that I am aware of is making sure that the order of inclusion of defined conversions and custom IO formatting is correct. Matthias
participants (2)
-
Alex Perry
-
Matthias Schabel