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)
10 
11 #ifndef BOOST_UNITS_STATIC_CONSTANT_HPP
12 #define BOOST_UNITS_STATIC_CONSTANT_HPP
13 
14 #include <boost/units/config.hpp>
15 
16 #if defined(BOOST_NO_CXX11_CONSTEXPR) || defined(BOOST_UNITS_DOXYGEN)
17 /// A convenience macro that allows definition of static
18 /// constants in headers in an ODR-safe way.
19 # define BOOST_UNITS_STATIC_CONSTANT(name, type)            \
20 template<bool b>                                            \
21 struct name##_instance_t                                    \
22 {                                                           \
23     static const type instance;                             \
24 };                                                          \
25                                                             \
26 namespace                                                   \
27 {                                                           \
28     static const type& name = name##_instance_t<true>::instance;   \
29 }                                                           \
30                                                             \
31 template<bool b>                                            \
32 const type name##_instance_t<b>::instance
33 #else
34 # define BOOST_UNITS_STATIC_CONSTANT(name, type)            \
35 BOOST_STATIC_CONSTEXPR type name
36 #endif
37 
38 /// A convenience macro for static constants with auto
39 /// type deduction.
40 #if BOOST_UNITS_HAS_TYPEOF
41 
42 #if BOOST_UNITS_HAS_BOOST_TYPEOF
43 
44 #define BOOST_UNITS_AUTO_STATIC_CONSTANT(name, value)               \
45 BOOST_TYPEOF_NESTED_TYPEDEF(name##_nested_t, value)                 \
46 BOOST_UNITS_STATIC_CONSTANT(name, name##_nested_t::type) = (value)
47 
48 #elif BOOST_UNITS_HAS_MWERKS_TYPEOF
49 
50 #define BOOST_UNITS_AUTO_STATIC_CONSTANT(name, value)               \
51 BOOST_UNITS_STATIC_CONSTANT(name, __typeof__(value)) = (value)
52 
53 #elif BOOST_UNITS_HAS_GNU_TYPEOF
54 
55 #define BOOST_UNITS_AUTO_STATIC_CONSTANT(name, value)               \
56 BOOST_UNITS_STATIC_CONSTANT(name, typeof(value)) = (value)
57 
58 #endif // BOOST_UNITS_HAS_BOOST_TYPEOF
59 
60 #endif // BOOST_UNITS_HAS_TYPEOF
61 
62 #endif // BOOST_UNITS_STATIC_CONSTANT_HPP
63