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)
12 /// \brief base dimensions (mass, length, time...).
13 /// \details base dimension definition registration.
15 #ifndef BOOST_UNITS_BASE_DIMENSION_HPP
16 #define BOOST_UNITS_BASE_DIMENSION_HPP
18 #include <boost/units/config.hpp>
19 #include <boost/units/dim.hpp>
20 #include <boost/units/static_rational.hpp>
21 #include <boost/units/units_fwd.hpp>
22 #include <boost/units/detail/dimension_list.hpp>
23 #include <boost/units/detail/ordinal.hpp>
24 #include <boost/units/detail/prevent_redefinition.hpp>
30 /// This must be in namespace boost::units so that ADL
31 /// will work with friend functions defined inline.
33 template<long N> struct base_dimension_ordinal { };
36 template<class T, long N> struct base_dimension_pair { };
39 template<class T, long N>
40 struct check_base_dimension {
43 sizeof(boost_units_is_registered(units::base_dimension_ordinal<N>())) == sizeof(detail::yes) &&
44 sizeof(boost_units_is_registered(units::base_dimension_pair<T, N>())) != sizeof(detail::yes)
48 /// Defines a base dimension. To define a dimension you need to provide
49 /// the derived class (CRTP) and a unique integer.
51 /// struct my_dimension : boost::units::base_dimension<my_dimension, 1> {};
53 /// It is designed so that you will get an error message if you try
54 /// to use the same value in multiple definitions.
55 template<class Derived,
57 #if !defined(BOOST_UNITS_DOXYGEN) && !defined(__BORLANDC__)
59 class = typename detail::ordinal_has_already_been_defined<
60 check_base_dimension<Derived, N>::value
64 class base_dimension :
69 typedef base_dimension this_type;
70 /// A convenience typedef. Equivalent to boost::units::derived_dimension<Derived,1>::type.
71 #ifndef BOOST_UNITS_DOXYGEN
72 typedef list<dim<Derived,static_rational<1> >, dimensionless_type> dimension_type;
74 typedef detail::unspecified dimension_type;
76 /// Provided for mpl compatability.
80 /// Check for C++0x. In C++0x, we have to have identical
81 /// arguments but a different return type to trigger an
82 /// error. Note that this is only needed for clang as
83 /// check_base_dimension will trigger an error earlier
84 /// for compilers with less strict name lookup.
87 check_double_register(const units::base_dimension_ordinal<N>&)
90 /// Register this ordinal
93 boost_units_is_registered(const units::base_dimension_ordinal<N>&)
94 { detail::yes result; return(result); }
96 /// But make sure we can identify the current instantiation!
99 boost_units_is_registered(const units::base_dimension_pair<Derived, N>&)
100 { detail::yes result; return(result); }
107 #endif // BOOST_UNITS_BASE_DIMENSION_HPP