fix doc example typo
[boost.git] / boost / units / base_unit.hpp
blob975da576189d1b94b784c62bfdf4b7fb9ec8e2fa
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_BASE_UNIT_HPP
12 #define BOOST_UNITS_BASE_UNIT_HPP
14 #include <boost/units/config.hpp>
15 #include <boost/units/heterogeneous_system.hpp>
16 #include <boost/units/static_rational.hpp>
17 #include <boost/units/units_fwd.hpp>
18 #include <boost/units/unit.hpp>
19 #include <boost/units/detail/dimension_list.hpp>
20 #include <boost/units/detail/ordinal.hpp>
21 #include <boost/units/detail/prevent_redefinition.hpp>
23 namespace boost {
25 namespace units {
27 /// This must be in namespace boost::units so that ADL
28 /// will work with friend functions defined inline.
29 /// Base dimensions and base units are independent.
30 /// INTERNAL ONLY
31 template<long N> struct base_unit_ordinal { };
33 /// INTERNAL ONLY
34 template<class T, long N> struct base_unit_pair { };
36 /// INTERNAL ONLY
37 template<class T, long N>
38 struct check_base_unit {
39 enum {
40 value =
41 sizeof(boost_units_unit_is_registered(units::base_unit_ordinal<N>())) == sizeof(detail::yes) &&
42 sizeof(boost_units_unit_is_registered(units::base_unit_pair<T, N>())) != sizeof(detail::yes)
46 /// Defines a base unit. To define a unit you need to provide
47 /// the derived class (CRTP), a dimension list and a unique integer.
48 /// @code
49 /// struct my_unit : boost::units::base_unit<my_unit, length_dimension, 1> {};
50 /// @endcode
51 /// It is designed so that you will get an error message if you try
52 /// to use the same value in multiple definitions.
53 template<class Derived,
54 class Dim,
55 long N
56 #if !defined(BOOST_UNITS_DOXYGEN) && !defined(__BORLANDC__)
58 class = typename detail::ordinal_has_already_been_defined<
59 check_base_unit<Derived, N>::value
60 >::type
61 #endif
63 class base_unit :
64 public ordinal<N>
66 public:
67 /// INTERNAL ONLY
68 typedef void boost_units_is_base_unit_type;
69 /// INTERNAL ONLY
70 typedef base_unit this_type;
71 /// The dimensions of this base unit.
72 typedef Dim dimension_type;
74 /// Provided for mpl compatability.
75 typedef Derived type;
77 /// The unit corresponding to this base unit.
78 #ifndef BOOST_UNITS_DOXYGEN
79 typedef unit<
80 Dim,
81 heterogeneous_system<
82 heterogeneous_system_impl<
83 list<
84 heterogeneous_system_dim<Derived,static_rational<1> >,
85 dimensionless_type
87 Dim,
88 no_scale
91 > unit_type;
92 #else
93 typedef detail::unspecified unit_type;
94 #endif
96 private:
97 /// Register this ordinal
98 /// INTERNAL ONLY
99 friend detail::yes
100 boost_units_unit_is_registered(const units::base_unit_ordinal<N>&)
101 { detail::yes result; return(result); }
103 /// But make sure we can identify the current instantiation!
104 /// INTERNAL ONLY
105 friend detail::yes
106 boost_units_unit_is_registered(const units::base_unit_pair<Derived, N>&)
107 { detail::yes result; return(result); }
110 } // namespace units
112 } // namespace boost
114 #endif // BOOST_UNITS_BASE_UNIT_HPP