1 // 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 17 Test heterogeneous units and quantities. 18 19 Output: 20 @verbatim 21 22 //[heterogeneous_unit_output_1 23 1.5 m 24 1 g 25 1.5 m g 26 1.5 m g^-1 27 28 1 N 29 1 kg s^-2 30 31 1 cm kg s^-2 32 1 cm m^-1 kg s^-2 33 //] 34 35 //[heterogeneous_unit_output_2 36 1.5 cm m 37 0.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 55 using namespace boost::units; 56 main()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 } 88