blob: 022ea4e602b24e2d858263d28d36addf01c23bae [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 composite_output.cpp
15
16\details An example of textual representations of units.
17
18Output:
19@verbatim
20
21//[conversion_output_output
222 dyn
232 dyn
242 dyne
25cm g s^-1
26centimeter gram second^-1
27dyn
28dyne
29n
30nano
31n
32nano
33F
34farad
351 F
361 farad
37nF
38nanofarad
391 nF
401 nanofarad
41n(cm g s^-1)
42nano(centimeter gram second^-1)
43//]
44
45@endverbatim
46**/
47#include <boost/units/quantity.hpp>
48#include <boost/units/systems/cgs.hpp>
49#include <boost/units/io.hpp>
50#include <boost/units/scale.hpp>
51
52#include <boost/units/detail/utility.hpp>
53
54#include <boost/units/systems/si/capacitance.hpp>
55#include <boost/units/systems/si/io.hpp>
56#include <boost/units/systems/si/prefixes.hpp>
57
58#include <iostream>
59#include <sstream>
60
61namespace boost {
62
63namespace units {
64
65//[composite_output_snippet_1
66
67std::string name_string(const cgs::force&)
68{
69 return "dyne";
70}
71
72std::string symbol_string(const cgs::force&)
73{
74 return "dyn";
75}
76
77//]
78
79}
80
81}
82
83int main()
84{
85 using namespace boost::units;
86 using boost::units::cgs::centimeter;
87 using boost::units::cgs::gram;
88 using boost::units::cgs::second;
89 using boost::units::cgs::dyne;
90
91 //[composite_output_snippet_2]
92 std::cout << 2.0 * dyne << std::endl
93 << symbol_format << 2.0 * dyne << std::endl
94 << name_format << 2.0 * dyne << std::endl
95 << symbol_format << gram*centimeter/second << std::endl
96 << name_format << gram*centimeter/second << std::endl
97 << symbol_format << gram*centimeter/(second*second) << std::endl
98 << name_format << gram*centimeter/(second*second) << std::endl
99 << symbol_string(scale<10,static_rational<-9> >()) << std::endl
100 << name_string(scale<10,static_rational<-9> >()) << std::endl
101 << symbol_format << si::nano << std::endl
102 << name_format << si::nano << std::endl
103 << symbol_format << si::farad << std::endl
104 << name_format << si::farad << std::endl
105 << symbol_format << 1.0*si::farad << std::endl
106 << name_format << 1.0*si::farad << std::endl
107 << symbol_format << si::farad*si::nano << std::endl
108 << name_format << si::farad*si::nano << std::endl
109 << symbol_format << 1.0*si::farad*si::nano << std::endl
110 << name_format << 1.0*si::farad*si::nano << std::endl
111 << symbol_format << si::nano*gram*centimeter/second << std::endl
112 << name_format << si::nano*gram*centimeter/second << std::endl;
113 //]
114
115 return 0;
116}