fix doc example typo
[boost.git] / boost / units / dim.hpp
blob53372cfda60416eaab50a4c197cf1e6976e22f76
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_DIM_HPP
12 #define BOOST_UNITS_DIM_HPP
14 #include <boost/static_assert.hpp>
16 #include <boost/type_traits/is_same.hpp>
18 #include <boost/mpl/arithmetic.hpp>
20 #include <boost/units/config.hpp>
21 #include <boost/units/static_rational.hpp>
22 #include <boost/units/detail/dim_impl.hpp>
24 /// \file
25 /// \brief Handling of fundamental dimension/exponent pairs.
27 namespace boost {
29 namespace units {
31 namespace detail {
33 struct dim_tag { };
37 /// \brief Dimension tag/exponent pair for a single fundamental dimension.
38 ///
39 /// \detailed
40 /// The dim class represents a single dimension tag/dimension exponent pair.
41 /// That is, @c dim<tag_type,value_type> is a pair where @c tag_type represents the
42 /// fundamental dimension being represented and @c value_type represents the
43 /// exponent of that fundamental dimension as a @c static_rational. @c tag_type must
44 /// be a derived from a specialization of @c base_dimension.
45 /// Specialization of the following Boost.MPL metafunctions are provided
46 ///
47 /// - @c mpl::plus for two @c dims
48 /// - @c mpl::minus for two @c dims
49 /// - @c mpl::negate for a @c dim
50 ///
51 /// These metafunctions all operate on the exponent, and require
52 /// that the @c dim operands have the same base dimension tag.
53 /// In addition, multiplication and division by @c static_rational
54 /// is supported.
55 ///
56 /// - @c mpl::times for a @c static_rational and a @c dim in either order
57 /// - @c mpl::divides for a @c static_rational and a @c dim in either order
58 ///
59 /// These metafunctions likewise operate on the exponent only.
60 template<typename T,typename V>
61 struct dim
63 typedef dim type;
64 typedef detail::dim_tag tag;
65 typedef T tag_type;
66 typedef V value_type;
69 } // namespace units
71 } // namespace boost
73 #if BOOST_UNITS_HAS_BOOST_TYPEOF
75 #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
77 BOOST_TYPEOF_REGISTER_TEMPLATE(boost::units::dim, 2)
79 #endif
81 #ifndef BOOST_UNITS_DOXYGEN
83 namespace boost {
85 namespace mpl {
87 // define MPL operators acting on dim<T,V>
89 template<>
90 struct plus_impl<boost::units::detail::dim_tag,boost::units::detail::dim_tag>
92 template<class T0, class T1>
93 struct apply
95 BOOST_STATIC_ASSERT((boost::is_same<typename T0::tag_type,typename T1::tag_type>::value == true));
96 typedef boost::units::dim<typename T0::tag_type, typename mpl::plus<typename T0::value_type, typename T1::value_type>::type> type;
100 template<>
101 struct minus_impl<boost::units::detail::dim_tag,boost::units::detail::dim_tag>
103 template<class T0, class T1>
104 struct apply
106 BOOST_STATIC_ASSERT((boost::is_same<typename T0::tag_type,typename T1::tag_type>::value == true));
107 typedef boost::units::dim<typename T0::tag_type, typename mpl::minus<typename T0::value_type, typename T1::value_type>::type> type;
111 template<>
112 struct times_impl<boost::units::detail::dim_tag,boost::units::detail::static_rational_tag>
114 template<class T0, class T1>
115 struct apply
117 typedef boost::units::dim<typename T0::tag_type, typename mpl::times<typename T0::value_type, T1>::type> type;
121 template<>
122 struct times_impl<boost::units::detail::static_rational_tag,boost::units::detail::dim_tag>
124 template<class T0, class T1>
125 struct apply
127 typedef boost::units::dim<typename T1::tag_type, typename mpl::times<T0, typename T1::value_type>::type> type;
131 template<>
132 struct divides_impl<boost::units::detail::dim_tag,boost::units::detail::static_rational_tag>
134 template<class T0, class T1>
135 struct apply
137 typedef boost::units::dim<typename T0::tag_type, typename mpl::divides<typename T0::value_type, T1>::type> type;
141 template<>
142 struct divides_impl<boost::units::detail::static_rational_tag,boost::units::detail::dim_tag>
144 template<class T0, class T1>
145 struct apply
147 typedef boost::units::dim<typename T1::tag_type, typename mpl::divides<T0, typename T1::value_type>::type> type;
151 template<>
152 struct negate_impl<boost::units::detail::dim_tag>
154 template<class T0>
155 struct apply
157 typedef boost::units::dim<typename T0::tag_type,typename mpl::negate<typename T0::value_type>::type> type;
161 } // namespace mpl
163 } // namespace boost
165 #endif
167 #endif // BOOST_UNITS_DIM_HPP