temperature.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Boost.Units - A C++ library for zero-overhead dimensional analysis and
  2. // unit/quantity manipulation and conversion
  3. //
  4. // Copyright (C) 2003-2008 Matthias Christian Schabel
  5. // Copyright (C) 2008 Steven Watanabe
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See
  8. // accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. /**
  11. \file
  12. \brief temperature.cpp
  13. \details
  14. Conversions between Fahrenheit and Kelvin for absolute temperatures and
  15. temperature differences.
  16. Output:
  17. @verbatim
  18. //[ temperature_output_1
  19. { 32 } F
  20. { 273.15 } K
  21. { 273.15 } K
  22. [ 32 ] F
  23. [ 17.7778 ] K
  24. [ 17.7778 ] K
  25. //]
  26. @endverbatim
  27. **/
  28. #include <iomanip>
  29. #include <iostream>
  30. #include <boost/units/absolute.hpp>
  31. #include <boost/units/get_system.hpp>
  32. #include <boost/units/io.hpp>
  33. #include <boost/units/unit.hpp>
  34. #include <boost/units/quantity.hpp>
  35. #include <boost/units/systems/si/temperature.hpp>
  36. #include <boost/units/detail/utility.hpp>
  37. #include <boost/units/base_units/temperature/fahrenheit.hpp>
  38. using namespace boost::units;
  39. namespace boost {
  40. namespace units {
  41. namespace fahrenheit {
  42. //[temperature_snippet_1
  43. typedef temperature::fahrenheit_base_unit::unit_type temperature;
  44. typedef get_system<temperature>::type system;
  45. BOOST_UNITS_STATIC_CONSTANT(degree,temperature);
  46. BOOST_UNITS_STATIC_CONSTANT(degrees,temperature);
  47. //]
  48. } // fahrenheit
  49. } // namespace units
  50. } // namespace boost
  51. int main()
  52. {
  53. //[temperature_snippet_3
  54. quantity<absolute<fahrenheit::temperature> > T1p(
  55. 32.0*absolute<fahrenheit::temperature>());
  56. quantity<fahrenheit::temperature> T1v(
  57. 32.0*fahrenheit::degrees);
  58. quantity<absolute<si::temperature> > T2p(T1p);
  59. quantity<si::temperature> T2v(T1v);
  60. //]
  61. typedef conversion_helper<
  62. quantity<absolute<fahrenheit::temperature> >,
  63. quantity<absolute<si::temperature> > > absolute_conv_type;
  64. typedef conversion_helper<
  65. quantity<fahrenheit::temperature>,
  66. quantity<si::temperature> > relative_conv_type;
  67. std::cout << T1p << std::endl
  68. << absolute_conv_type::convert(T1p) << std::endl
  69. << T2p << std::endl
  70. << T1v << std::endl
  71. << relative_conv_type::convert(T1v) << std::endl
  72. << T2v << std::endl
  73. << std::endl;
  74. return 0;
  75. }