blob: 7a4f1123471a27d9fbcfa0047dad83d73167d52c [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 heterogeneous_unit.cpp
15
16\details
17Test heterogeneous units and quantities.
18
19Output:
20@verbatim
21
22//[heterogeneous_unit_output_1
231.5 m
241 g
251.5 m g
261.5 m g^-1
27
281 N
291 kg s^-2
30
311 cm kg s^-2
321 cm m^-1 kg s^-2
33//]
34
35//[heterogeneous_unit_output_2
361.5 cm m
370.015 m^2
38//]
39
40@endverbatim
41**/
42
43#define MCS_USE_DEMANGLING
44//#define MCS_USE_BOOST_REGEX_DEMANGLING
45
46#include <iostream>
47
48#include <boost/units/io.hpp>
49#include <boost/units/pow.hpp>
50#include <boost/units/detail/utility.hpp>
51#include <boost/units/systems/cgs.hpp>
52#include <boost/units/systems/si.hpp>
53#include <boost/units/systems/si/io.hpp>
54
55using namespace boost::units;
56
57int main()
58{
59 //[heterogeneous_unit_snippet_1
60 quantity<si::length> L(1.5*si::meter);
61 quantity<cgs::mass> M(1.0*cgs::gram);
62
63 std::cout << L << std::endl
64 << M << std::endl
65 << L*M << std::endl
66 << L/M << std::endl
67 << std::endl;
68
69 std::cout << 1.0*si::meter*si::kilogram/pow<2>(si::second) << std::endl
70 << 1.0*si::meter*si::kilogram/pow<2>(si::second)/si::meter
71 << std::endl << std::endl;
72
73 std::cout << 1.0*cgs::centimeter*si::kilogram/pow<2>(si::second) << std::endl
74 << 1.0*cgs::centimeter*si::kilogram/pow<2>(si::second)/si::meter
75 << std::endl << std::endl;
76 //]
77
78 //[heterogeneous_unit_snippet_2
79 quantity<si::area> A(1.5*si::meter*cgs::centimeter);
80
81 std::cout << 1.5*si::meter*cgs::centimeter << std::endl
82 << A << std::endl
83 << std::endl;
84 //]
85
86 return 0;
87}