• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 dimension.cpp
15 
16 \details
17 Test dimension list manipulation.
18 
19 Output:
20 @verbatim
21 
22 //[dimension_output
23 length_dimension  = list<dim<length_base_dimension, static_rational<1l, 1l> >, dimensionless_type>
24 mass_dimension    = list<dim<mass_base_dimension, static_rational<1l, 1l> >, dimensionless_type>
25 time_dimension    = list<dim<time_base_dimension, static_rational<1l, 1l> >, dimensionless_type>
26 energy_dimension  = list<dim<length_base_dimension, static_rational<2l, 1l> >, list<dim<mass_base_dimension, static_rational<1l, 1l> >, list<dim<time_base_dimension, static_rational<-2l, 1l> >, dimensionless_type> > >
27 LM_type      = list<dim<length_base_dimension, static_rational<1l, 1l> >, list<dim<mass_base_dimension, static_rational<1l, 1l> >, dimensionless_type> >
28 L_T_type     = list<dim<length_base_dimension, static_rational<1l, 1l> >, list<dim<time_base_dimension, static_rational<-1l, 1l> >, dimensionless_type> >
29 V_type       = list<dim<length_base_dimension, static_rational<1l, 1l> >, list<dim<time_base_dimension, static_rational<-1l, 1l> >, dimensionless_type> >
30 //]
31 
32 @endverbatim
33 **/
34 
35 #include <boost/type_traits/is_same.hpp>
36 #include <boost/mpl/assert.hpp>
37 
38 #include <iostream>
39 
40 #include <boost/units/detail/utility.hpp>
41 
42 #include "test_system.hpp"
43 
44 namespace mpl = boost::mpl;
45 
main(void)46 int main(void)
47 {
48     using namespace boost::units;
49 
50     BOOST_MPL_ASSERT((boost::is_same<
51         length_dimension,
52         mpl::push_front<
53             dimensionless_type,
54             dim<length_base_dimension, static_rational<1L, 1L> >
55         >::type
56     >));
57     BOOST_MPL_ASSERT((boost::is_same<
58         mass_dimension,
59         mpl::push_front<
60             dimensionless_type,
61             dim<mass_base_dimension, static_rational<1L, 1L> >
62         >::type
63     >));
64     BOOST_MPL_ASSERT((boost::is_same<energy_dimension,
65         mpl::push_front<
66         mpl::push_front<
67         mpl::push_front<
68         dimensionless_type,
69         dim<time_base_dimension, static_rational<-2L, 1L> > >::type,
70         dim<mass_base_dimension, static_rational<1L, 1L> > >::type,
71         dim<length_base_dimension, static_rational<2L, 1L> > >::type>));
72 
73     std::cout << "length_dimension  = "
74               << simplify_typename(length_dimension()) << std::endl
75               << "mass_dimension    = "
76               << simplify_typename(mass_dimension()) << std::endl
77               << "time_dimension    = "
78               << simplify_typename(time_dimension()) << std::endl
79               << "energy_dimension  = "
80               << simplify_typename(energy_dimension()) << std::endl;
81 
82     //[dimension_snippet_1
83     typedef mpl::times<length_dimension,mass_dimension>::type   LM_type;
84     typedef mpl::divides<length_dimension,time_dimension>::type L_T_type;
85     typedef static_root<
86         mpl::divides<energy_dimension,mass_dimension>::type,
87         static_rational<2>
88     >::type    V_type;
89     //]
90 
91     BOOST_MPL_ASSERT((boost::is_same<LM_type,
92         mpl::push_front<
93         mpl::push_front<
94         dimensionless_type,
95         dim<mass_base_dimension, static_rational<1L, 1L> > >::type,
96         dim<length_base_dimension, static_rational<1L, 1L> > >::type>));
97 
98     BOOST_MPL_ASSERT((boost::is_same<L_T_type,
99         mpl::push_front<
100         mpl::push_front<
101         dimensionless_type,
102         dim<time_base_dimension, static_rational<-1L, 1L> > >::type,
103         dim<length_base_dimension, static_rational<1L, 1L> > >::type>));
104 
105     BOOST_MPL_ASSERT((boost::is_same<V_type,
106         mpl::push_front<
107         mpl::push_front<
108         dimensionless_type,
109         dim<time_base_dimension, static_rational<-1L, 1L> > >::type,
110         dim<length_base_dimension, static_rational<1L, 1L> > >::type>));
111 
112     std::cout << "LM_type      = " << simplify_typename(LM_type()) << std::endl
113               << "L_T_type     = " << simplify_typename(L_T_type()) << std::endl
114               << "V_type       = " << simplify_typename(V_type()) << std::endl;
115 
116     return 0;
117 }
118