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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
// 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 composite_output.cpp
\details An example of textual representations of units.
Output:
@verbatim
//[conversion_output_output
2 dyn
2 dyn
2 dyne
cm g s^-1
centimeter gram second^-1
dyn
dyne
n
nano
n
nano
F
farad
1 F
1 farad
nF
nanofarad
1 nF
1 nanofarad
n(cm g s^-1)
nano(centimeter gram second^-1)
//]
@endverbatim
**/
#include <boost/units/quantity.hpp>
#include <boost/units/systems/cgs.hpp>
#include <boost/units/io.hpp>
#include <boost/units/scale.hpp>
#include <boost/units/detail/utility.hpp>
#include <boost/units/systems/si/capacitance.hpp>
#include <boost/units/systems/si/io.hpp>
#include <boost/units/systems/si/prefixes.hpp>
#include <iostream>
#include <sstream>
namespace boost {
namespace units {
//[composite_output_snippet_1
std::string name_string(const cgs::force&)
{
return "dyne";
}
std::string symbol_string(const cgs::force&)
{
return "dyn";
}
//]
}
}
int main()
{
using namespace boost::units;
using boost::units::cgs::centimeter;
using boost::units::cgs::gram;
using boost::units::cgs::second;
using boost::units::cgs::dyne;
//[composite_output_snippet_2]
std::cout << 2.0 * dyne << std::endl
<< symbol_format << 2.0 * dyne << std::endl
<< name_format << 2.0 * dyne << std::endl
<< symbol_format << gram*centimeter/second << std::endl
<< name_format << gram*centimeter/second << std::endl
<< symbol_format << gram*centimeter/(second*second) << std::endl
<< name_format << gram*centimeter/(second*second) << std::endl
<< symbol_string(scale<10,static_rational<-9> >()) << std::endl
<< name_string(scale<10,static_rational<-9> >()) << std::endl
<< symbol_format << si::nano << std::endl
<< name_format << si::nano << std::endl
<< symbol_format << si::farad << std::endl
<< name_format << si::farad << std::endl
<< symbol_format << 1.0*si::farad << std::endl
<< name_format << 1.0*si::farad << std::endl
<< symbol_format << si::farad*si::nano << std::endl
<< name_format << si::farad*si::nano << std::endl
<< symbol_format << 1.0*si::farad*si::nano << std::endl
<< name_format << 1.0*si::farad*si::nano << std::endl
<< symbol_format << si::nano*gram*centimeter/second << std::endl
<< name_format << si::nano*gram*centimeter/second << std::endl;
//]
return 0;
}
|