1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
2 // unit/quantity manipulation and conversion
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
5 // Copyright (C) 2007-2008 Steven Watanabe
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>
25 /// \brief Handling of fundamental dimension/exponent pairs.
37 /// \brief Dimension tag/exponent pair for a single fundamental dimension.
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
47 /// - @c mpl::plus for two @c dims
48 /// - @c mpl::minus for two @c dims
49 /// - @c mpl::negate for a @c dim
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
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
59 /// These metafunctions likewise operate on the exponent only.
60 template<typename T
,typename V
>
64 typedef detail::dim_tag tag
;
73 #if BOOST_UNITS_HAS_BOOST_TYPEOF
75 #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
77 BOOST_TYPEOF_REGISTER_TEMPLATE(boost::units::dim
, 2)
81 #ifndef BOOST_UNITS_DOXYGEN
87 // define MPL operators acting on dim<T,V>
90 struct plus_impl
<boost::units::detail::dim_tag
,boost::units::detail::dim_tag
>
92 template<class T0
, class T1
>
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
;
101 struct minus_impl
<boost::units::detail::dim_tag
,boost::units::detail::dim_tag
>
103 template<class T0
, class T1
>
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
;
112 struct times_impl
<boost::units::detail::dim_tag
,boost::units::detail::static_rational_tag
>
114 template<class T0
, class T1
>
117 typedef boost::units::dim
<typename
T0::tag_type
, typename
mpl::times
<typename
T0::value_type
, T1
>::type
> type
;
122 struct times_impl
<boost::units::detail::static_rational_tag
,boost::units::detail::dim_tag
>
124 template<class T0
, class T1
>
127 typedef boost::units::dim
<typename
T1::tag_type
, typename
mpl::times
<T0
, typename
T1::value_type
>::type
> type
;
132 struct divides_impl
<boost::units::detail::dim_tag
,boost::units::detail::static_rational_tag
>
134 template<class T0
, class T1
>
137 typedef boost::units::dim
<typename
T0::tag_type
, typename
mpl::divides
<typename
T0::value_type
, T1
>::type
> type
;
142 struct divides_impl
<boost::units::detail::static_rational_tag
,boost::units::detail::dim_tag
>
144 template<class T0
, class T1
>
147 typedef boost::units::dim
<typename
T1::tag_type
, typename
mpl::divides
<T0
, typename
T1::value_type
>::type
> type
;
152 struct negate_impl
<boost::units::detail::dim_tag
>
157 typedef boost::units::dim
<typename
T0::tag_type
,typename
mpl::negate
<typename
T0::value_type
>::type
> type
;
167 #endif // BOOST_UNITS_DIM_HPP