fix doc example typo
[boost.git] / boost / units / static_constant.hpp
blob9026b3fde2175c93f4640c473cff531404680750
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) 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_STATIC_CONSTANT_HPP
12 #define BOOST_UNITS_STATIC_CONSTANT_HPP
14 #include <boost/units/config.hpp>
16 /// A convenience macro that allows definition of static
17 /// constants in headers in an ODR-safe way.
18 #define BOOST_UNITS_STATIC_CONSTANT(name, type) \
19 template<bool b> \
20 struct name##_instance_t \
21 { \
22 static const type instance; \
23 }; \
25 namespace \
26 { \
27 static const type& name = name##_instance_t<true>::instance; \
28 } \
30 template<bool b> \
31 const type name##_instance_t<b>::instance
33 /// A convenience macro for static constants with auto
34 /// type deduction.
35 #if BOOST_UNITS_HAS_TYPEOF
37 #if BOOST_UNITS_HAS_BOOST_TYPEOF
39 #define BOOST_UNITS_AUTO_STATIC_CONSTANT(name, value) \
40 BOOST_TYPEOF_NESTED_TYPEDEF(name##_nested_t, value) \
41 BOOST_UNITS_STATIC_CONSTANT(name, name##_nested_t::type) = (value)
43 #elif BOOST_UNITS_HAS_MWERKS_TYPEOF
45 #define BOOST_UNITS_AUTO_STATIC_CONSTANT(name, value) \
46 BOOST_UNITS_STATIC_CONSTANT(name, __typeof__(value)) = (value)
48 #elif BOOST_UNITS_HAS_GNU_TYPEOF
50 #define BOOST_UNITS_AUTO_STATIC_CONSTANT(name, value) \
51 BOOST_UNITS_STATIC_CONSTANT(name, typeof(value)) = (value)
53 #endif // BOOST_UNITS_HAS_BOOST_TYPEOF
55 #endif // BOOST_UNITS_HAS_TYPEOF
57 #endif // BOOST_UNITS_STATIC_CONSTANT_HPP