diff options
Diffstat (limited to 'boost/units/systems/detail/constants.hpp')
-rw-r--r-- | boost/units/systems/detail/constants.hpp | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/boost/units/systems/detail/constants.hpp b/boost/units/systems/detail/constants.hpp index cf156f7072..692efa4eb6 100644 --- a/boost/units/systems/detail/constants.hpp +++ b/boost/units/systems/detail/constants.hpp @@ -31,22 +31,22 @@ template<class Base> struct constant { typedef typename Base::value_type value_type; - operator value_type() const { return Base().value(); } - value_type value() const { return Base().value(); } - value_type uncertainty() const { return Base().uncertainty(); } - value_type lower_bound() const { return Base().lower_bound(); } - value_type upper_bound() const { return Base().upper_bound(); } + BOOST_CONSTEXPR operator value_type() const { return Base().value(); } + BOOST_CONSTEXPR value_type value() const { return Base().value(); } + BOOST_CONSTEXPR value_type uncertainty() const { return Base().uncertainty(); } + BOOST_CONSTEXPR value_type lower_bound() const { return Base().lower_bound(); } + BOOST_CONSTEXPR value_type upper_bound() const { return Base().upper_bound(); } }; template<class Base> struct physical_constant { typedef typename Base::value_type value_type; - operator value_type() const { return Base().value(); } - value_type value() const { return Base().value(); } - value_type uncertainty() const { return Base().uncertainty(); } - value_type lower_bound() const { return Base().lower_bound(); } - value_type upper_bound() const { return Base().upper_bound(); } + BOOST_CONSTEXPR operator value_type() const { return Base().value(); } + BOOST_CONSTEXPR value_type value() const { return Base().value(); } + BOOST_CONSTEXPR value_type uncertainty() const { return Base().uncertainty(); } + BOOST_CONSTEXPR value_type lower_bound() const { return Base().lower_bound(); } + BOOST_CONSTEXPR value_type upper_bound() const { return Base().upper_bound(); } }; #define BOOST_UNITS_DEFINE_HELPER(name, symbol, template_name) \ @@ -64,6 +64,7 @@ struct name ## _typeof_helper<template_name<Arg1, Arg2>, constant<T> >\ }; \ \ template<class T, class Arg1, class Arg2> \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper<typename T::value_type, template_name<Arg1, Arg2> >::type \ operator symbol(const constant<T>& t, const template_name<Arg1, Arg2>& u)\ { \ @@ -71,6 +72,7 @@ operator symbol(const constant<T>& t, const template_name<Arg1, Arg2>& u)\ } \ \ template<class T, class Arg1, class Arg2> \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper<template_name<Arg1, Arg2>, typename T::value_type>::type \ operator symbol(const template_name<Arg1, Arg2>& u, const constant<T>& t)\ { \ @@ -97,6 +99,7 @@ struct name ## _typeof_helper<constant<T1>, constant<T2> > \ }; \ \ template<class T1, class T2> \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper<typename T1::value_type, typename T2::value_type>::type \ operator symbol(const constant<T1>& t, const constant<T2>& u) \ { \ @@ -116,6 +119,7 @@ struct name ## _typeof_helper<T1, constant<T2> > \ }; \ \ template<class T1, class T2> \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper<typename T1::value_type, T2>::type \ operator symbol(const constant<T1>& t, const T2& u) \ { \ @@ -123,6 +127,7 @@ operator symbol(const constant<T1>& t, const T2& u) \ } \ \ template<class T1, class T2> \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper<T1, typename T2::value_type>::type \ operator symbol(const T1& t, const constant<T2>& u) \ { \ @@ -151,6 +156,7 @@ struct name ## _typeof_helper<one, constant<T2> > \ }; \ \ template<class T1> \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper<typename T1::value_type, one>::type \ operator symbol(const constant<T1>& t, const one& u) \ { \ @@ -158,6 +164,7 @@ operator symbol(const constant<T1>& t, const one& u) \ } \ \ template<class T2> \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper<one, typename T2::value_type>::type \ operator symbol(const one& t, const constant<T2>& u) \ { \ @@ -174,7 +181,7 @@ struct power_typeof_helper<constant<T1>, static_rational<N,D> > { typedef power_typeof_helper<typename T1::value_type, static_rational<N,D> > base; typedef typename base::type type; - static type value(const constant<T1>& arg) + static BOOST_CONSTEXPR type value(const constant<T1>& arg) { return base::value(arg.value()); } @@ -189,6 +196,7 @@ struct name ## _typeof_helper<constant<T1> > \ }; \ \ template<class T1> \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper<typename T1::value_type, one>::type \ operator symbol(const constant<T1>& t, const one& u) \ { \ @@ -196,21 +204,22 @@ operator symbol(const constant<T1>& t, const one& u) \ } \ \ template<class T2> \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper<one, typename T2::value_type>::type \ operator symbol(const one& t, const constant<T2>& u) \ { \ return(t symbol u.value()); \ } -#define BOOST_UNITS_PHYSICAL_CONSTANT(name, type, value_, uncertainty_) \ -struct name ## _t { \ - typedef type value_type; \ - operator value_type() const { return value_; } \ - value_type value() const { return value_; } \ - value_type uncertainty() const { return uncertainty_; } \ - value_type lower_bound() const { return value_-uncertainty_; } \ - value_type upper_bound() const { return value_+uncertainty_; } \ -}; \ +#define BOOST_UNITS_PHYSICAL_CONSTANT(name, type, value_, uncertainty_) \ +struct name ## _t { \ + typedef type value_type; \ + BOOST_CONSTEXPR operator value_type() const { return value_; } \ + BOOST_CONSTEXPR value_type value() const { return value_; } \ + BOOST_CONSTEXPR value_type uncertainty() const { return uncertainty_; } \ + BOOST_CONSTEXPR value_type lower_bound() const { return value_-uncertainty_; } \ + BOOST_CONSTEXPR value_type upper_bound() const { return value_+uncertainty_; } \ +}; \ BOOST_UNITS_STATIC_CONSTANT(name, boost::units::constant<boost::units::physical_constant<name ## _t> >) = { } // stream output |