Blame view

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