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 fail_heterogeneous_unit.cpp |
15 | |
16 | \details |
17 | make sure that trying to bind a heterogeneous system to a different dimension fails. |
18 | |
19 | Output: |
20 | @verbatim |
21 | @endverbatim |
22 | **/ |
23 | |
24 | #include <boost/units/pow.hpp> |
25 | #include <boost/units/quantity.hpp> |
26 | #include <boost/units/systems/si.hpp> |
27 | #include <boost/units/systems/cgs.hpp> |
28 | //#include <boost/units/systems/conversions/convert_cgs_to_si.hpp> |
29 | //#include <boost/units/systems/conversions/convert_si_to_cgs.hpp> |
30 | |
31 | namespace bu = boost::units; |
32 | |
33 | template<class System> |
34 | bu::quantity<bu::unit<bu::energy_dimension, System> > f(bu::quantity<bu::unit<bu::length_dimension, System> > l) { |
35 | return(static_cast<bu::quantity<bu::unit<bu::energy_dimension, System> > >(f(l: static_cast<bu::quantity<bu::si::length> >(l)))); |
36 | } |
37 | bu::quantity<bu::si::energy> f(bu::quantity<bu::si::length> l) { |
38 | return(l * l * 2.0 * bu::si::kilograms / bu::pow<2>(x: bu::si::seconds)); |
39 | } |
40 | |
41 | int main() { |
42 | |
43 | f(l: 1.0 * bu::pow<2>(x: bu::si::meters) / bu::cgs::centimeters); |
44 | |
45 | return(0); |
46 | } |
47 |