Chris@16: // Boost.Units - A C++ library for zero-overhead dimensional analysis and Chris@16: // unit/quantity manipulation and conversion Chris@16: // Chris@16: // Copyright (C) 2003-2008 Matthias Christian Schabel Chris@16: // Copyright (C) 2008 Steven Watanabe Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_UNITS_STATIC_CONSTANT_HPP Chris@16: #define BOOST_UNITS_STATIC_CONSTANT_HPP Chris@16: Chris@16: #include Chris@16: Chris@16: /// A convenience macro that allows definition of static Chris@16: /// constants in headers in an ODR-safe way. Chris@16: #define BOOST_UNITS_STATIC_CONSTANT(name, type) \ Chris@16: template \ Chris@16: struct name##_instance_t \ Chris@16: { \ Chris@16: static const type instance; \ Chris@16: }; \ Chris@16: \ Chris@16: namespace \ Chris@16: { \ Chris@16: static const type& name = name##_instance_t::instance; \ Chris@16: } \ Chris@16: \ Chris@16: template \ Chris@16: const type name##_instance_t::instance Chris@16: Chris@16: /// A convenience macro for static constants with auto Chris@16: /// type deduction. Chris@16: #if BOOST_UNITS_HAS_TYPEOF Chris@16: Chris@16: #if BOOST_UNITS_HAS_BOOST_TYPEOF Chris@16: Chris@16: #define BOOST_UNITS_AUTO_STATIC_CONSTANT(name, value) \ Chris@16: BOOST_TYPEOF_NESTED_TYPEDEF(name##_nested_t, value) \ Chris@16: BOOST_UNITS_STATIC_CONSTANT(name, name##_nested_t::type) = (value) Chris@16: Chris@16: #elif BOOST_UNITS_HAS_MWERKS_TYPEOF Chris@16: Chris@16: #define BOOST_UNITS_AUTO_STATIC_CONSTANT(name, value) \ Chris@16: BOOST_UNITS_STATIC_CONSTANT(name, __typeof__(value)) = (value) Chris@16: Chris@16: #elif BOOST_UNITS_HAS_GNU_TYPEOF Chris@16: Chris@16: #define BOOST_UNITS_AUTO_STATIC_CONSTANT(name, value) \ Chris@16: BOOST_UNITS_STATIC_CONSTANT(name, typeof(value)) = (value) Chris@16: Chris@16: #endif // BOOST_UNITS_HAS_BOOST_TYPEOF Chris@16: Chris@16: #endif // BOOST_UNITS_HAS_TYPEOF Chris@16: Chris@16: #endif // BOOST_UNITS_STATIC_CONSTANT_HPP