blob: f6b434214d3d891570c6cbe9e6a716383c8dfa74 [file] [log] [blame]
Brian Silvermana8ce4c32018-08-04 23:57:09 -07001// 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/**
12\file
13
14\brief temperature.cpp
15
16\details
17Conversions between Fahrenheit and Kelvin for absolute temperatures and
18temperature differences.
19
20Output:
21@verbatim
22
23//[ temperature_output_1
24{ 32 } F
25{ 273.15 } K
26{ 273.15 } K
27[ 32 ] F
28[ 17.7778 ] K
29[ 17.7778 ] K
30//]
31
32@endverbatim
33**/
34
35#include <iomanip>
36#include <iostream>
37
38#include <boost/units/absolute.hpp>
39#include <boost/units/get_system.hpp>
40#include <boost/units/io.hpp>
41#include <boost/units/unit.hpp>
42#include <boost/units/quantity.hpp>
43#include <boost/units/systems/si/temperature.hpp>
44#include <boost/units/detail/utility.hpp>
45
46#include <boost/units/base_units/temperature/fahrenheit.hpp>
47
48using namespace boost::units;
49
50namespace boost {
51
52namespace units {
53
54namespace fahrenheit {
55
56//[temperature_snippet_1
57typedef temperature::fahrenheit_base_unit::unit_type temperature;
58typedef get_system<temperature>::type system;
59
60BOOST_UNITS_STATIC_CONSTANT(degree,temperature);
61BOOST_UNITS_STATIC_CONSTANT(degrees,temperature);
62//]
63
64} // fahrenheit
65
66} // namespace units
67
68} // namespace boost
69
70int main()
71{
72 //[temperature_snippet_3
73 quantity<absolute<fahrenheit::temperature> > T1p(
74 32.0*absolute<fahrenheit::temperature>());
75 quantity<fahrenheit::temperature> T1v(
76 32.0*fahrenheit::degrees);
77
78 quantity<absolute<si::temperature> > T2p(T1p);
79 quantity<si::temperature> T2v(T1v);
80 //]
81
82 typedef conversion_helper<
83 quantity<absolute<fahrenheit::temperature> >,
84 quantity<absolute<si::temperature> > > absolute_conv_type;
85 typedef conversion_helper<
86 quantity<fahrenheit::temperature>,
87 quantity<si::temperature> > relative_conv_type;
88
89 std::cout << T1p << std::endl
90 << absolute_conv_type::convert(T1p) << std::endl
91 << T2p << std::endl
92 << T1v << std::endl
93 << relative_conv_type::convert(T1v) << std::endl
94 << T2v << std::endl
95 << std::endl;
96
97 return 0;
98}