fix doc example typo
[boost.git] / boost / units / detail / unscale.hpp
blob08e51e96d5389e436dd589270efdf46e1fe60f92
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) 2007-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)
11 #ifndef BOOST_UNITS_DETAIL_UNSCALE_HPP_INCLUDED
12 #define BOOST_UNITS_DETAIL_UNSCALE_HPP_INCLUDED
14 #include <string>
16 #include <boost/mpl/bool.hpp>
17 #include <boost/mpl/size.hpp>
18 #include <boost/mpl/begin.hpp>
19 #include <boost/mpl/next.hpp>
20 #include <boost/mpl/deref.hpp>
21 #include <boost/mpl/plus.hpp>
22 #include <boost/mpl/times.hpp>
23 #include <boost/mpl/negate.hpp>
24 #include <boost/mpl/less.hpp>
26 #include <boost/units/config.hpp>
27 #include <boost/units/dimension.hpp>
28 #include <boost/units/scale.hpp>
29 #include <boost/units/static_rational.hpp>
30 #include <boost/units/units_fwd.hpp>
31 #include <boost/units/detail/one.hpp>
33 namespace boost {
35 namespace units {
37 template<class T>
38 struct heterogeneous_system;
40 template<class T, class D, class Scale>
41 struct heterogeneous_system_impl;
43 template<class T, class E>
44 struct heterogeneous_system_dim;
46 template<class S, class Scale>
47 struct scaled_base_unit;
49 /// removes all scaling from a unit or a base unit.
50 template<class T>
51 struct unscale
53 #ifndef BOOST_UNITS_DOXYGEN
54 typedef T type;
55 #else
56 typedef detail::unspecified type;
57 #endif
60 /// INTERNAL ONLY
61 template<class S, class Scale>
62 struct unscale<scaled_base_unit<S, Scale> >
64 typedef typename unscale<S>::type type;
67 /// INTERNAL ONLY
68 template<class D, class S>
69 struct unscale<unit<D, S> >
71 typedef unit<D, typename unscale<S>::type> type;
74 /// INTERNAL ONLY
75 template<class Scale>
76 struct scale_list_dim;
78 /// INTERNAL ONLY
79 template<class T>
80 struct get_scale_list
82 typedef dimensionless_type type;
85 /// INTERNAL ONLY
86 template<class S, class Scale>
87 struct get_scale_list<scaled_base_unit<S, Scale> >
89 typedef typename mpl::times<list<scale_list_dim<Scale>, dimensionless_type>, typename get_scale_list<S>::type>::type type;
92 /// INTERNAL ONLY
93 template<class D, class S>
94 struct get_scale_list<unit<D, S> >
96 typedef typename get_scale_list<S>::type type;
99 /// INTERNAL ONLY
100 struct scale_dim_tag {};
102 /// INTERNAL ONLY
103 template<class Scale>
104 struct scale_list_dim : Scale
106 typedef scale_dim_tag tag;
107 typedef scale_list_dim type;
110 } // namespace units
112 #ifndef BOOST_UNITS_DOXYGEN
114 namespace mpl {
116 /// INTERNAL ONLY
117 template<>
118 struct less_impl<boost::units::scale_dim_tag, boost::units::scale_dim_tag>
120 template<class T0, class T1>
121 struct apply : mpl::bool_<((T0::base) < (T1::base))> {};
126 #endif
128 namespace units {
130 namespace detail {
132 template<class Scale>
133 struct is_empty_dim<scale_list_dim<Scale> > : mpl::false_ {};
135 template<long N>
136 struct is_empty_dim<scale_list_dim<scale<N, static_rational<0, 1> > > > : mpl::true_ {};
138 template<int N>
139 struct eval_scale_list_impl
141 template<class Begin>
142 struct apply
144 typedef typename eval_scale_list_impl<N-1>::template apply<typename Begin::next> next_iteration;
145 typedef typename multiply_typeof_helper<typename next_iteration::type, typename Begin::item::value_type>::type type;
146 static type value()
148 return(next_iteration::value() * Begin::item::value());
153 template<>
154 struct eval_scale_list_impl<0>
156 template<class Begin>
157 struct apply
159 typedef one type;
160 static one value()
162 one result;
163 return(result);
170 /// INTERNAL ONLY
171 template<class T>
172 struct eval_scale_list : detail::eval_scale_list_impl<T::size::value>::template apply<T> {};
174 } // namespace units
176 #ifndef BOOST_UNITS_DOXYGEN
178 namespace mpl {
180 /// INTERNAL ONLY
181 template<>
182 struct plus_impl<boost::units::scale_dim_tag, boost::units::scale_dim_tag>
184 template<class T0, class T1>
185 struct apply
187 typedef boost::units::scale_list_dim<
188 boost::units::scale<
189 (T0::base),
190 typename mpl::plus<typename T0::exponent, typename T1::exponent>::type
192 > type;
196 /// INTERNAL ONLY
197 template<>
198 struct negate_impl<boost::units::scale_dim_tag>
200 template<class T0>
201 struct apply
203 typedef boost::units::scale_list_dim<
204 boost::units::scale<
205 (T0::base),
206 typename mpl::negate<typename T0::exponent>::type
208 > type;
212 /// INTERNAL ONLY
213 template<>
214 struct times_impl<boost::units::scale_dim_tag, boost::units::detail::static_rational_tag>
216 template<class T0, class T1>
217 struct apply
219 typedef boost::units::scale_list_dim<
220 boost::units::scale<
221 (T0::base),
222 typename mpl::times<typename T0::exponent, T1>::type
224 > type;
228 } // namespace mpl
230 #endif
232 } // namespace boost
234 #endif