From 595390497c4faaf215ba5b10ed9df9187df9c468 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Sun, 14 Aug 2016 08:00:27 +0200 Subject: [PATCH 1/2] Add constexpr support Ensuring that: * it still works as before on C++98 and C++03 * C++11 "strict" constexpr is used where possible - requires replacing { R x; return f(x); } with { return f(R()); } * C++14 "relaxed" constexpr is used only where otherwise impossible - assignment operators - functions who's implementations require more than a single return statement --- example/autoprefixes.cpp | 6 +- example/complex.cpp | 40 +++--- example/conversion.cpp | 30 ++--- example/conversion_factor.cpp | 10 +- example/heterogeneous_unit.cpp | 6 +- example/information.cpp | 8 +- example/kitchen_sink.cpp | 54 ++++---- example/lambda.cpp | 12 +- example/measurement.hpp | 53 +++++--- example/non_base_dimension.cpp | 8 +- example/performance.cpp | 21 +-- example/quantity.cpp | 8 +- example/radar_beam_height.cpp | 27 ++-- example/systems.cpp | 148 ++++++++++----------- example/temperature.cpp | 8 +- example/tutorial.cpp | 13 +- example/unit.cpp | 8 +- include/boost/units/absolute.hpp | 30 ++--- include/boost/units/base_dimension.hpp | 10 +- include/boost/units/base_unit.hpp | 10 +- include/boost/units/cmath.hpp | 53 ++++++++ include/boost/units/config.hpp | 2 +- include/boost/units/conversion.hpp | 15 ++- include/boost/units/detail/absolute_impl.hpp | 8 +- include/boost/units/detail/conversion_impl.hpp | 50 +++---- include/boost/units/detail/linear_algebra.hpp | 10 +- include/boost/units/detail/one.hpp | 31 ++--- include/boost/units/detail/ordinal.hpp | 4 +- .../boost/units/detail/prevent_redefinition.hpp | 8 +- .../boost/units/detail/static_rational_power.hpp | 39 +++--- include/boost/units/detail/unscale.hpp | 7 +- include/boost/units/io.hpp | 14 +- include/boost/units/lambda.hpp | 12 +- include/boost/units/limits.hpp | 68 +++++----- include/boost/units/operators.hpp | 4 +- include/boost/units/pow.hpp | 10 +- include/boost/units/quantity.hpp | 128 +++++++++++------- include/boost/units/scale.hpp | 16 +-- include/boost/units/static_constant.hpp | 7 +- include/boost/units/static_rational.hpp | 22 +-- include/boost/units/systems/detail/constants.hpp | 49 ++++--- include/boost/units/unit.hpp | 18 ++- test/test_absolute.cpp | 12 +- test/test_cmath.cpp | 28 ++-- test/test_conversion.cpp | 30 ++--- test/test_default_conversion.cpp | 14 +- test/test_dimensionless_ice1.cpp | 2 +- test/test_dimensionless_ice2.cpp | 2 +- test/test_dimensionless_quantity.cpp | 32 ++--- test/test_implicit_conversion.cpp | 10 +- test/test_information_units.cpp | 58 ++++---- test/test_mixed_value_types.cpp | 2 +- test/test_quantity.cpp | 38 +++--- test/test_scaled_unit.cpp | 12 +- test/test_unit.cpp | 14 +- 55 files changed, 733 insertions(+), 606 deletions(-) diff --git a/example/autoprefixes.cpp b/example/autoprefixes.cpp index 441843ab..478fbbd1 100644 --- a/example/autoprefixes.cpp +++ b/example/autoprefixes.cpp @@ -105,8 +105,8 @@ int main() // Note that scalar dimensionless values are *not* prefixed automatically by the engineering_prefix or binary_prefix iostream manipulators. //[autoprefixes_snippet_3 - const double s1 = 2345.6; - const long x1 = 23456; + BOOST_CONSTEXPR_OR_CONST double s1 = 2345.6; + BOOST_CONSTEXPR_OR_CONST long x1 = 23456; cout << engineering_prefix << s1 << endl; // 2345.6 cout << engineering_prefix << x1 << endl; // 23456 @@ -115,7 +115,7 @@ int main() //] [/autoprefixes_snippet_3] //[autoprefixes_snippet_4 - const length L; // A unit of length (but not a quantity of length). + BOOST_CONSTEXPR_OR_CONST length L; // A unit of length (but not a quantity of length). cout << L << endl; // Default length unit is meter, // but default is symbol format so output is just "m". cout << name_format << L << endl; // default length name is "meter". diff --git a/example/complex.cpp b/example/complex.cpp index d03eb3df..c312346e 100644 --- a/example/complex.cpp +++ b/example/complex.cpp @@ -72,10 +72,10 @@ class complex public: typedef complex this_type; - complex(const T& r = 0,const T& i = 0) : r_(r),i_(i) { } - complex(const this_type& source) : r_(source.r_),i_(source.i_) { } + BOOST_CONSTEXPR complex(const T& r = 0,const T& i = 0) : r_(r),i_(i) { } + BOOST_CONSTEXPR complex(const this_type& source) : r_(source.r_),i_(source.i_) { } - this_type& operator=(const this_type& source) + BOOST_CXX14_CONSTEXPR this_type& operator=(const this_type& source) { if (this == &source) return *this; @@ -85,59 +85,59 @@ class complex return *this; } - T& real() { return r_; } - T& imag() { return i_; } + BOOST_CXX14_CONSTEXPR T& real() { return r_; } + BOOST_CXX14_CONSTEXPR T& imag() { return i_; } - const T& real() const { return r_; } - const T& imag() const { return i_; } + BOOST_CONSTEXPR const T& real() const { return r_; } + BOOST_CONSTEXPR const T& imag() const { return i_; } - this_type& operator+=(const T& val) + BOOST_CXX14_CONSTEXPR this_type& operator+=(const T& val) { r_ += val; return *this; } - this_type& operator-=(const T& val) + BOOST_CXX14_CONSTEXPR this_type& operator-=(const T& val) { r_ -= val; return *this; } - this_type& operator*=(const T& val) + BOOST_CXX14_CONSTEXPR this_type& operator*=(const T& val) { r_ *= val; i_ *= val; return *this; } - this_type& operator/=(const T& val) + BOOST_CXX14_CONSTEXPR this_type& operator/=(const T& val) { r_ /= val; i_ /= val; return *this; } - this_type& operator+=(const this_type& source) + BOOST_CXX14_CONSTEXPR this_type& operator+=(const this_type& source) { r_ += source.r_; i_ += source.i_; return *this; } - this_type& operator-=(const this_type& source) + BOOST_CXX14_CONSTEXPR this_type& operator-=(const this_type& source) { r_ -= source.r_; i_ -= source.i_; return *this; } - this_type& operator*=(const this_type& source) + BOOST_CXX14_CONSTEXPR this_type& operator*=(const this_type& source) { *this = *this * source; return *this; } - this_type& operator/=(const this_type& source) + BOOST_CXX14_CONSTEXPR this_type& operator/=(const this_type& source) { *this = *this / source; return *this; @@ -164,6 +164,7 @@ namespace boost { namespace units { template +BOOST_CONSTEXPR complex::type> operator+(const complex& x) { @@ -173,6 +174,7 @@ operator+(const complex& x) } template +BOOST_CONSTEXPR complex::type> operator-(const complex& x) { @@ -182,6 +184,7 @@ operator-(const complex& x) } template +BOOST_CONSTEXPR complex::type> operator+(const complex& x,const complex& y) { @@ -191,6 +194,7 @@ operator+(const complex& x,const complex& y) } template +BOOST_CONSTEXPR complex::type> operator-(const complex& x,const complex& y) { @@ -200,6 +204,7 @@ operator-(const complex& x,const complex& y) } template +BOOST_CONSTEXPR complex::type> operator*(const complex& x,const complex& y) { @@ -226,6 +231,7 @@ operator*(const complex& x,const complex& y) } template +BOOST_CONSTEXPR complex::type> operator/(const complex& x,const complex& y) { @@ -376,7 +382,7 @@ int main(void) //[complex_snippet_1 typedef quantity > length_dimension; - length_dimension L(complex(2.0,1.0)*meters); + BOOST_CONSTEXPR_OR_CONST length_dimension L(complex(2.0,1.0)*meters); //] std::cout << "+L = " << +L << std::endl @@ -396,7 +402,7 @@ int main(void) //[complex_snippet_2 typedef complex > length_dimension; - length_dimension L(2.0*meters,1.0*meters); + BOOST_CONSTEXPR_OR_CONST length_dimension L(2.0*meters,1.0*meters); //] std::cout << "+L = " << +L << std::endl diff --git a/example/conversion.cpp b/example/conversion.cpp index 0299dfdc..73b606be 100644 --- a/example/conversion.cpp +++ b/example/conversion.cpp @@ -62,21 +62,21 @@ int main() { // implicit value_type conversions //[conversion_snippet_1 - quantity L1 = quantity(int(2.5)*si::meters); - quantity L2(quantity(2.5*si::meters)); + BOOST_CONSTEXPR_OR_CONST quantity L1 = quantity(int(2.5)*si::meters); + BOOST_CONSTEXPR_OR_CONST quantity L2(quantity(2.5*si::meters)); //] //[conversion_snippet_3 - quantity L3 = static_cast >(L1); + BOOST_CONSTEXPR_OR_CONST quantity L3 = static_cast >(L1); //] //[conversion_snippet_4 - quantity L4 = static_cast >(L1); + BOOST_CONSTEXPR_OR_CONST quantity L4 = static_cast >(L1); //] - quantity L5(4*si::meters), - L6(5*si::meters); - quantity L7(L1); + quantity L5(4*si::meters), + L6(5*si::meters); + BOOST_CONSTEXPR_OR_CONST quantity L7(L1); swap(L5,L6); @@ -93,16 +93,16 @@ int main() // test explicit unit system conversion { //[conversion_snippet_5 - quantity vs(1.0*pow<3>(si::meter)); - quantity vc(vs); - quantity vs2(vc); + BOOST_CONSTEXPR_OR_CONST quantity vs(1.0*pow<3>(si::meter)); + BOOST_CONSTEXPR_OR_CONST quantity vc(vs); + BOOST_CONSTEXPR_OR_CONST quantity vs2(vc); - quantity es(1.0*si::joule); - quantity ec(es); - quantity es2(ec); + BOOST_CONSTEXPR_OR_CONST quantity es(1.0*si::joule); + BOOST_CONSTEXPR_OR_CONST quantity ec(es); + BOOST_CONSTEXPR_OR_CONST quantity es2(ec); - quantity v1 = 2.0*si::meters/si::second, - v2(2.0*cgs::centimeters/cgs::second); + BOOST_CONSTEXPR_OR_CONST quantity v1 = 2.0*si::meters/si::second, + v2(2.0*cgs::centimeters/cgs::second); //] std::cout << "volume (m^3) = " << vs << std::endl diff --git a/example/conversion_factor.cpp b/example/conversion_factor.cpp index 4401e477..f99f524f 100644 --- a/example/conversion_factor.cpp +++ b/example/conversion_factor.cpp @@ -50,23 +50,23 @@ int main() //[conversion_factor_snippet_1 - double dyne_to_newton = + BOOST_CONSTEXPR_OR_CONST double dyne_to_newton = conversion_factor(cgs::dyne,si::newton); std::cout << dyne_to_newton << std::endl; - double force_over_mass_conversion = + BOOST_CONSTEXPR_OR_CONST double force_over_mass_conversion = conversion_factor(si::newton/si::kilogram,cgs::dyne/cgs::gram); std::cout << force_over_mass_conversion << std::endl; - double momentum_conversion = + BOOST_CONSTEXPR_OR_CONST double momentum_conversion = conversion_factor(cgs::momentum(),si::momentum()); std::cout << momentum_conversion << std::endl; - double momentum_over_mass_conversion = + BOOST_CONSTEXPR_OR_CONST double momentum_over_mass_conversion = conversion_factor(si::momentum()/si::mass(),cgs::momentum()/cgs::gram); std::cout << momentum_over_mass_conversion << std::endl; - double acceleration_conversion = + BOOST_CONSTEXPR_OR_CONST double acceleration_conversion = conversion_factor(cgs::gal,si::meter_per_second_squared); std::cout << acceleration_conversion << std::endl; diff --git a/example/heterogeneous_unit.cpp b/example/heterogeneous_unit.cpp index 7a4f1123..e52ae48f 100644 --- a/example/heterogeneous_unit.cpp +++ b/example/heterogeneous_unit.cpp @@ -57,8 +57,8 @@ using namespace boost::units; int main() { //[heterogeneous_unit_snippet_1 - quantity L(1.5*si::meter); - quantity M(1.0*cgs::gram); + BOOST_CONSTEXPR_OR_CONST quantity L(1.5*si::meter); + BOOST_CONSTEXPR_OR_CONST quantity M(1.0*cgs::gram); std::cout << L << std::endl << M << std::endl @@ -76,7 +76,7 @@ int main() //] //[heterogeneous_unit_snippet_2 - quantity A(1.5*si::meter*cgs::centimeter); + BOOST_CONSTEXPR_OR_CONST quantity A(1.5*si::meter*cgs::centimeter); std::cout << 1.5*si::meter*cgs::centimeter << std::endl << A << std::endl diff --git a/example/information.cpp b/example/information.cpp index 0efc01a1..92572466 100644 --- a/example/information.cpp +++ b/example/information.cpp @@ -37,6 +37,7 @@ entropy in bytes= 0.125 B #include using std::cout; using std::endl; +using std::log; #include #include @@ -59,6 +60,7 @@ using namespace bu::information; // must be a unit of information. Conversion to the requested return unit is // accomplished automatically by the boost::units library. template +BOOST_CONSTEXPR quantity > bernoulli_entropy(double p, const bu::unit&) { typedef bu::unit requested_unit; @@ -67,15 +69,15 @@ bernoulli_entropy(double p, const bu::unit&) { int main(int argc, char** argv) { // a quantity of information (default in units of bytes) - quantity nbytes(1 * si::giga * bit); + BOOST_CONSTEXPR_OR_CONST quantity nbytes(1 * si::giga * bit); cout << "bytes= " << nbytes << endl; // a quantity of information, stored as bits - quantity nbits(1 * si::mega * byte); + BOOST_CONSTEXPR_OR_CONST quantity nbits(1 * si::mega * byte); cout << "bits= " << nbits << endl; // a quantity of information, stored as nats - quantity nnats(2 * si::kilo * hartleys); + BOOST_CONSTEXPR_OR_CONST quantity nnats(2 * si::kilo * hartleys); cout << "nats= " << nnats << endl; // how many bytes are in a kibi-byte? diff --git a/example/kitchen_sink.cpp b/example/kitchen_sink.cpp index 211d9819..da384962 100644 --- a/example/kitchen_sink.cpp +++ b/example/kitchen_sink.cpp @@ -200,6 +200,7 @@ namespace units { //[kitchen_sink_function_snippet_3 /// the physical definition of work - computed for an arbitrary unit system template +BOOST_CONSTEXPR quantity,Y> work(quantity,Y> F, quantity,Y> dx) @@ -211,6 +212,7 @@ work(quantity,Y> F, //[kitchen_sink_function_snippet_4 /// the ideal gas law in si units template +BOOST_CONSTEXPR quantity idealGasLaw(const quantity& P, const quantity& V, @@ -235,18 +237,18 @@ int main() { //[kitchen_sink_snippet_1 /// scalar - const double s1 = 2; + BOOST_CONSTEXPR_OR_CONST double s1 = 2; - const long x1 = 2; - const static_rational<4,3> x2; + BOOST_CONSTEXPR_OR_CONST long x1 = 2; + BOOST_CONSTEXPR_OR_CONST static_rational<4,3> x2; /// define some units - force u1 = newton; - energy u2 = joule; + BOOST_CONSTEXPR_OR_CONST force u1 = newton; + BOOST_CONSTEXPR_OR_CONST energy u2 = joule; /// define some quantities - quantity q1(1.0*u1); - quantity q2(2.0*u2); + BOOST_CONSTEXPR_OR_CONST quantity q1(1.0*u1); + BOOST_CONSTEXPR_OR_CONST quantity q2(2.0*u2); //] /// check scalar, unit, and quantity io @@ -326,8 +328,8 @@ int main() //[kitchen_sink_snippet_2 /// check comparison tests - quantity l1(1.0*meter), - l2(2.0*meters); + BOOST_CONSTEXPR_OR_CONST quantity l1(1.0*meter), + l2(2.0*meters); //] std::cout << std::boolalpha @@ -341,22 +343,22 @@ int main() //[kitchen_sink_snippet_3 /// check implicit unit conversion from dimensionless to value_type - const double dimless = (q1/q1); + BOOST_CONSTEXPR_OR_CONST double dimless = (q1/q1); //] std::cout << "dimless = " << dimless << std::endl << std::endl; - quantity v1 = 2.0*meters/second; + BOOST_CONSTEXPR_OR_CONST quantity v1 = 2.0*meters/second; std::cout << "v1 = " << v1 << std::endl << std::endl; //[kitchen_sink_snippet_4 /// test calcuation of work - quantity F(1.0*newton); - quantity dx(1.0*meter); - quantity E(work(F,dx)); + BOOST_CONSTEXPR_OR_CONST quantity F(1.0*newton); + BOOST_CONSTEXPR_OR_CONST quantity dx(1.0*meter); + BOOST_CONSTEXPR_OR_CONST quantity E(work(F,dx)); //] std::cout << "F = " << F << std::endl @@ -367,11 +369,11 @@ int main() { //[kitchen_sink_snippet_5 /// test ideal gas law - quantity T = (273.+37.)*kelvin; - quantity P = 1.01325e5*pascals; - quantity r = 0.5e-6*meters; - quantity V = (4.0/3.0)*3.141592*pow<3>(r); - quantity n(idealGasLaw(P,V,T)); + BOOST_CONSTEXPR_OR_CONST quantity T = (273.+37.)*kelvin; + BOOST_CONSTEXPR_OR_CONST quantity P = 1.01325e5*pascals; + BOOST_CONSTEXPR_OR_CONST quantity r = 0.5e-6*meters; + BOOST_CONSTEXPR_OR_CONST quantity V = (4.0/3.0)*3.141592*pow<3>(r); + BOOST_CONSTEXPR_OR_CONST quantity n(idealGasLaw(P,V,T)); //] std::cout << "r = " << r << std::endl @@ -389,9 +391,9 @@ int main() //[kitchen_sink_snippet_6 /// test trig stuff - quantity theta = 0.375*radians; - quantity sin_theta = sin(theta); - quantity thetap = asin(sin_theta); + BOOST_CONSTEXPR_OR_CONST quantity theta = 0.375*radians; + const quantity sin_theta = sin(theta); + const quantity thetap = asin(sin_theta); //] std::cout << "theta = " << theta << std::endl @@ -413,9 +415,9 @@ int main() typedef std::complex complex_type; //[kitchen_sink_snippet_7 - quantity v = complex_type(12.5,0.0)*volts; - quantity i = complex_type(3.0,4.0)*amperes; - quantity z = complex_type(1.5,-2.0)*ohms; + BOOST_CONSTEXPR_OR_CONST quantity v = complex_type(12.5,0.0)*volts; + BOOST_CONSTEXPR_OR_CONST quantity i = complex_type(3.0,4.0)*amperes; + BOOST_CONSTEXPR_OR_CONST quantity z = complex_type(1.5,-2.0)*ohms; //] std::cout << "V = " << v << std::endl @@ -427,7 +429,7 @@ int main() /// check quantities using user-defined type encapsulating error propagation //[kitchen_sink_snippet_8 - quantity > + BOOST_CONSTEXPR_OR_CONST quantity > u(measurement(1.0,0.0)*meters), w(measurement(4.52,0.02)*meters), x(measurement(2.0,0.2)*meters), diff --git a/example/lambda.cpp b/example/lambda.cpp index 0fbac916..f7c35e17 100644 --- a/example/lambda.cpp +++ b/example/lambda.cpp @@ -96,9 +96,9 @@ int main(int argc, char **argv) { //////////////////////////////////////////////////////////////////////// // Constants for the current amplitude, frequency, and offset current - const bu::quantity iamp = 1.5 * si::ampere; - const bu::quantity f = 1.0e3 * si::hertz; - const bu::quantity i0 = 0.5 * si::ampere; + BOOST_CONSTEXPR_OR_CONST bu::quantity iamp = 1.5 * si::ampere; + BOOST_CONSTEXPR_OR_CONST bu::quantity f = 1.0e3 * si::hertz; + BOOST_CONSTEXPR_OR_CONST bu::quantity i0 = 0.5 * si::ampere; // The invocation of the sin function needs to be postponed using // bind to specify the oscillation function. A lengthy static_cast @@ -121,7 +121,7 @@ int main(int argc, char **argv) { //////////////////////////////////////////////////////////////////////// // Length constant - const bu::quantity l = 1.5 * si::meter; + BOOST_CONSTEXPR_OR_CONST bu::quantity l = 1.5 * si::meter; // Again an ugly static_cast is needed to bind pow<2> to the first // function argument. @@ -138,9 +138,9 @@ int main(int argc, char **argv) { //////////////////////////////////////////////////////////////////////// // Absolute temperature constants - const bu::quantity > + BOOST_CONSTEXPR_OR_CONST bu::quantity > Tref = 273.15 * bu::absolute(); - const bu::quantity > + BOOST_CONSTEXPR_OR_CONST bu::quantity > Tamb = 300.00 * bu::absolute(); boost::function (bu::quantity >, diff --git a/example/measurement.hpp b/example/measurement.hpp index 217fac1b..fb2618af 100644 --- a/example/measurement.hpp +++ b/example/measurement.hpp @@ -26,6 +26,7 @@ namespace units { namespace sqr_namespace /**/ { template +BOOST_CONSTEXPR Y sqr(Y val) { return val*val; } @@ -40,20 +41,20 @@ class measurement typedef measurement this_type; typedef Y value_type; - measurement(const value_type& val = value_type(), + BOOST_CONSTEXPR measurement(const value_type& val = value_type(), const value_type& err = value_type()) : value_(val), uncertainty_(std::abs(err)) { } - measurement(const this_type& source) : + BOOST_CONSTEXPR measurement(const this_type& source) : value_(source.value_), uncertainty_(source.uncertainty_) { } //~measurement() { } - this_type& operator=(const this_type& source) + BOOST_CXX14_CONSTEXPR this_type& operator=(const this_type& source) { if (this == &source) return *this; @@ -63,43 +64,43 @@ class measurement return *this; } - operator value_type() const { return value_; } + BOOST_CONSTEXPR 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_; } + 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_; } - this_type& operator+=(const value_type& val) + BOOST_CXX14_CONSTEXPR this_type& operator+=(const value_type& val) { value_ += val; return *this; } - this_type& operator-=(const value_type& val) + BOOST_CXX14_CONSTEXPR this_type& operator-=(const value_type& val) { value_ -= val; return *this; } - this_type& operator*=(const value_type& val) + BOOST_CXX14_CONSTEXPR this_type& operator*=(const value_type& val) { value_ *= val; uncertainty_ *= val; return *this; } - this_type& operator/=(const value_type& val) + BOOST_CXX14_CONSTEXPR this_type& operator/=(const value_type& val) { value_ /= val; uncertainty_ /= val; return *this; } - this_type& operator+=(const this_type& /*source*/); - this_type& operator-=(const this_type& /*source*/); - this_type& operator*=(const this_type& /*source*/); - this_type& operator/=(const this_type& /*source*/); + BOOST_CXX14_CONSTEXPR this_type& operator+=(const this_type& /*source*/); + BOOST_CXX14_CONSTEXPR this_type& operator-=(const this_type& /*source*/); + BOOST_CXX14_CONSTEXPR this_type& operator*=(const this_type& /*source*/); + BOOST_CXX14_CONSTEXPR this_type& operator/=(const this_type& /*source*/); private: value_type value_, @@ -122,6 +123,7 @@ namespace units { template inline +BOOST_CXX14_CONSTEXPR measurement& measurement::operator+=(const this_type& source) { @@ -133,6 +135,7 @@ measurement::operator+=(const this_type& source) template inline +BOOST_CXX14_CONSTEXPR measurement& measurement::operator-=(const this_type& source) { @@ -144,6 +147,7 @@ measurement::operator-=(const this_type& source) template inline +BOOST_CXX14_CONSTEXPR measurement& measurement::operator*=(const this_type& source) { @@ -157,6 +161,7 @@ measurement::operator*=(const this_type& source) template inline +BOOST_CXX14_CONSTEXPR measurement& measurement::operator/=(const this_type& source) { @@ -171,6 +176,7 @@ measurement::operator/=(const this_type& source) // value_type op measurement template inline +BOOST_CONSTEXPR measurement operator+(Y lhs,const measurement& rhs) { @@ -179,6 +185,7 @@ operator+(Y lhs,const measurement& rhs) template inline +BOOST_CONSTEXPR measurement operator-(Y lhs,const measurement& rhs) { @@ -187,6 +194,7 @@ operator-(Y lhs,const measurement& rhs) template inline +BOOST_CONSTEXPR measurement operator*(Y lhs,const measurement& rhs) { @@ -195,6 +203,7 @@ operator*(Y lhs,const measurement& rhs) template inline +BOOST_CONSTEXPR measurement operator/(Y lhs,const measurement& rhs) { @@ -204,6 +213,7 @@ operator/(Y lhs,const measurement& rhs) // measurement op value_type template inline +BOOST_CONSTEXPR measurement operator+(const measurement& lhs,Y rhs) { @@ -212,6 +222,7 @@ operator+(const measurement& lhs,Y rhs) template inline +BOOST_CONSTEXPR measurement operator-(const measurement& lhs,Y rhs) { @@ -220,6 +231,7 @@ operator-(const measurement& lhs,Y rhs) template inline +BOOST_CONSTEXPR measurement operator*(const measurement& lhs,Y rhs) { @@ -228,6 +240,7 @@ operator*(const measurement& lhs,Y rhs) template inline +BOOST_CONSTEXPR measurement operator/(const measurement& lhs,Y rhs) { @@ -237,6 +250,7 @@ operator/(const measurement& lhs,Y rhs) // measurement op measurement template inline +BOOST_CONSTEXPR measurement operator+(const measurement& lhs,const measurement& rhs) { @@ -245,6 +259,7 @@ operator+(const measurement& lhs,const measurement& rhs) template inline +BOOST_CONSTEXPR measurement operator-(const measurement& lhs,const measurement& rhs) { @@ -253,6 +268,7 @@ operator-(const measurement& lhs,const measurement& rhs) template inline +BOOST_CONSTEXPR measurement operator*(const measurement& lhs,const measurement& rhs) { @@ -261,6 +277,7 @@ operator*(const measurement& lhs,const measurement& rhs) template inline +BOOST_CONSTEXPR measurement operator/(const measurement& lhs,const measurement& rhs) { @@ -275,7 +292,7 @@ struct power_typeof_helper,static_rational > typename power_typeof_helper >::type > type; - static type value(const measurement& x) + static BOOST_CXX14_CONSTEXPR type value(const measurement& x) { const static_rational rat; @@ -295,7 +312,7 @@ struct root_typeof_helper,static_rational > typename root_typeof_helper >::type > type; - static type value(const measurement& x) + static BOOST_CXX14_CONSTEXPR type value(const measurement& x) { const static_rational rat; diff --git a/example/non_base_dimension.cpp b/example/non_base_dimension.cpp index 4476a34e..77af1649 100644 --- a/example/non_base_dimension.cpp +++ b/example/non_base_dimension.cpp @@ -68,11 +68,11 @@ using namespace boost::units; int main(void) { - quantity ig1(1.0*imperial_gallon()); - quantity ug1(1.0*us_gallon()); + BOOST_CONSTEXPR_OR_CONST quantity ig1(1.0*imperial_gallon()); + BOOST_CONSTEXPR_OR_CONST quantity ug1(1.0*us_gallon()); - quantity ig2(ug1); - quantity ug2(ig1); + BOOST_CONSTEXPR_OR_CONST quantity ig2(ug1); + BOOST_CONSTEXPR_OR_CONST quantity ug2(ig1); return 0; } diff --git a/example/performance.cpp b/example/performance.cpp index 3407c137..fd2abe10 100644 --- a/example/performance.cpp +++ b/example/performance.cpp @@ -176,6 +176,7 @@ void tiled_multiply_carray_outer(T0* first, enum { max_value = 1000}; template +BOOST_CXX14_CONSTEXPR R solve_differential_equation(F f, T lower, T upper, N steps, R start) { typedef typename F::template result::type f_result; T h = (upper - lower) / (1.0*steps); @@ -197,13 +198,13 @@ using namespace boost::units; struct f { template struct result; - double operator()(const double& x, const double& y) const { + BOOST_CONSTEXPR double operator()(const double& x, const double& y) const { return(1.0 - x + 4.0 * y); } boost::units::quantity - operator()(const quantity& x, - const quantity& y) const { + BOOST_CONSTEXPR operator()(const quantity& x, + const quantity& y) const { using namespace boost::units; using namespace si; return(1.0 * meters / second - @@ -330,7 +331,7 @@ int main() { } for(int i = 0; i < max_value; ++i) { for(int j = 0; j < max_value; ++j) { - double diff = + const double diff = std::abs(ublas_result(i,j) - cresult[i * max_value + j]); if(diff > ublas_result(i,j) /1e14) { std::cout << std::setprecision(15) << "Uh Oh. ublas_result(" @@ -348,13 +349,13 @@ int main() { std::cout << "solving y' = 1 - x + 4 * y with double: "; boost::timer timer; for(int i = 0; i < 1000; ++i) { - double x = .1 * i; + const double x = .1 * i; values[i] = solve_differential_equation(f(), 0.0, x, i * 100, 1.0); } std::cout << timer.elapsed() << " seconds" << std::endl; for(int i = 0; i < 1000; ++i) { - double x = .1 * i; - double value = 1.0/4.0 * x - 3.0/16.0 + 19.0/16.0 * std::exp(4 * x); + const double x = .1 * i; + const double value = 1.0/4.0 * x - 3.0/16.0 + 19.0/16.0 * std::exp(4 * x); if(std::abs(values[i] - value) > value / 1e9) { std::cout << std::setprecision(15) << "i = : " << i << ", value = " << value << " approx = " << values[i] @@ -370,7 +371,7 @@ int main() { std::cout << "solving y' = 1 - x + 4 * y with quantity: "; boost::timer timer; for(int i = 0; i < 1000; ++i) { - quantity x = .1 * i * seconds; + const quantity x = .1 * i * seconds; values[i] = solve_differential_equation( f(), 0.0 * seconds, @@ -380,8 +381,8 @@ int main() { } std::cout << timer.elapsed() << " seconds" << std::endl; for(int i = 0; i < 1000; ++i) { - double x = .1 * i; - quantity value = + const double x = .1 * i; + const quantity value = (1.0/4.0 * x - 3.0/16.0 + 19.0/16.0 * std::exp(4 * x)) * meters; if(abs(values[i] - value) > value / 1e9) { std::cout << std::setprecision(15) << "i = : " << i diff --git a/example/quantity.cpp b/example/quantity.cpp index e3d3f18a..dbf0cde8 100644 --- a/example/quantity.cpp +++ b/example/quantity.cpp @@ -72,8 +72,8 @@ int main(void) { //[quantity_snippet_1 - quantity L = 2.0*meters; // quantity of length - quantity E = kilograms*pow<2>(L/seconds); // quantity of energy + BOOST_CONSTEXPR_OR_CONST quantity L = 2.0*meters; // quantity of length + BOOST_CONSTEXPR_OR_CONST quantity E = kilograms*pow<2>(L/seconds); // quantity of energy //] std::cout << "L = " << L << std::endl @@ -99,8 +99,8 @@ int main(void) { //[quantity_snippet_2 - quantity > L(std::complex(3.0,4.0)*meters); - quantity > E(kilograms*pow<2>(L/seconds)); + const quantity > L(std::complex(3.0,4.0)*meters); + const quantity > E(kilograms*pow<2>(L/seconds)); //] std::cout << "L = " << L << std::endl diff --git a/example/radar_beam_height.cpp b/example/radar_beam_height.cpp index 63752f7c..8277bd18 100644 --- a/example/radar_beam_height.cpp +++ b/example/radar_beam_height.cpp @@ -62,7 +62,7 @@ typedef boost::units::make_system::type system; /// unit typedefs typedef unit length; -static const length mile,miles; +BOOST_STATIC_CONSTEXPR length mile,miles; } // namespace nautical @@ -87,7 +87,7 @@ typedef boost::units::make_system::type system; /// unit typedefs typedef unit length; -static const length foot,feet; +BOOST_STATIC_CONSTEXPR length foot,feet; } // imperial @@ -100,6 +100,7 @@ BOOST_UNITS_DEFINE_CONVERSION_FACTOR(imperial::length_base_unit, // radar beam height functions //[radar_beam_height_function_snippet_1 template +BOOST_CONSTEXPR quantity,T> radar_beam_height(const quantity,T>& radar_range, const quantity,T>& earth_radius, @@ -112,20 +113,20 @@ radar_beam_height(const quantity,T>& radar_range, //[radar_beam_height_function_snippet_2 template +BOOST_CONSTEXPR return_type radar_beam_height(const quantity,T>& radar_range, const quantity,T>& earth_radius, T k = 4.0/3.0) { // need to decide which system to use for calculation - const return_type rr(radar_range), - er(earth_radius); - - return return_type(pow<2>(rr)/(2.0*k*er)); + return pow<2>(static_cast(radar_range)) + / (2.0*k*static_cast(earth_radius)); } //] //[radar_beam_height_function_snippet_3 +BOOST_CONSTEXPR quantity radar_beam_height(const quantity& range) { @@ -141,13 +142,13 @@ int main(void) using namespace nautical; //[radar_beam_height_snippet_1 - const quantity radar_range(300.0*miles); - const quantity earth_radius(6371.0087714*kilo*meters); - - const quantity beam_height_1(radar_beam_height(quantity(radar_range),earth_radius)); - const quantity beam_height_2(radar_beam_height(radar_range,quantity(earth_radius))); - const quantity beam_height_3(radar_beam_height< quantity >(radar_range,earth_radius)); - const quantity beam_height_4(radar_beam_height< quantity >(radar_range,earth_radius)); + BOOST_CONSTEXPR_OR_CONST quantity radar_range(300.0*miles); + BOOST_CONSTEXPR_OR_CONST quantity earth_radius(6371.0087714*kilo*meters); + + BOOST_CONSTEXPR_OR_CONST quantity beam_height_1(radar_beam_height(quantity(radar_range),earth_radius)); + BOOST_CONSTEXPR_OR_CONST quantity beam_height_2(radar_beam_height(radar_range,quantity(earth_radius))); + BOOST_CONSTEXPR_OR_CONST quantity beam_height_3(radar_beam_height< quantity >(radar_range,earth_radius)); + BOOST_CONSTEXPR_OR_CONST quantity beam_height_4(radar_beam_height< quantity >(radar_range,earth_radius)); //] std::cout << "radar range : " << radar_range << std::endl diff --git a/example/systems.cpp b/example/systems.cpp index 877b2fa7..a4232768 100644 --- a/example/systems.cpp +++ b/example/systems.cpp @@ -28,7 +28,7 @@ namespace units { namespace namespace_ { \ typedef make_system::type unit_name_ ## system_; \ typedef unit unit_name_ ## _ ## dimension_; \ -static const unit_name_ ## _ ## dimension_ unit_name_ ## s; \ +BOOST_STATIC_CONSTEXPR unit_name_ ## _ ## dimension_ unit_name_ ## s; \ } \ } \ } \ @@ -238,12 +238,12 @@ int main(void) std::cout << "Testing angle base units..." << std::endl; - quantity as(1.0*arcseconds); - quantity am(1.0*arcminutes); - quantity d(1.0*degrees); - quantity g(1.0*gradians); - quantity r(1.0*radians); - quantity rev(1.0*revolutions); + BOOST_CONSTEXPR_OR_CONST quantity as(1.0*arcseconds); + BOOST_CONSTEXPR_OR_CONST quantity am(1.0*arcminutes); + BOOST_CONSTEXPR_OR_CONST quantity d(1.0*degrees); + BOOST_CONSTEXPR_OR_CONST quantity g(1.0*gradians); + BOOST_CONSTEXPR_OR_CONST quantity r(1.0*radians); + BOOST_CONSTEXPR_OR_CONST quantity rev(1.0*revolutions); std::cout << as << " = " << quantity(as) << std::endl << am << " = " << quantity(am) << std::endl @@ -286,7 +286,7 @@ int main(void) << rev << " = " << quantity(rev) << std::endl << std::endl; - quantity sa1(1.0*steradians); + BOOST_CONSTEXPR_OR_CONST quantity sa1(1.0*steradians); std::cout << sa1 << std::endl << std::endl; @@ -297,13 +297,13 @@ int main(void) std::cout << "Testing astronomical base units..." << std::endl; - quantity ls(1.0*light_seconds); - quantity lm(1.0*light_minutes); - quantity au(1.0*astronomical_units); - quantity lh(1.0*light_hours); - quantity ld(1.0*light_days); - quantity ly(1.0*light_years); - quantity ps(1.0*parsecs); + BOOST_CONSTEXPR_OR_CONST quantity ls(1.0*light_seconds); + BOOST_CONSTEXPR_OR_CONST quantity lm(1.0*light_minutes); + BOOST_CONSTEXPR_OR_CONST quantity au(1.0*astronomical_units); + BOOST_CONSTEXPR_OR_CONST quantity lh(1.0*light_hours); + BOOST_CONSTEXPR_OR_CONST quantity ld(1.0*light_days); + BOOST_CONSTEXPR_OR_CONST quantity ly(1.0*light_years); + BOOST_CONSTEXPR_OR_CONST quantity ps(1.0*parsecs); std::cout << ls << " = " << quantity(ls) << std::endl << lm << " = " << quantity(lm) << std::endl @@ -363,13 +363,13 @@ int main(void) std::cout << "Testing imperial base units..." << std::endl; - quantity iml1(1.0*thous); - quantity iml2(1.0*inchs); - quantity iml3(1.0*foots); - quantity iml4(1.0*yards); - quantity iml5(1.0*furlongs); - quantity iml6(1.0*miles); - quantity iml7(1.0*leagues); + BOOST_CONSTEXPR_OR_CONST quantity iml1(1.0*thous); + BOOST_CONSTEXPR_OR_CONST quantity iml2(1.0*inchs); + BOOST_CONSTEXPR_OR_CONST quantity iml3(1.0*foots); + BOOST_CONSTEXPR_OR_CONST quantity iml4(1.0*yards); + BOOST_CONSTEXPR_OR_CONST quantity iml5(1.0*furlongs); + BOOST_CONSTEXPR_OR_CONST quantity iml6(1.0*miles); + BOOST_CONSTEXPR_OR_CONST quantity iml7(1.0*leagues); std::cout << iml1 << " = " << quantity(iml1) << std::endl << iml2 << " = " << quantity(iml2) << std::endl @@ -451,14 +451,14 @@ int main(void) << iml7 << " = " << quantity(iml7) << std::endl << std::endl; - quantity imm1(1.0*grains); - quantity imm2(1.0*drachms); - quantity imm3(1.0*ounces); - quantity imm4(1.0*pounds); - quantity imm5(1.0*stones); - quantity imm6(1.0*quarters); - quantity imm7(1.0*hundredweights); - quantity imm8(1.0*tons); + BOOST_CONSTEXPR_OR_CONST quantity imm1(1.0*grains); + BOOST_CONSTEXPR_OR_CONST quantity imm2(1.0*drachms); + BOOST_CONSTEXPR_OR_CONST quantity imm3(1.0*ounces); + BOOST_CONSTEXPR_OR_CONST quantity imm4(1.0*pounds); + BOOST_CONSTEXPR_OR_CONST quantity imm5(1.0*stones); + BOOST_CONSTEXPR_OR_CONST quantity imm6(1.0*quarters); + BOOST_CONSTEXPR_OR_CONST quantity imm7(1.0*hundredweights); + BOOST_CONSTEXPR_OR_CONST quantity imm8(1.0*tons); std::cout << imm1 << " = " << quantity(imm1) << std::endl << imm2 << " = " << quantity(imm2) << std::endl @@ -559,11 +559,11 @@ int main(void) << imm8 << " = " << quantity(imm8) << std::endl << std::endl; - quantity imv1(1.0*fluid_ounces); - quantity imv2(1.0*gills); - quantity imv3(1.0*pints); - quantity imv4(1.0*quarts); - quantity imv5(1.0*gallons); + BOOST_CONSTEXPR_OR_CONST quantity imv1(1.0*fluid_ounces); + BOOST_CONSTEXPR_OR_CONST quantity imv2(1.0*gills); + BOOST_CONSTEXPR_OR_CONST quantity imv3(1.0*pints); + BOOST_CONSTEXPR_OR_CONST quantity imv4(1.0*quarts); + BOOST_CONSTEXPR_OR_CONST quantity imv5(1.0*gallons); std::cout << imv1 << " = " << quantity(imv1) << std::endl << imv2 << " = " << quantity(imv2) << std::endl @@ -619,10 +619,10 @@ int main(void) std::cout << "Testing metric base units..." << std::endl; - quantity ml1(1.0*fermis); - quantity ml2(1.0*angstroms); - quantity ml3(1.0*microns); - quantity ml4(1.0*nautical_miles); + BOOST_CONSTEXPR_OR_CONST quantity ml1(1.0*fermis); + BOOST_CONSTEXPR_OR_CONST quantity ml2(1.0*angstroms); + BOOST_CONSTEXPR_OR_CONST quantity ml3(1.0*microns); + BOOST_CONSTEXPR_OR_CONST quantity ml4(1.0*nautical_miles); std::cout << ml1 << " = " << quantity(ml1) << std::endl << ml2 << " = " << quantity(ml2) << std::endl @@ -659,16 +659,16 @@ int main(void) << ml4 << " = " << quantity(ml4) << std::endl << std::endl; - quantity mm1(1.0*tons); + BOOST_CONSTEXPR_OR_CONST quantity mm1(1.0*tons); std::cout << mm1 << " = " << quantity(mm1) << std::endl //<< quantity(mm1) << std::endl // this should work... << std::endl; - quantity mt1(1.0*minutes); - quantity mt2(1.0*hours); - quantity mt3(1.0*days); - quantity mt4(1.0*years); + BOOST_CONSTEXPR_OR_CONST quantity mt1(1.0*minutes); + BOOST_CONSTEXPR_OR_CONST quantity mt2(1.0*hours); + BOOST_CONSTEXPR_OR_CONST quantity mt3(1.0*days); + BOOST_CONSTEXPR_OR_CONST quantity mt4(1.0*years); std::cout << mt1 << " = " << quantity(mt1) << std::endl << mt2 << " = " << quantity(mt2) << std::endl @@ -705,14 +705,14 @@ int main(void) << mt4 << " = " << quantity(mt4) << std::endl << std::endl; - quantity ms1(1.0*knots); + BOOST_CONSTEXPR_OR_CONST quantity ms1(1.0*knots); std::cout << ms1 << " = " << quantity(ms1) << std::endl << std::endl; - quantity ma1(1.0*barns); - quantity ma2(1.0*ares); - quantity ma3(1.0*hectares); + BOOST_CONSTEXPR_OR_CONST quantity ma1(1.0*barns); + BOOST_CONSTEXPR_OR_CONST quantity ma2(1.0*ares); + BOOST_CONSTEXPR_OR_CONST quantity ma3(1.0*hectares); std::cout << ma1 << " = " << quantity(ma1) << std::endl << ma2 << " = " << quantity(ma2) << std::endl @@ -738,15 +738,15 @@ int main(void) << ma3 << " = " << quantity(ma3) << std::endl << std::endl; - quantity mv1(1.0*liters); + BOOST_CONSTEXPR_OR_CONST quantity mv1(1.0*liters); std::cout << mv1 << " = " << quantity(mv1) << std::endl << std::endl; - quantity mp1(1.0*mmHgs); - quantity mp2(1.0*torrs); - quantity mp3(1.0*bars); - quantity mp4(1.0*atmospheres); + BOOST_CONSTEXPR_OR_CONST quantity mp1(1.0*mmHgs); + BOOST_CONSTEXPR_OR_CONST quantity mp2(1.0*torrs); + BOOST_CONSTEXPR_OR_CONST quantity mp3(1.0*bars); + BOOST_CONSTEXPR_OR_CONST quantity mp4(1.0*atmospheres); std::cout << mp1 << " = " << quantity(mp1) << std::endl << mp2 << " = " << quantity(mp2) << std::endl @@ -789,11 +789,11 @@ int main(void) std::cout << "Testing U.S. customary base units..." << std::endl; - quantity iml1(1.0*mils); - quantity iml2(1.0*inchs); - quantity iml3(1.0*foots); - quantity iml4(1.0*yards); - quantity iml5(1.0*miles); + BOOST_CONSTEXPR_OR_CONST quantity iml1(1.0*mils); + BOOST_CONSTEXPR_OR_CONST quantity iml2(1.0*inchs); + BOOST_CONSTEXPR_OR_CONST quantity iml3(1.0*foots); + BOOST_CONSTEXPR_OR_CONST quantity iml4(1.0*yards); + BOOST_CONSTEXPR_OR_CONST quantity iml5(1.0*miles); std::cout << iml1 << " = " << quantity(iml1) << std::endl << iml2 << " = " << quantity(iml2) << std::endl @@ -843,12 +843,12 @@ int main(void) << iml5 << " = " << quantity(iml5) << std::endl << std::endl; - quantity imm1(1.0*grains); - quantity imm2(1.0*drams); - quantity imm3(1.0*ounces); - quantity imm4(1.0*pounds); - quantity imm5(1.0*hundredweights); - quantity imm6(1.0*tons); + BOOST_CONSTEXPR_OR_CONST quantity imm1(1.0*grains); + BOOST_CONSTEXPR_OR_CONST quantity imm2(1.0*drams); + BOOST_CONSTEXPR_OR_CONST quantity imm3(1.0*ounces); + BOOST_CONSTEXPR_OR_CONST quantity imm4(1.0*pounds); + BOOST_CONSTEXPR_OR_CONST quantity imm5(1.0*hundredweights); + BOOST_CONSTEXPR_OR_CONST quantity imm6(1.0*tons); std::cout << imm1 << " = " << quantity(imm1) << std::endl << imm2 << " = " << quantity(imm2) << std::endl @@ -913,16 +913,16 @@ int main(void) << imm6 << " = " << quantity(imm6) << std::endl << std::endl; - quantity imv1(1.0*minims); - quantity imv2(1.0*fluid_drams); - quantity imv3(1.0*teaspoons); - quantity imv4(1.0*tablespoons); - quantity imv5(1.0*fluid_ounces); - quantity imv6(1.0*gills); - quantity imv7(1.0*cups); - quantity imv8(1.0*pints); - quantity imv9(1.0*quarts); - quantity imv10(1.0*gallons); + BOOST_CONSTEXPR_OR_CONST quantity imv1(1.0*minims); + BOOST_CONSTEXPR_OR_CONST quantity imv2(1.0*fluid_drams); + BOOST_CONSTEXPR_OR_CONST quantity imv3(1.0*teaspoons); + BOOST_CONSTEXPR_OR_CONST quantity imv4(1.0*tablespoons); + BOOST_CONSTEXPR_OR_CONST quantity imv5(1.0*fluid_ounces); + BOOST_CONSTEXPR_OR_CONST quantity imv6(1.0*gills); + BOOST_CONSTEXPR_OR_CONST quantity imv7(1.0*cups); + BOOST_CONSTEXPR_OR_CONST quantity imv8(1.0*pints); + BOOST_CONSTEXPR_OR_CONST quantity imv9(1.0*quarts); + BOOST_CONSTEXPR_OR_CONST quantity imv10(1.0*gallons); std::cout << imv1 << " = " << quantity(imv1) << std::endl << imv2 << " = " << quantity(imv2) << std::endl diff --git a/example/temperature.cpp b/example/temperature.cpp index f6b43421..312818be 100644 --- a/example/temperature.cpp +++ b/example/temperature.cpp @@ -70,13 +70,13 @@ BOOST_UNITS_STATIC_CONSTANT(degrees,temperature); int main() { //[temperature_snippet_3 - quantity > T1p( + BOOST_CONSTEXPR_OR_CONST quantity > T1p( 32.0*absolute()); - quantity T1v( + BOOST_CONSTEXPR_OR_CONST quantity T1v( 32.0*fahrenheit::degrees); - quantity > T2p(T1p); - quantity T2v(T1v); + BOOST_CONSTEXPR_OR_CONST quantity > T2p(T1p); + BOOST_CONSTEXPR_OR_CONST quantity T2v(T1v); //] typedef conversion_helper< diff --git a/example/tutorial.cpp b/example/tutorial.cpp index 855cce61..510f6a52 100644 --- a/example/tutorial.cpp +++ b/example/tutorial.cpp @@ -55,6 +55,7 @@ I*Z == V? true using namespace boost::units; using namespace boost::units::si; +BOOST_CONSTEXPR quantity work(const quantity& F, const quantity& dx) { @@ -64,9 +65,9 @@ work(const quantity& F, const quantity& dx) int main() { /// Test calculation of work. - quantity F(2.0 * newton); // Define a quantity of force. - quantity dx(2.0 * meter); // and a distance, - quantity E(work(F,dx)); // and calculate the work done. + BOOST_CONSTEXPR_OR_CONST quantity F(2.0 * newton); // Define a quantity of force. + BOOST_CONSTEXPR_OR_CONST quantity dx(2.0 * meter); // and a distance, + BOOST_CONSTEXPR_OR_CONST quantity E(work(F,dx)); // and calculate the work done. std::cout << "F = " << F << std::endl << "dx = " << dx << std::endl @@ -77,9 +78,9 @@ int main() typedef std::complex complex_type; // double real and imaginary parts. // Define some complex electrical quantities. - quantity v = complex_type(12.5, 0.0) * volts; - quantity i = complex_type(3.0, 4.0) * amperes; - quantity z = complex_type(1.5, -2.0) * ohms; + BOOST_CONSTEXPR_OR_CONST quantity v = complex_type(12.5, 0.0) * volts; + BOOST_CONSTEXPR_OR_CONST quantity i = complex_type(3.0, 4.0) * amperes; + BOOST_CONSTEXPR_OR_CONST quantity z = complex_type(1.5, -2.0) * ohms; std::cout << "V = " << v << std::endl << "I = " << i << std::endl diff --git a/example/unit.cpp b/example/unit.cpp index 934d5573..4fbc25c5 100644 --- a/example/unit.cpp +++ b/example/unit.cpp @@ -48,11 +48,11 @@ int main() using namespace boost::units::test; //[unit_snippet_1 - const length L; - const mass M; + BOOST_CONSTEXPR_OR_CONST length L; + BOOST_CONSTEXPR_OR_CONST mass M; // needs to be namespace-qualified because of global time definition - const boost::units::test::time T; - const energy E; + BOOST_CONSTEXPR_OR_CONST boost::units::test::time T; + BOOST_CONSTEXPR_OR_CONST energy E; //] std::cout << "L = " << L << std::endl diff --git a/include/boost/units/absolute.hpp b/include/boost/units/absolute.hpp index c035475a..25415945 100644 --- a/include/boost/units/absolute.hpp +++ b/include/boost/units/absolute.hpp @@ -37,16 +37,16 @@ class absolute typedef absolute this_type; typedef Y value_type; - absolute() : val_() { } - absolute(const value_type& val) : val_(val) { } - absolute(const this_type& source) : val_(source.val_) { } + BOOST_CONSTEXPR absolute() : val_() { } + BOOST_CONSTEXPR absolute(const value_type& val) : val_(val) { } + BOOST_CONSTEXPR absolute(const this_type& source) : val_(source.val_) { } - this_type& operator=(const this_type& source) { val_ = source.val_; return *this; } + BOOST_CXX14_CONSTEXPR this_type& operator=(const this_type& source) { val_ = source.val_; return *this; } - const value_type& value() const { return val_; } + BOOST_CONSTEXPR const value_type& value() const { return val_; } - const this_type& operator+=(const value_type& val) { val_ += val; return *this; } - const this_type& operator-=(const value_type& val) { val_ -= val; return *this; } + BOOST_CXX14_CONSTEXPR const this_type& operator+=(const value_type& val) { val_ += val; return *this; } + BOOST_CXX14_CONSTEXPR const this_type& operator-=(const value_type& val) { val_ -= val; return *this; } private: value_type val_; @@ -54,42 +54,42 @@ class absolute /// add a relative value to an absolute one template -absolute operator+(const absolute& aval,const Y& rval) +BOOST_CONSTEXPR absolute operator+(const absolute& aval,const Y& rval) { return absolute(aval.value()+rval); } /// add a relative value to an absolute one template -absolute operator+(const Y& rval,const absolute& aval) +BOOST_CONSTEXPR absolute operator+(const Y& rval,const absolute& aval) { return absolute(aval.value()+rval); } /// subtract a relative value from an absolute one template -absolute operator-(const absolute& aval,const Y& rval) +BOOST_CONSTEXPR absolute operator-(const absolute& aval,const Y& rval) { return absolute(aval.value()-rval); } /// subtracting two absolutes gives a difference template -Y operator-(const absolute& aval1,const absolute& aval2) +BOOST_CONSTEXPR Y operator-(const absolute& aval1,const absolute& aval2) { return Y(aval1.value()-aval2.value()); } /// creates a quantity from an absolute unit and a raw value template -quantity >, T> operator*(const T& t, const absolute >&) +BOOST_CONSTEXPR quantity >, T> operator*(const T& t, const absolute >&) { return(quantity >, T>::from_value(t)); } /// creates a quantity from an absolute unit and a raw value template -quantity >, T> operator*(const absolute >&, const T& t) +BOOST_CONSTEXPR quantity >, T> operator*(const absolute >&, const T& t) { return(quantity >, T>::from_value(t)); } @@ -138,9 +138,9 @@ namespace units { reduce_unit::type, \ reduce_unit::type> \ { \ - static const bool is_defined = true; \ + BOOST_STATIC_CONSTEXPR bool is_defined = true; \ typedef type_ type; \ - static type value() { return(value_); } \ + static BOOST_CONSTEXPR type value() { return(value_); } \ }; \ } \ } \ diff --git a/include/boost/units/base_dimension.hpp b/include/boost/units/base_dimension.hpp index a635aa66..430f019e 100644 --- a/include/boost/units/base_dimension.hpp +++ b/include/boost/units/base_dimension.hpp @@ -83,21 +83,21 @@ class base_dimension : /// check_base_dimension will trigger an error earlier /// for compilers with less strict name lookup. /// INTERNAL ONLY - friend Derived* + friend BOOST_CONSTEXPR Derived* check_double_register(const units::base_dimension_ordinal&) { return(0); } /// Register this ordinal /// INTERNAL ONLY - friend detail::yes + friend BOOST_CONSTEXPR detail::yes boost_units_is_registered(const units::base_dimension_ordinal&) - { detail::yes result; return(result); } + { return(detail::yes()); } /// But make sure we can identify the current instantiation! /// INTERNAL ONLY - friend detail::yes + friend BOOST_CONSTEXPR detail::yes boost_units_is_registered(const units::base_dimension_pair&) - { detail::yes result; return(result); } + { return(detail::yes()); } }; } // namespace units diff --git a/include/boost/units/base_unit.hpp b/include/boost/units/base_unit.hpp index 94fc4165..b66558a6 100644 --- a/include/boost/units/base_unit.hpp +++ b/include/boost/units/base_unit.hpp @@ -104,21 +104,21 @@ class base_unit : /// check_base_unit will trigger an error earlier /// for compilers with less strict name lookup. /// INTERNAL ONLY - friend Derived* + friend BOOST_CONSTEXPR Derived* check_double_register(const units::base_unit_ordinal&) { return(0); } /// Register this ordinal /// INTERNAL ONLY - friend detail::yes + friend BOOST_CONSTEXPR detail::yes boost_units_unit_is_registered(const units::base_unit_ordinal&) - { detail::yes result; return(result); } + { return(detail::yes()); } /// But make sure we can identify the current instantiation! /// INTERNAL ONLY - friend detail::yes + friend BOOST_CONSTEXPR detail::yes boost_units_unit_is_registered(const units::base_unit_pair&) - { detail::yes result; return(result); } + { return(detail::yes()); } }; } // namespace units diff --git a/include/boost/units/cmath.hpp b/include/boost/units/cmath.hpp index 238b31c3..da3da46f 100644 --- a/include/boost/units/cmath.hpp +++ b/include/boost/units/cmath.hpp @@ -47,6 +47,7 @@ namespace units { template inline +BOOST_CONSTEXPR bool isfinite BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) { @@ -56,6 +57,7 @@ isfinite BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) template inline +BOOST_CONSTEXPR bool isinf BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) { @@ -65,6 +67,7 @@ isinf BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) template inline +BOOST_CONSTEXPR bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) { @@ -74,6 +77,7 @@ isnan BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) template inline +BOOST_CONSTEXPR bool isnormal BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) { @@ -83,6 +87,7 @@ isnormal BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) template inline +BOOST_CONSTEXPR bool isgreater BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, const quantity& q2) @@ -93,6 +98,7 @@ isgreater BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, template inline +BOOST_CONSTEXPR bool isgreaterequal BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, const quantity& q2) @@ -103,6 +109,7 @@ isgreaterequal BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, template inline +BOOST_CONSTEXPR bool isless BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, const quantity& q2) @@ -113,6 +120,7 @@ isless BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, template inline +BOOST_CONSTEXPR bool islessequal BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, const quantity& q2) @@ -123,6 +131,7 @@ islessequal BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, template inline +BOOST_CONSTEXPR bool islessgreater BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, const quantity& q2) @@ -133,6 +142,7 @@ islessgreater BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, template inline +BOOST_CONSTEXPR bool isunordered BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, const quantity& q2) @@ -143,6 +153,7 @@ isunordered BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, template inline +BOOST_CONSTEXPR quantity abs BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) { @@ -155,6 +166,7 @@ abs BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) template inline +BOOST_CONSTEXPR quantity ceil BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) { @@ -167,6 +179,7 @@ ceil BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) template inline +BOOST_CONSTEXPR quantity copysign BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, const quantity& q2) @@ -180,6 +193,7 @@ copysign BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, template inline +BOOST_CONSTEXPR quantity fabs BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) { @@ -192,6 +206,7 @@ fabs BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) template inline +BOOST_CONSTEXPR quantity floor BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) { @@ -204,6 +219,7 @@ floor BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) template inline +BOOST_CONSTEXPR quantity fdim BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, const quantity& q2) @@ -219,6 +235,7 @@ fdim BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, template inline +BOOST_CONSTEXPR typename add_typeof_helper< typename multiply_typeof_helper, quantity >::type, @@ -243,6 +260,7 @@ fma BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, template inline +BOOST_CONSTEXPR quantity fmax BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, const quantity& q2) @@ -256,6 +274,7 @@ fmax BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, template inline +BOOST_CONSTEXPR quantity fmin BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, const quantity& q2) @@ -269,6 +288,7 @@ fmin BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, template inline +BOOST_CONSTEXPR int fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) { @@ -279,6 +299,7 @@ fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) template inline +BOOST_CONSTEXPR typename root_typeof_helper< typename add_typeof_helper< typename power_typeof_helper, @@ -302,6 +323,7 @@ hypot BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1,const quantit // does ISO C++ support long long? g++ claims not //template //inline +//BOOST_CONSTEXPR //quantity //llrint BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) //{ @@ -315,6 +337,7 @@ hypot BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1,const quantit // does ISO C++ support long long? g++ claims not //template //inline +//BOOST_CONSTEXPR //quantity //llround BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) //{ @@ -329,6 +352,7 @@ hypot BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1,const quantit template inline +BOOST_CONSTEXPR quantity nearbyint BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) { @@ -343,6 +367,7 @@ nearbyint BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) template inline +BOOST_CONSTEXPR quantity nextafter BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, const quantity& q2) { @@ -354,6 +379,7 @@ quantity nextafter BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity inline +BOOST_CONSTEXPR quantity nexttoward BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q1, const quantity& q2) { @@ -371,6 +397,7 @@ quantity nexttoward BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity inline +BOOST_CONSTEXPR quantity rint BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) { @@ -385,6 +412,7 @@ rint BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) template inline +BOOST_CONSTEXPR quantity round BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) { @@ -397,6 +425,7 @@ round BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) template inline +BOOST_CONSTEXPR int signbit BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) { @@ -407,6 +436,7 @@ signbit BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) template inline +BOOST_CONSTEXPR quantity trunc BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) { @@ -419,6 +449,7 @@ trunc BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity& q) template inline +BOOST_CONSTEXPR quantity fmod(const quantity& q1, const quantity& q2) { @@ -431,6 +462,7 @@ fmod(const quantity& q1, const quantity& q2) template inline +BOOST_CONSTEXPR quantity modf(const quantity& q1, quantity* q2) { @@ -443,6 +475,7 @@ modf(const quantity& q1, quantity* q2) template inline +BOOST_CONSTEXPR quantity frexp(const quantity& q,Int* ex) { @@ -457,6 +490,7 @@ frexp(const quantity& q,Int* ex) /// and roots can be computed by @c pow and @c root respectively. template inline +BOOST_CONSTEXPR quantity pow(const quantity& q1, const quantity& q2) @@ -470,6 +504,7 @@ pow(const quantity& q1, template inline +BOOST_CONSTEXPR quantity exp(const quantity& q) { @@ -482,6 +517,7 @@ exp(const quantity& q) template inline +BOOST_CONSTEXPR quantity ldexp(const quantity& q,const Int& ex) { @@ -494,6 +530,7 @@ ldexp(const quantity& q,const Int& ex) template inline +BOOST_CONSTEXPR quantity log(const quantity& q) { @@ -506,6 +543,7 @@ log(const quantity& q) template inline +BOOST_CONSTEXPR quantity log10(const quantity& q) { @@ -518,6 +556,7 @@ log10(const quantity& q) template inline +BOOST_CONSTEXPR typename root_typeof_helper< quantity, static_rational<2> @@ -546,6 +585,7 @@ namespace units { /// cos of theta in radians template +BOOST_CONSTEXPR typename dimensionless_quantity::type cos(const quantity& theta) { @@ -555,6 +595,7 @@ cos(const quantity& theta) /// sin of theta in radians template +BOOST_CONSTEXPR typename dimensionless_quantity::type sin(const quantity& theta) { @@ -564,6 +605,7 @@ sin(const quantity& theta) /// tan of theta in radians template +BOOST_CONSTEXPR typename dimensionless_quantity::type tan(const quantity& theta) { @@ -573,6 +615,7 @@ tan(const quantity& theta) /// cos of theta in other angular units template +BOOST_CONSTEXPR typename dimensionless_quantity::type cos(const quantity,Y>& theta) { @@ -581,6 +624,7 @@ cos(const quantity,Y>& theta) /// sin of theta in other angular units template +BOOST_CONSTEXPR typename dimensionless_quantity::type sin(const quantity,Y>& theta) { @@ -589,6 +633,7 @@ sin(const quantity,Y>& theta) /// tan of theta in other angular units template +BOOST_CONSTEXPR typename dimensionless_quantity::type tan(const quantity,Y>& theta) { @@ -597,6 +642,7 @@ tan(const quantity,Y>& theta) /// acos of dimensionless quantity returning angle in same system template +BOOST_CONSTEXPR quantity >,Y> acos(const quantity >,Y>& val) { @@ -606,6 +652,7 @@ acos(const quantity >,Y>& va /// acos of dimensionless quantity returning angle in radians template +BOOST_CONSTEXPR quantity acos(const quantity,Y>& val) { @@ -615,6 +662,7 @@ acos(const quantity /// asin of dimensionless quantity returning angle in same system template +BOOST_CONSTEXPR quantity >,Y> asin(const quantity >,Y>& val) { @@ -624,6 +672,7 @@ asin(const quantity >,Y>& va /// asin of dimensionless quantity returning angle in radians template +BOOST_CONSTEXPR quantity asin(const quantity,Y>& val) { @@ -633,6 +682,7 @@ asin(const quantity /// atan of dimensionless quantity returning angle in same system template +BOOST_CONSTEXPR quantity >,Y> atan(const quantity >, Y>& val) { @@ -642,6 +692,7 @@ atan(const quantity >, Y>& v /// atan of dimensionless quantity returning angle in radians template +BOOST_CONSTEXPR quantity atan(const quantity, Y>& val) { @@ -651,6 +702,7 @@ atan(const quantity /// atan2 of @c value_type returning angle in radians template +BOOST_CONSTEXPR quantity >, Y> atan2(const quantity >, Y>& y, const quantity >, Y>& x) @@ -661,6 +713,7 @@ atan2(const quantity >, Y>& y, /// atan2 of @c value_type returning angle in radians template +BOOST_CONSTEXPR quantity atan2(const quantity >, Y>& y, const quantity >, Y>& x) diff --git a/include/boost/units/config.hpp b/include/boost/units/config.hpp index 694abd5a..64e9025c 100644 --- a/include/boost/units/config.hpp +++ b/include/boost/units/config.hpp @@ -75,7 +75,7 @@ #define BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(a, b) BOOST_STATIC_ASSERT((sizeof(a) == sizeof(b))) #else ///INTERNAL ONLY - #define BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(a, b) ((void)0) + #define BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(a, b) #endif #ifdef BOOST_UNITS_DOXYGEN diff --git a/include/boost/units/conversion.hpp b/include/boost/units/conversion.hpp index 2e5d4db6..ab02e5bf 100644 --- a/include/boost/units/conversion.hpp +++ b/include/boost/units/conversion.hpp @@ -51,7 +51,7 @@ struct conversion_helper; template struct conversion_helper { - static To convert(const From&); + static BOOST_CONSTEXPR To convert(const From&); }; #endif @@ -77,9 +77,9 @@ struct conversion_helper template<> \ struct base_unit_converter::type> \ { \ - static const bool is_defined = true; \ + BOOST_STATIC_CONSTEXPR bool is_defined = true; \ typedef type_ type; \ - static type value() { return(value_); } \ + static BOOST_CONSTEXPR type value() { return(value_); } \ }; \ } \ } \ @@ -103,9 +103,9 @@ struct conversion_helper BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(Destination, typename Source::dimension_type)\ > \ { \ - static const bool is_defined = true; \ + BOOST_STATIC_CONSTEXPR bool is_defined = true; \ typedef type_ type; \ - static type value() { return(value_); } \ + static BOOST_CONSTEXPR type value() { return(value_); } \ }; \ } \ } \ @@ -121,7 +121,7 @@ struct conversion_helper template<> \ struct unscaled_get_default_conversion::type> \ { \ - static const bool is_defined = true; \ + BOOST_STATIC_CONSTEXPR bool is_defined = true; \ typedef Dest::unit_type type; \ }; \ } \ @@ -140,7 +140,7 @@ struct conversion_helper template \ struct unscaled_get_default_conversion \ { \ - static const bool is_defined = true; \ + BOOST_STATIC_CONSTEXPR bool is_defined = true; \ typedef typename Dest::unit_type type; \ }; \ } \ @@ -170,6 +170,7 @@ BOOST_UNITS_DEFAULT_CONVERSION(namespace_::name_ ## _base_unit, unit) /// Find the conversion factor between two units. template inline +BOOST_CONSTEXPR typename one_to_double_type< typename detail::conversion_factor_helper::type >::type diff --git a/include/boost/units/detail/absolute_impl.hpp b/include/boost/units/detail/absolute_impl.hpp index 127b33a7..ffd8b215 100644 --- a/include/boost/units/detail/absolute_impl.hpp +++ b/include/boost/units/detail/absolute_impl.hpp @@ -32,7 +32,7 @@ struct reduce_unit > > namespace detail { struct undefined_affine_conversion_base { - static const bool is_defined = false; + BOOST_STATIC_CONSTEXPR bool is_defined = false; }; } // namespace detail @@ -51,7 +51,7 @@ struct affine_conversion_impl { template struct apply { - static T1 value(const T0& t0) + static BOOST_CONSTEXPR T1 value(const T0& t0) { return( t0 * @@ -67,7 +67,7 @@ struct affine_conversion_impl template struct apply { - static T1 value(const T0& t0) + static BOOST_CONSTEXPR T1 value(const T0& t0) { return( (t0 - affine_conversion_helper::type, typename reduce_unit::type>::value()) * @@ -84,7 +84,7 @@ struct conversion_helper, T1>, quantity { typedef quantity, T1> from_quantity_type; typedef quantity, T2> to_quantity_type; - static to_quantity_type convert(const from_quantity_type& source) + static BOOST_CONSTEXPR to_quantity_type convert(const from_quantity_type& source) { return( to_quantity_type::from_value( diff --git a/include/boost/units/detail/conversion_impl.hpp b/include/boost/units/detail/conversion_impl.hpp index 8946faf5..f3cc1957 100644 --- a/include/boost/units/detail/conversion_impl.hpp +++ b/include/boost/units/detail/conversion_impl.hpp @@ -46,12 +46,12 @@ struct call_base_unit_converter; /// INTERNAL ONLY struct undefined_base_unit_converter_base { - static const bool is_defined = false; + BOOST_STATIC_CONSTEXPR bool is_defined = false; }; /// INTERNAL ONLY struct no_default_conversion { - static const bool is_defined = false; + BOOST_STATIC_CONSTEXPR bool is_defined = false; }; /// INTERNAL ONLY @@ -110,11 +110,10 @@ struct base_unit_converter_base : undefined_base_unit_converter_base { template struct base_unit_converter_base { - static const bool is_defined = true; + BOOST_STATIC_CONSTEXPR bool is_defined = true; typedef one type; - static type value() { - one result; - return(result); + static BOOST_CONSTEXPR type value() { + return(one()); } }; @@ -135,7 +134,7 @@ struct do_call_base_unit_converter { typedef typename mpl::divides::type factor; typedef eval_scale_list eval_factor; typedef typename multiply_typeof_helper::type type; - static type value() + static BOOST_CONSTEXPR type value() { return(converter::value() * eval_factor::value()); } @@ -172,9 +171,8 @@ struct call_base_unit_converter_base_unit_impl { typedef do_call_base_unit_converter converter; typedef typename divide_typeof_helper::type type; - static type value() { - one numerator; - return(numerator / converter::value()); + static BOOST_CONSTEXPR type value() { + return(one() / converter::value()); } }; }; @@ -200,7 +198,7 @@ struct call_base_unit_converter_base_unit_impl >::type, typename end::type >::type type; - static type value() { + static BOOST_CONSTEXPR type value() { return(start::value() * conversion::value() / end::value()); } }; @@ -220,7 +218,7 @@ struct get_default_conversion_impl typedef typename multiply_typeof_helper::type, typename next_iteration::unit_type>::type unit_type; typedef call_base_unit_converter conversion; typedef typename multiply_typeof_helper::type type; - static type value() { + static BOOST_CONSTEXPR type value() { return(static_rational_power(conversion::value()) * next_iteration::value()); } }; @@ -234,9 +232,8 @@ struct get_default_conversion_impl<0> { typedef unit > > unit_type; typedef one type; - static one value() { - one result; - return(result); + static BOOST_CONSTEXPR one value() { + return(one()); } }; }; @@ -272,7 +269,7 @@ struct call_base_unit_converter_impl >::type, typename impl::type >::type type; - static type value() { + static BOOST_CONSTEXPR type value() { return(start::value() * conversion::value() / impl::value()); } }; @@ -314,7 +311,7 @@ struct conversion_impl typedef typename reduce_unit >::type reduced_unit; typedef detail::call_base_unit_converter converter; typedef typename multiply_typeof_helper::type type; - static type value() { return(static_rational_power(converter::value()) * next_iteration::value()); } + static BOOST_CONSTEXPR type value() { return(static_rational_power(converter::value()) * next_iteration::value()); } }; }; @@ -325,7 +322,7 @@ struct conversion_impl<0> struct apply { typedef one type; - static type value() { one result; return(result); } + static BOOST_CONSTEXPR type value() { return(one()); } }; }; @@ -338,11 +335,9 @@ struct conversion_helper, quantity > { /// INTERNAL ONLY typedef quantity destination_type; - static destination_type convert(const quantity& source) + static BOOST_CONSTEXPR destination_type convert(const quantity& source) { - Unit1 u1; - Unit2 u2; - return(destination_type::from_value(static_cast(source.value() * conversion_factor(u1, u2)))); + return(destination_type::from_value(static_cast(source.value() * conversion_factor(Unit1(), Unit2())))); } }; @@ -365,7 +360,7 @@ struct conversion_factor_helper >, unit //> impl; //typedef typename impl::type type; - //static type value() + //static BOOST_CONSTEXPR type value() //{ // return(impl::value()); //} @@ -384,7 +379,7 @@ struct conversion_factor_helper >, unit impl; //typedef eval_scale_list scale; //typedef typename multiply_typeof_helper::type type; - //static type value() + //static BOOST_CONSTEXPR type value() //{ // return(impl::value() * scale::value()); //} @@ -406,10 +401,9 @@ struct conversion_factor_helper >, unit impl; //typedef eval_scale_list scale; //typedef typename multiply_typeof_helper::type type; - //static type value() + //static BOOST_CONSTEXPR type value() //{ - // one numerator; - // return(numerator / (impl::value() * scale::value())); + // return(one() / (impl::value() * scale::value())); //} }; @@ -443,7 +437,7 @@ struct conversion_factor_helper >, unit::type >::type type; - static type value() + static BOOST_CONSTEXPR type value() { return(conversion1::value() * (scale::value() / conversion2::value())); } diff --git a/include/boost/units/detail/linear_algebra.hpp b/include/boost/units/detail/linear_algebra.hpp index 96b27a25..17ed34bd 100644 --- a/include/boost/units/detail/linear_algebra.hpp +++ b/include/boost/units/detail/linear_algebra.hpp @@ -598,8 +598,8 @@ struct set_insert { template struct has_key { - static const long size = sizeof(Set::lookup((wrap*)0)); - static const bool value = (size == sizeof(set_yes)); + BOOST_STATIC_CONSTEXPR long size = sizeof(Set::lookup((wrap*)0)); + BOOST_STATIC_CONSTEXPR bool value = (size == sizeof(set_yes)); }; template @@ -826,7 +826,7 @@ struct normalize_units { dimensions >::type matrix; typedef typename make_square_and_invert::type type; - static const long extra = (type::size::value) - (T::size::value); + BOOST_STATIC_CONSTEXPR long extra = (type::size::value) - (T::size::value); }; // multiply_add_units computes M x V @@ -977,7 +977,7 @@ struct is_simple_system_impl { typename test::base_dimension_type > > type; - static const bool value = (type::value); + BOOST_STATIC_CONSTEXPR bool value = (type::value); }; }; @@ -1001,7 +1001,7 @@ struct is_simple_system { typename test::base_dimension_type > >::type type; - static const bool value = type::value; + BOOST_STATIC_CONSTEXPR bool value = type::value; }; template diff --git a/include/boost/units/detail/one.hpp b/include/boost/units/detail/one.hpp index bf1cad90..1643e6a6 100644 --- a/include/boost/units/detail/one.hpp +++ b/include/boost/units/detail/one.hpp @@ -17,12 +17,11 @@ namespace boost { namespace units { -struct one { one() {} }; +struct one { BOOST_CONSTEXPR one() {} }; // workaround for pathscale. -inline one make_one() { - one result; - return(result); +inline BOOST_CONSTEXPR one make_one() { + return(one()); } template @@ -44,21 +43,20 @@ struct multiply_typeof_helper }; template -inline T operator*(const one&, const T& t) +inline BOOST_CONSTEXPR T operator*(const one&, const T& t) { return(t); } template -inline T operator*(const T& t, const one&) +inline BOOST_CONSTEXPR T operator*(const T& t, const one&) { return(t); } -inline one operator*(const one&, const one&) +inline BOOST_CONSTEXPR one operator*(const one&, const one&) { - one result; - return(result); + return(one()); } template @@ -80,32 +78,31 @@ struct divide_typeof_helper }; template -inline T operator/(const T& t, const one&) +inline BOOST_CONSTEXPR T operator/(const T& t, const one&) { return(t); } template -inline T operator/(const one&, const T& t) +inline BOOST_CONSTEXPR T operator/(const one&, const T& t) { return(1/t); } -inline one operator/(const one&, const one&) +inline BOOST_CONSTEXPR one operator/(const one&, const one&) { - one result; - return(result); + return(one()); } template -inline bool operator>(const boost::units::one&, const T& t) { +inline BOOST_CONSTEXPR bool operator>(const boost::units::one&, const T& t) { return(1 > t); } template -T one_to_double(const T& t) { return t; } +BOOST_CONSTEXPR T one_to_double(const T& t) { return t; } -inline double one_to_double(const one&) { return 1.0; } +inline BOOST_CONSTEXPR double one_to_double(const one&) { return 1.0; } template struct one_to_double_type { typedef T type; }; diff --git a/include/boost/units/detail/ordinal.hpp b/include/boost/units/detail/ordinal.hpp index b47ef674..eaf5bde3 100644 --- a/include/boost/units/detail/ordinal.hpp +++ b/include/boost/units/detail/ordinal.hpp @@ -26,11 +26,11 @@ struct ordinal_tag {}; template struct ordinal { typedef detail::ordinal_tag tag; - static const long value = N; + BOOST_STATIC_CONSTEXPR long value = N; }; template -const long ordinal::value; +BOOST_CONSTEXPR_OR_CONST long ordinal::value; } diff --git a/include/boost/units/detail/prevent_redefinition.hpp b/include/boost/units/detail/prevent_redefinition.hpp index fba969ae..1f235753 100644 --- a/include/boost/units/detail/prevent_redefinition.hpp +++ b/include/boost/units/detail/prevent_redefinition.hpp @@ -19,7 +19,7 @@ namespace units { namespace detail { -struct no { no() {} char dummy; }; +struct no { BOOST_CONSTEXPR no() : dummy() {} char dummy; }; struct yes { no dummy[2]; }; template struct ordinal_has_already_been_defined; @@ -37,15 +37,17 @@ struct ordinal_has_already_been_defined { typedef void type; }; /// be found by ADL /// INTERNAL ONLY template +BOOST_CONSTEXPR detail::no boost_units_is_registered(const T&) -{ detail::no result; return(result); } +{ return(detail::no()); } /// INTERNAL ONLY template +BOOST_CONSTEXPR detail::no boost_units_unit_is_registered(const T&) -{ detail::no result; return(result); } +{ return(detail::no()); } } // namespace units diff --git a/include/boost/units/detail/static_rational_power.hpp b/include/boost/units/detail/static_rational_power.hpp index 66c9d9d0..e8e62c75 100644 --- a/include/boost/units/detail/static_rational_power.hpp +++ b/include/boost/units/detail/static_rational_power.hpp @@ -50,7 +50,7 @@ template struct static_rational_power_impl { typedef typename typeof_pow_adl_barrier::typeof_pow::type type; - static type call(const Y& y) + static BOOST_CONSTEXPR type call(const Y& y) { using std::pow; return(pow(y, static_cast(R::Numerator) / static_cast(R::Denominator))); @@ -61,10 +61,9 @@ template struct static_rational_power_impl { typedef one type; - static one call(const one&) + static BOOST_CONSTEXPR one call(const one&) { - one result; - return(result); + return(one()); } }; @@ -72,10 +71,9 @@ template struct static_rational_power_impl, one> { typedef one type; - static one call(const one&) + static BOOST_CONSTEXPR one call(const one&) { - one result; - return(result); + return(one()); } }; @@ -91,10 +89,9 @@ struct static_int_power_impl typedef typename multiply_typeof_helper::type square_type; typedef typename static_int_power_impl<(N >> 1)>::template apply next; typedef typename next::type type; - static type call(const Y& y, const R& r) + static BOOST_CONSTEXPR type call(const Y& y, const R& r) { - const square_type square = y * y; - return(next::call(square, r)); + return(next::call(static_cast(y * y), r)); } }; }; @@ -109,10 +106,9 @@ struct static_int_power_impl typedef typename multiply_typeof_helper::type new_r; typedef typename static_int_power_impl<(N >> 1)>::template apply next; typedef typename next::type type; - static type call(const Y& y, const R& r) + static BOOST_CONSTEXPR type call(const Y& y, const R& r) { - const Y square = y * y; - return(next::call(square, y * r)); + return(next::call(static_cast(y * y), y * r)); } }; }; @@ -124,7 +120,7 @@ struct static_int_power_impl<1, false> struct apply { typedef typename multiply_typeof_helper::type type; - static type call(const Y& y, const R& r) + static BOOST_CONSTEXPR type call(const Y& y, const R& r) { return(y * r); } @@ -138,7 +134,7 @@ struct static_int_power_impl<0, true> struct apply { typedef R type; - static R call(const Y&, const R& r) + static BOOST_CONSTEXPR R call(const Y&, const R& r) { return(r); } @@ -156,10 +152,9 @@ struct static_int_power_sign_impl { typedef typename static_int_power_impl::template apply impl; typedef typename impl::type type; - static type call(const Y& y) + static BOOST_CONSTEXPR type call(const Y& y) { - one result; - return(impl::call(y, result)); + return(impl::call(y, one())); } }; }; @@ -172,10 +167,9 @@ struct static_int_power_sign_impl { typedef typename static_int_power_impl<-N>::template apply impl; typedef typename divide_typeof_helper::type type; - static type call(const Y& y) + static BOOST_CONSTEXPR type call(const Y& y) { - one result; - return(result/impl::call(y, result)); + return(one()/impl::call(y, one())); } }; }; @@ -185,13 +179,14 @@ struct static_rational_power_impl, Y> { typedef typename static_int_power_sign_impl::template apply impl; typedef typename impl::type type; - static type call(const Y& y) + static BOOST_CONSTEXPR type call(const Y& y) { return(impl::call(y)); } }; template +BOOST_CONSTEXPR typename detail::static_rational_power_impl::type static_rational_power(const Y& y) { return(detail::static_rational_power_impl::call(y)); diff --git a/include/boost/units/detail/unscale.hpp b/include/boost/units/detail/unscale.hpp index 08e51e96..b851d34b 100644 --- a/include/boost/units/detail/unscale.hpp +++ b/include/boost/units/detail/unscale.hpp @@ -143,7 +143,7 @@ struct eval_scale_list_impl { typedef typename eval_scale_list_impl::template apply next_iteration; typedef typename multiply_typeof_helper::type type; - static type value() + static BOOST_CONSTEXPR type value() { return(next_iteration::value() * Begin::item::value()); } @@ -157,10 +157,9 @@ struct eval_scale_list_impl<0> struct apply { typedef one type; - static one value() + static BOOST_CONSTEXPR one value() { - one result; - return(result); + return(one()); } }; }; diff --git a/include/boost/units/io.hpp b/include/boost/units/io.hpp index eda83556..c998e273 100644 --- a/include/boost/units/io.hpp +++ b/include/boost/units/io.hpp @@ -669,17 +669,18 @@ template struct autoprefix_norm_impl { typedef double type; - static double call(const T& arg) { return std::abs(arg); } + static BOOST_CONSTEXPR double call(const T& arg) { return std::abs(arg); } }; template struct autoprefix_norm_impl { typedef one type; - static one call(const T&) { return one(); } + static BOOST_CONSTEXPR one call(const T&) { return one(); } }; template +BOOST_CONSTEXPR typename autoprefix_norm_impl::type autoprefix_norm(const T& arg) { return autoprefix_norm_impl::call(arg); @@ -690,12 +691,14 @@ typename autoprefix_norm_impl::type autoprefix_norm(const T& arg) namespace detail { template +BOOST_CONSTEXPR bool find_matching_scale_impl(End, End, Prev, T, double, F) { return false; } template +BOOST_CXX14_CONSTEXPR bool find_matching_scale_impl(Begin, End end, Prev prev, T t, double x, F f) { if(Begin::item::value() > x) { @@ -714,12 +717,14 @@ bool find_matching_scale_impl(Begin, End end, Prev prev, T t, double x, F f) } template +BOOST_CONSTEXPR bool find_matching_scale_i(End, End, T, double, F) { return false; } template +BOOST_CXX14_CONSTEXPR bool find_matching_scale_i(Begin, End end, T t, double x, F f) { if(Begin::item::value() > x) { @@ -730,6 +735,7 @@ bool find_matching_scale_i(Begin, End end, T t, double x, F f) } template +BOOST_CXX14_CONSTEXPR bool find_matching_scale(T t, double x, F f) { return detail::find_matching_scale_i(Scales(), dimensionless_type(), t, x, f); @@ -976,8 +982,8 @@ void maybe_print_prefixed(std::basic_ostream& os, const quantity< detail::print_default(os, q)(); } -inline mpl::true_ test_norm(double) { return mpl::true_(); } -inline mpl::false_ test_norm(one) { return mpl::false_(); } +inline BOOST_CONSTEXPR mpl::true_ test_norm(double) { return mpl::true_(); } +inline BOOST_CONSTEXPR mpl::false_ test_norm(one) { return mpl::false_(); } } // namespace detail diff --git a/include/boost/units/lambda.hpp b/include/boost/units/lambda.hpp index 9014ccaa..ff14a397 100644 --- a/include/boost/units/lambda.hpp +++ b/include/boost/units/lambda.hpp @@ -69,7 +69,7 @@ namespace units { /// unit * lambda_functor /// based on \. template - inline const typename multiply_typeof_helper, boost::lambda::lambda_functor >::type + inline BOOST_CONSTEXPR_OR_CONST typename multiply_typeof_helper, boost::lambda::lambda_functor >::type operator*(const boost::units::unit& a, const boost::lambda::lambda_functor& b) { return typename multiply_typeof_helper, boost::lambda::lambda_functor >::type::inherited @@ -110,7 +110,7 @@ namespace units { /// unit / lambda_functor /// based on \. template - inline const typename divide_typeof_helper, boost::lambda::lambda_functor >::type + inline BOOST_CONSTEXPR_OR_CONST typename divide_typeof_helper, boost::lambda::lambda_functor >::type operator/(const boost::units::unit& a, const boost::lambda::lambda_functor& b) { return typename divide_typeof_helper, boost::lambda::lambda_functor >::type::inherited @@ -151,7 +151,7 @@ namespace units { /// lambda_functor * unit /// based on \. template - inline const typename multiply_typeof_helper, boost::units::unit >::type + inline BOOST_CONSTEXPR_OR_CONST typename multiply_typeof_helper, boost::units::unit >::type operator*(const boost::lambda::lambda_functor& a, const boost::units::unit& b) { return typename multiply_typeof_helper, boost::units::unit >::type::inherited @@ -192,7 +192,7 @@ namespace units { /// lambda_functor / unit /// based on \. template - inline const typename divide_typeof_helper, boost::units::unit >::type + inline BOOST_CONSTEXPR_OR_CONST typename divide_typeof_helper, boost::units::unit >::type operator/(const boost::lambda::lambda_functor& a, const boost::units::unit& b) { return typename divide_typeof_helper, boost::units::unit >::type::inherited @@ -535,7 +535,7 @@ namespace units { /// lambda_functor * absolute > /// based on \. template - inline const typename multiply_typeof_helper, boost::units::absolute > >::type + inline BOOST_CONSTEXPR_OR_CONST typename multiply_typeof_helper, boost::units::absolute > >::type operator*(const boost::lambda::lambda_functor& a, const boost::units::absolute >& b) { return typename multiply_typeof_helper, boost::units::absolute > >::type::inherited @@ -577,7 +577,7 @@ namespace units { /// absolute > * lambda_functor /// based on \. template - inline const typename multiply_typeof_helper >, boost::lambda::lambda_functor >::type + inline BOOST_CONSTEXPR_OR_CONST typename multiply_typeof_helper >, boost::lambda::lambda_functor >::type operator*(const boost::units::absolute >& a, const boost::lambda::lambda_functor& b) { return typename multiply_typeof_helper >, boost::lambda::lambda_functor >::type::inherited diff --git a/include/boost/units/limits.hpp b/include/boost/units/limits.hpp index a8b6f732..7886d692 100644 --- a/include/boost/units/limits.hpp +++ b/include/boost/units/limits.hpp @@ -28,46 +28,46 @@ class numeric_limits< ::boost::units::quantity > { public: typedef ::boost::units::quantity quantity_type; - static const bool is_specialized = std::numeric_limits::is_specialized; - static quantity_type (min)() { return(quantity_type::from_value((std::numeric_limits::min)())); } - static quantity_type (max)() { return(quantity_type::from_value((std::numeric_limits::max)())); } + BOOST_STATIC_CONSTEXPR bool is_specialized = std::numeric_limits::is_specialized; + static BOOST_CONSTEXPR quantity_type (min)() { return(quantity_type::from_value((std::numeric_limits::min)())); } + static BOOST_CONSTEXPR quantity_type (max)() { return(quantity_type::from_value((std::numeric_limits::max)())); } #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS - static quantity_type (lowest)() { return(quantity_type::from_value((std::numeric_limits::lowest)())); } + static BOOST_CONSTEXPR quantity_type (lowest)() { return(quantity_type::from_value((std::numeric_limits::lowest)())); } #endif - static const int digits = std::numeric_limits::digits; - static const int digits10 = std::numeric_limits::digits10; + BOOST_STATIC_CONSTEXPR int digits = std::numeric_limits::digits; + BOOST_STATIC_CONSTEXPR int digits10 = std::numeric_limits::digits10; #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS - static const int max_digits10 = std::numeric_limits::max_digits10; + BOOST_STATIC_CONSTEXPR int max_digits10 = std::numeric_limits::max_digits10; #endif - static const bool is_signed = std::numeric_limits::is_signed; - static const bool is_integer = std::numeric_limits::is_integer; - static const bool is_exact = std::numeric_limits::is_exact; - static const int radix = std::numeric_limits::radix; - static quantity_type epsilon() { return(quantity_type::from_value(std::numeric_limits::epsilon())); } - static quantity_type round_error() { return(quantity_type::from_value(std::numeric_limits::round_error())); } - static const int min_exponent = std::numeric_limits::min_exponent; - static const int min_exponent10 = std::numeric_limits::min_exponent10; - static const int max_exponent = std::numeric_limits::max_exponent; - static const int max_exponent10 = std::numeric_limits::max_exponent10; - static const bool has_infinity = std::numeric_limits::has_infinity; - static const bool has_quiet_NaN = std::numeric_limits::has_quiet_NaN; - static const bool has_signaling_NaN = std::numeric_limits::has_signaling_NaN; - static const bool has_denorm_loss = std::numeric_limits::has_denorm_loss; - static quantity_type infinity() { return(quantity_type::from_value(std::numeric_limits::infinity())); } - static quantity_type quiet_NaN() { return(quantity_type::from_value(std::numeric_limits::quiet_NaN())); } - static quantity_type signaling_NaN() { return(quantity_type::from_value(std::numeric_limits::signaling_NaN())); } - static quantity_type denorm_min() { return(quantity_type::from_value(std::numeric_limits::denorm_min())); } - static const bool is_iec559 = std::numeric_limits::is_iec559; - static const bool is_bounded = std::numeric_limits::is_bounded; - static const bool is_modulo = std::numeric_limits::is_modulo; - static const bool traps = std::numeric_limits::traps; - static const bool tinyness_before = std::numeric_limits::tinyness_before; + BOOST_STATIC_CONSTEXPR bool is_signed = std::numeric_limits::is_signed; + BOOST_STATIC_CONSTEXPR bool is_integer = std::numeric_limits::is_integer; + BOOST_STATIC_CONSTEXPR bool is_exact = std::numeric_limits::is_exact; + BOOST_STATIC_CONSTEXPR int radix = std::numeric_limits::radix; + static BOOST_CONSTEXPR quantity_type epsilon() { return(quantity_type::from_value(std::numeric_limits::epsilon())); } + static BOOST_CONSTEXPR quantity_type round_error() { return(quantity_type::from_value(std::numeric_limits::round_error())); } + BOOST_STATIC_CONSTEXPR int min_exponent = std::numeric_limits::min_exponent; + BOOST_STATIC_CONSTEXPR int min_exponent10 = std::numeric_limits::min_exponent10; + BOOST_STATIC_CONSTEXPR int max_exponent = std::numeric_limits::max_exponent; + BOOST_STATIC_CONSTEXPR int max_exponent10 = std::numeric_limits::max_exponent10; + BOOST_STATIC_CONSTEXPR bool has_infinity = std::numeric_limits::has_infinity; + BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = std::numeric_limits::has_quiet_NaN; + BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = std::numeric_limits::has_signaling_NaN; + BOOST_STATIC_CONSTEXPR bool has_denorm_loss = std::numeric_limits::has_denorm_loss; + static BOOST_CONSTEXPR quantity_type infinity() { return(quantity_type::from_value(std::numeric_limits::infinity())); } + static BOOST_CONSTEXPR quantity_type quiet_NaN() { return(quantity_type::from_value(std::numeric_limits::quiet_NaN())); } + static BOOST_CONSTEXPR quantity_type signaling_NaN() { return(quantity_type::from_value(std::numeric_limits::signaling_NaN())); } + static BOOST_CONSTEXPR quantity_type denorm_min() { return(quantity_type::from_value(std::numeric_limits::denorm_min())); } + BOOST_STATIC_CONSTEXPR bool is_iec559 = std::numeric_limits::is_iec559; + BOOST_STATIC_CONSTEXPR bool is_bounded = std::numeric_limits::is_bounded; + BOOST_STATIC_CONSTEXPR bool is_modulo = std::numeric_limits::is_modulo; + BOOST_STATIC_CONSTEXPR bool traps = std::numeric_limits::traps; + BOOST_STATIC_CONSTEXPR bool tinyness_before = std::numeric_limits::tinyness_before; #if defined(_STLP_STATIC_CONST_INIT_BUG) - static const int has_denorm = std::numeric_limits::has_denorm; - static const int round_style = std::numeric_limits::round_style; + BOOST_STATIC_CONSTEXPR int has_denorm = std::numeric_limits::has_denorm; + BOOST_STATIC_CONSTEXPR int round_style = std::numeric_limits::round_style; #else - static const float_denorm_style has_denorm = std::numeric_limits::has_denorm; - static const float_round_style round_style = std::numeric_limits::round_style; + BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = std::numeric_limits::has_denorm; + BOOST_STATIC_CONSTEXPR float_round_style round_style = std::numeric_limits::round_style; #endif }; diff --git a/include/boost/units/operators.hpp b/include/boost/units/operators.hpp index 19b8aace..6941aaff 100644 --- a/include/boost/units/operators.hpp +++ b/include/boost/units/operators.hpp @@ -135,7 +135,7 @@ struct power_typeof_helper /// specifies the result type typedef detail::unspecified type; /// Carries out the runtime calculation. - static type value(const BaseType& base); + static BOOST_CONSTEXPR type value(const BaseType& base); }; /// A helper used by @c root to take a root @@ -152,7 +152,7 @@ struct root_typeof_helper /// specifies the result type typedef detail::unspecified type; /// Carries out the runtime calculation. - static type value(const Radicand& base); + static BOOST_CONSTEXPR type value(const Radicand& base); }; #endif diff --git a/include/boost/units/pow.hpp b/include/boost/units/pow.hpp index 1d856a53..6b0e69c4 100644 --- a/include/boost/units/pow.hpp +++ b/include/boost/units/pow.hpp @@ -27,6 +27,7 @@ namespace units { /// raise a value to a @c static_rational power. template +BOOST_CONSTEXPR inline typename power_typeof_helper::type pow(const Y& x) { @@ -35,6 +36,7 @@ pow(const Y& x) /// raise a value to an integer power. template +BOOST_CONSTEXPR inline typename power_typeof_helper >::type pow(const Y& x) { @@ -51,7 +53,7 @@ struct power_typeof_helper > typedef detail::static_rational_power_impl, internal_type> impl; typedef typename impl::type type; - static type value(const T& x) + static BOOST_CONSTEXPR type value(const T& x) { return impl::call(x); } @@ -64,7 +66,7 @@ struct power_typeof_helper > // N.B. pathscale doesn't accept inheritance for some reason. typedef power_typeof_helper > base; typedef typename base::type type; - static type value(const double& x) + static BOOST_CONSTEXPR type value(const double& x) { return base::value(x); } @@ -74,6 +76,7 @@ struct power_typeof_helper > /// take the @c static_rational root of a value. template +BOOST_CONSTEXPR typename root_typeof_helper::type root(const Y& x) { @@ -82,6 +85,7 @@ root(const Y& x) /// take the integer root of a value. template +BOOST_CONSTEXPR typename root_typeof_helper >::type root(const Y& x) { @@ -97,7 +101,7 @@ struct root_typeof_helper > // N.B. pathscale doesn't accept inheritance for some reason. typedef power_typeof_helper > base; typedef typename base::type type; - static type value(const T& x) + static BOOST_CONSTEXPR type value(const T& x) { return(base::value(x)); } diff --git a/include/boost/units/quantity.hpp b/include/boost/units/quantity.hpp index 7bdb78ef..c6ae6e73 100644 --- a/include/boost/units/quantity.hpp +++ b/include/boost/units/quantity.hpp @@ -98,17 +98,17 @@ class quantity typedef Y value_type; typedef Unit unit_type; - quantity() : val_() + BOOST_CONSTEXPR quantity() : val_() { BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y); } - quantity(unspecified_null_pointer_constant_type) : val_() + BOOST_CONSTEXPR quantity(unspecified_null_pointer_constant_type) : val_() { BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y); } - quantity(const this_type& source) : val_(source.val_) + BOOST_CONSTEXPR quantity(const this_type& source) : val_(source.val_) { BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y); } @@ -124,7 +124,7 @@ class quantity //~quantity() { } - this_type& operator=(const this_type& source) + BOOST_CXX14_CONSTEXPR this_type& operator=(const this_type& source) { val_ = source.val_; @@ -135,7 +135,7 @@ class quantity /// implicit conversion between value types is allowed if allowed for value types themselves template - quantity(const quantity& source, + BOOST_CONSTEXPR quantity(const quantity& source, typename boost::enable_if >::type* = 0) : val_(source.value()) { @@ -144,7 +144,7 @@ class quantity /// implicit conversion between value types is not allowed if not allowed for value types themselves template - explicit quantity(const quantity& source, + explicit BOOST_CONSTEXPR quantity(const quantity& source, typename boost::disable_if >::type* = 0) : val_(static_cast(source.value())) { @@ -155,7 +155,7 @@ class quantity /// implicit conversion between value types is allowed if allowed for value types themselves template - quantity(const quantity& source) : + BOOST_CONSTEXPR quantity(const quantity& source) : val_(source.value()) { BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y); @@ -166,7 +166,7 @@ class quantity /// implicit assignment between value types is allowed if allowed for value types themselves template - this_type& operator=(const quantity& source) + BOOST_CXX14_CONSTEXPR this_type& operator=(const quantity& source) { BOOST_STATIC_ASSERT((boost::is_convertible::value == true)); @@ -180,7 +180,7 @@ class quantity /// explicit conversion between different unit systems is allowed if implicit conversion is disallowed template explicit - quantity(const quantity& source, + BOOST_CONSTEXPR quantity(const quantity& source, typename boost::disable_if< mpl::and_< //is_implicitly_convertible should be undefined when the @@ -198,7 +198,7 @@ class quantity /// implicit conversion between different unit systems is allowed if each fundamental dimension is implicitly convertible template - quantity(const quantity& source, + BOOST_CONSTEXPR quantity(const quantity& source, typename boost::enable_if< mpl::and_< typename is_implicitly_convertible::type, @@ -217,7 +217,7 @@ class quantity /// without SFINAE we can't distinguish between explicit and implicit conversions so /// the conversion is always explicit template - explicit quantity(const quantity& source) + explicit BOOST_CONSTEXPR quantity(const quantity& source) : val_(conversion_helper,this_type>::convert(source).value()) { BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y); @@ -228,7 +228,7 @@ class quantity /// implicit assignment between different unit systems is allowed if each fundamental dimension is implicitly convertible template - this_type& operator=(const quantity& source) + BOOST_CXX14_CONSTEXPR this_type& operator=(const quantity& source) { BOOST_STATIC_ASSERT((is_implicitly_convertible::value == true)); @@ -239,11 +239,11 @@ class quantity return *this; } - const value_type& value() const { return val_; } ///< constant accessor to value + BOOST_CONSTEXPR const value_type& value() const { return val_; } ///< constant accessor to value ///< can add a quantity of the same type if add_typeof_helper::type is convertible to value_type template - this_type& operator+=(const quantity& source) + BOOST_CXX14_CONSTEXPR this_type& operator+=(const quantity& source) { BOOST_STATIC_ASSERT((boost::is_same::type, Unit>::value)); val_ += source.value(); @@ -252,7 +252,7 @@ class quantity ///< can subtract a quantity of the same type if subtract_typeof_helper::type is convertible to value_type template - this_type& operator-=(const quantity& source) + BOOST_CXX14_CONSTEXPR this_type& operator-=(const quantity& source) { BOOST_STATIC_ASSERT((boost::is_same::type, Unit>::value)); val_ -= source.value(); @@ -260,7 +260,7 @@ class quantity } template - this_type& operator*=(const quantity& source) + BOOST_CXX14_CONSTEXPR this_type& operator*=(const quantity& source) { BOOST_STATIC_ASSERT((boost::is_same::type, Unit>::value)); val_ *= source.value(); @@ -268,7 +268,7 @@ class quantity } template - this_type& operator/=(const quantity& source) + BOOST_CXX14_CONSTEXPR this_type& operator/=(const quantity& source) { BOOST_STATIC_ASSERT((boost::is_same::type, Unit>::value)); val_ /= source.value(); @@ -276,15 +276,15 @@ class quantity } ///< can multiply a quantity by a scalar value_type if multiply_typeof_helper::type is convertible to value_type - this_type& operator*=(const value_type& source) { val_ *= source; return *this; } + BOOST_CXX14_CONSTEXPR this_type& operator*=(const value_type& source) { val_ *= source; return *this; } ///< can divide a quantity by a scalar value_type if divide_typeof_helper::type is convertible to value_type - this_type& operator/=(const value_type& source) { val_ /= source; return *this; } + BOOST_CXX14_CONSTEXPR this_type& operator/=(const value_type& source) { val_ /= source; return *this; } /// Construct quantity directly from @c value_type (potentially dangerous). - static this_type from_value(const value_type& val) { return this_type(val, 0); } + static BOOST_CONSTEXPR this_type from_value(const value_type& val) { return this_type(val, 0); } protected: - explicit quantity(const value_type& val, int) : val_(val) { } + explicit BOOST_CONSTEXPR quantity(const value_type& val, int) : val_(val) { } private: value_type val_; @@ -305,25 +305,25 @@ class quantity typedef dimensionless_type dimension_type; typedef unit unit_type; - quantity() : val_() + BOOST_CONSTEXPR quantity() : val_() { BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y); } /// construction from raw @c value_type is allowed - quantity(value_type val) : val_(val) + BOOST_CONSTEXPR quantity(value_type val) : val_(val) { BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y); } - quantity(const this_type& source) : val_(source.val_) + BOOST_CONSTEXPR quantity(const this_type& source) : val_(source.val_) { BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y); } //~quantity() { } - this_type& operator=(const this_type& source) + BOOST_CXX14_CONSTEXPR this_type& operator=(const this_type& source) { val_ = source.val_; @@ -334,7 +334,7 @@ class quantity /// implicit conversion between value types is allowed if allowed for value types themselves template - quantity(const quantity,YY>& source, + BOOST_CONSTEXPR quantity(const quantity,YY>& source, typename boost::enable_if >::type* = 0) : val_(source.value()) { @@ -343,7 +343,7 @@ class quantity /// implicit conversion between value types is not allowed if not allowed for value types themselves template - explicit quantity(const quantity,YY>& source, + explicit BOOST_CONSTEXPR quantity(const quantity,YY>& source, typename boost::disable_if >::type* = 0) : val_(static_cast(source.value())) { @@ -354,7 +354,7 @@ class quantity /// implicit conversion between value types is allowed if allowed for value types themselves template - quantity(const quantity,YY>& source) : + BOOST_CONSTEXPR quantity(const quantity,YY>& source) : val_(source.value()) { BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y); @@ -365,7 +365,7 @@ class quantity /// implicit assignment between value types is allowed if allowed for value types themselves template - this_type& operator=(const quantity,YY>& source) + BOOST_CXX14_CONSTEXPR this_type& operator=(const quantity,YY>& source) { BOOST_STATIC_ASSERT((boost::is_convertible::value == true)); @@ -378,7 +378,7 @@ class quantity /// implicit conversion between different unit systems is allowed template - quantity(const quantity,Y2>& source, + BOOST_CONSTEXPR quantity(const quantity,Y2>& source, #ifdef __SUNPRO_CC typename boost::enable_if< boost::mpl::and_< @@ -399,7 +399,7 @@ class quantity /// implicit conversion between different unit systems is allowed template - explicit quantity(const quantity,Y2>& source, + explicit BOOST_CONSTEXPR quantity(const quantity,Y2>& source, #ifdef __SUNPRO_CC typename boost::enable_if< boost::mpl::and_< @@ -422,7 +422,7 @@ class quantity /// implicit conversion between different unit systems is allowed template - quantity(const quantity >,Y2>& source) : + BOOST_CONSTEXPR quantity(const quantity >,Y2>& source) : val_(source.value()) { BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y); @@ -434,7 +434,7 @@ class quantity /// conversion between different unit systems is explicit when /// the units are not equivalent. template - explicit quantity(const quantity,Y2>& source, + explicit BOOST_CONSTEXPR quantity(const quantity,Y2>& source, typename boost::disable_if >::type* = 0) : val_(conversion_helper,Y2>, this_type>::convert(source).value()) { @@ -445,7 +445,7 @@ class quantity /// implicit assignment between different unit systems is allowed template - this_type& operator=(const quantity& source) + BOOST_CXX14_CONSTEXPR this_type& operator=(const quantity& source) { *this = this_type(source); @@ -455,24 +455,24 @@ class quantity #endif /// implicit conversion to @c value_type is allowed - operator value_type() const { return val_; } + BOOST_CONSTEXPR operator value_type() const { return val_; } - const value_type& value() const { return val_; } ///< constant accessor to value + BOOST_CONSTEXPR const value_type& value() const { return val_; } ///< constant accessor to value ///< can add a quantity of the same type if add_typeof_helper::type is convertible to value_type - this_type& operator+=(const this_type& source) { val_ += source.val_; return *this; } + BOOST_CXX14_CONSTEXPR this_type& operator+=(const this_type& source) { val_ += source.val_; return *this; } ///< can subtract a quantity of the same type if subtract_typeof_helper::type is convertible to value_type - this_type& operator-=(const this_type& source) { val_ -= source.val_; return *this; } + BOOST_CXX14_CONSTEXPR this_type& operator-=(const this_type& source) { val_ -= source.val_; return *this; } ///< can multiply a quantity by a scalar value_type if multiply_typeof_helper::type is convertible to value_type - this_type& operator*=(const value_type& val) { val_ *= val; return *this; } + BOOST_CXX14_CONSTEXPR this_type& operator*=(const value_type& val) { val_ *= val; return *this; } ///< can divide a quantity by a scalar value_type if divide_typeof_helper::type is convertible to value_type - this_type& operator/=(const value_type& val) { val_ /= val; return *this; } + BOOST_CXX14_CONSTEXPR this_type& operator/=(const value_type& val) { val_ /= val; return *this; } /// Construct quantity directly from @c value_type. - static this_type from_value(const value_type& val) { return this_type(val); } + static BOOST_CONSTEXPR this_type from_value(const value_type& val) { return this_type(val); } private: value_type val_; @@ -513,7 +513,7 @@ struct quantity_cast_helper > { typedef Y type; - type operator()(quantity& source) { return const_cast(source.value()); } + BOOST_CONSTEXPR type operator()(quantity& source) const { return const_cast(source.value()); } }; /// specialization for casting to the value type @@ -522,7 +522,7 @@ struct quantity_cast_helper > { typedef Y type; - type operator()(const quantity& source) { return source.value(); } + BOOST_CONSTEXPR type operator()(const quantity& source) const { return source.value(); } }; } // namespace detail @@ -530,22 +530,20 @@ struct quantity_cast_helper > /// quantity_cast provides mutating access to underlying quantity value_type template inline +BOOST_CONSTEXPR X quantity_cast(Y& source) { - detail::quantity_cast_helper qch; - - return qch(source); + return detail::quantity_cast_helper()(source); } template inline +BOOST_CONSTEXPR X quantity_cast(const Y& source) { - detail::quantity_cast_helper qch; - - return qch(source); + return detail::quantity_cast_helper()(source); } /// swap quantities @@ -863,7 +861,7 @@ struct power_typeof_helper< quantity,static_rational > typedef typename power_typeof_helper >::type unit_type; typedef quantity type; - static type value(const quantity& x) + static BOOST_CONSTEXPR type value(const quantity& x) { return type::from_value(power_typeof_helper >::value(x.value())); } @@ -878,7 +876,7 @@ struct root_typeof_helper< quantity,static_rational > typedef typename root_typeof_helper >::type unit_type; typedef quantity type; - static type value(const quantity& x) + static BOOST_CONSTEXPR type value(const quantity& x) { return type::from_value(root_typeof_helper >::value(x.value())); } @@ -890,6 +888,7 @@ template inline +BOOST_CONSTEXPR typename multiply_typeof_helper< unit,Y >::type operator*(const unit&,const Y& rhs) { @@ -903,6 +902,7 @@ template inline +BOOST_CONSTEXPR typename divide_typeof_helper< unit,Y >::type operator/(const unit&,const Y& rhs) { @@ -916,6 +916,7 @@ template inline +BOOST_CONSTEXPR typename multiply_typeof_helper< Y,unit >::type operator*(const Y& lhs,const unit&) { @@ -929,6 +930,7 @@ template inline +BOOST_CONSTEXPR typename divide_typeof_helper< Y,unit >::type operator/(const Y& lhs,const unit&) { @@ -942,6 +944,7 @@ operator/(const Y& lhs,const unit&) // class X, // class Y> //inline +//BOOST_CONSTEXPR //typename multiply_typeof_helper< quantity,Y >::type //operator*(const quantity& lhs,const Y& rhs) //{ @@ -955,6 +958,7 @@ operator/(const Y& lhs,const unit&) // class X, // class Y> //inline +//BOOST_CONSTEXPR //typename multiply_typeof_helper< X,quantity >::type //operator*(const X& lhs,const quantity& rhs) //{ @@ -967,6 +971,7 @@ operator/(const Y& lhs,const unit&) template inline +BOOST_CONSTEXPR typename multiply_typeof_helper< quantity,X >::type operator*(const quantity& lhs,const X& rhs) { @@ -979,6 +984,7 @@ operator*(const quantity& lhs,const X& rhs) template inline +BOOST_CONSTEXPR typename multiply_typeof_helper< X,quantity >::type operator*(const X& lhs,const quantity& rhs) { @@ -992,6 +998,7 @@ operator*(const X& lhs,const quantity& rhs) // class X, // class Y> //inline +//BOOST_CONSTEXPR //typename divide_typeof_helper< quantity,Y >::type //operator/(const quantity& lhs,const Y& rhs) //{ @@ -1005,6 +1012,7 @@ operator*(const X& lhs,const quantity& rhs) // class X, // class Y> //inline +//BOOST_CONSTEXPR //typename divide_typeof_helper< X,quantity >::type //operator/(const X& lhs,const quantity& rhs) //{ @@ -1017,6 +1025,7 @@ operator*(const X& lhs,const quantity& rhs) template inline +BOOST_CONSTEXPR typename divide_typeof_helper< quantity,X >::type operator/(const quantity& lhs,const X& rhs) { @@ -1029,6 +1038,7 @@ operator/(const quantity& lhs,const X& rhs) template inline +BOOST_CONSTEXPR typename divide_typeof_helper< X,quantity >::type operator/(const X& lhs,const quantity& rhs) { @@ -1043,6 +1053,7 @@ template inline +BOOST_CONSTEXPR typename multiply_typeof_helper< unit,quantity >::type operator*(const unit&,const quantity& rhs) { @@ -1057,6 +1068,7 @@ template inline +BOOST_CONSTEXPR typename divide_typeof_helper< unit,quantity >::type operator/(const unit&,const quantity& rhs) { @@ -1071,6 +1083,7 @@ template inline +BOOST_CONSTEXPR typename multiply_typeof_helper< quantity,unit >::type operator*(const quantity& lhs,const unit&) { @@ -1085,6 +1098,7 @@ template inline +BOOST_CONSTEXPR typename divide_typeof_helper< quantity,unit >::type operator/(const quantity& lhs,const unit&) { @@ -1095,6 +1109,7 @@ operator/(const quantity& lhs,const unit&) /// runtime unary plus quantity template +BOOST_CONSTEXPR typename unary_plus_typeof_helper< quantity >::type operator+(const quantity& val) { @@ -1105,6 +1120,7 @@ operator+(const quantity& val) /// runtime unary minus quantity template +BOOST_CONSTEXPR typename unary_minus_typeof_helper< quantity >::type operator-(const quantity& val) { @@ -1119,6 +1135,7 @@ template inline +BOOST_CONSTEXPR typename add_typeof_helper< quantity,quantity >::type operator+(const quantity& lhs, const quantity& rhs) @@ -1134,6 +1151,7 @@ template inline +BOOST_CONSTEXPR typename subtract_typeof_helper< quantity,quantity >::type operator-(const quantity& lhs, const quantity& rhs) @@ -1149,6 +1167,7 @@ template inline +BOOST_CONSTEXPR typename multiply_typeof_helper< quantity,quantity >::type operator*(const quantity& lhs, const quantity& rhs) @@ -1165,6 +1184,7 @@ template inline +BOOST_CONSTEXPR typename divide_typeof_helper< quantity,quantity >::type operator/(const quantity& lhs, const quantity& rhs) @@ -1180,6 +1200,7 @@ template inline +BOOST_CONSTEXPR bool operator==(const quantity& val1, const quantity& val2) @@ -1192,6 +1213,7 @@ template inline +BOOST_CONSTEXPR bool operator!=(const quantity& val1, const quantity& val2) @@ -1204,6 +1226,7 @@ template inline +BOOST_CONSTEXPR bool operator<(const quantity& val1, const quantity& val2) @@ -1216,6 +1239,7 @@ template inline +BOOST_CONSTEXPR bool operator<=(const quantity& val1, const quantity& val2) @@ -1228,6 +1252,7 @@ template inline +BOOST_CONSTEXPR bool operator>(const quantity& val1, const quantity& val2) @@ -1240,6 +1265,7 @@ template inline +BOOST_CONSTEXPR bool operator>=(const quantity& val1, const quantity& val2) diff --git a/include/boost/units/scale.hpp b/include/boost/units/scale.hpp index 507c7fb9..7d64cd54 100644 --- a/include/boost/units/scale.hpp +++ b/include/boost/units/scale.hpp @@ -37,10 +37,10 @@ struct scaled_base_unit; template struct scale { - static const long base = Base; + BOOST_STATIC_CONSTEXPR long base = Base; typedef Exponent exponent; typedef double value_type; - static value_type value() { return(detail::static_rational_power(static_cast(base))); } + static BOOST_CONSTEXPR value_type value() { return(detail::static_rational_power(static_cast(base))); } // These need to be defined in specializations for // printing to work. // static std::string name(); @@ -48,22 +48,22 @@ struct scale }; template -const long scale::base; +BOOST_CONSTEXPR_OR_CONST long scale::base; /// INTERNAL ONLY template struct scale > { - static const long base = Base; + BOOST_STATIC_CONSTEXPR long base = Base; typedef static_rational<0> exponent; typedef one value_type; - static one value() { one result; return(result); } + static BOOST_CONSTEXPR one value() { return(one()); } static std::string name() { return(""); } static std::string symbol() { return(""); } }; template -const long scale >::base; +BOOST_CONSTEXPR_OR_CONST long scale >::base; template std::string symbol_string(const scale&) @@ -83,10 +83,10 @@ std::string name_string(const scale&) template<> \ struct scale \ { \ - static const long base = base_; \ + BOOST_STATIC_CONSTEXPR long base = base_; \ typedef exponent_ exponent; \ typedef double value_type; \ - static value_type value() { return(val_); } \ + static BOOST_CONSTEXPR value_type value() { return(val_); } \ static std::string name() { return(#name_); } \ static std::string symbol() { return(#symbol_); } \ } diff --git a/include/boost/units/static_constant.hpp b/include/boost/units/static_constant.hpp index 9026b3fd..d3646adb 100644 --- a/include/boost/units/static_constant.hpp +++ b/include/boost/units/static_constant.hpp @@ -13,9 +13,10 @@ #include +#if defined(BOOST_NO_CXX11_CONSTEXPR) || defined(BOOST_UNITS_DOXYGEN) /// A convenience macro that allows definition of static /// constants in headers in an ODR-safe way. -#define BOOST_UNITS_STATIC_CONSTANT(name, type) \ +# define BOOST_UNITS_STATIC_CONSTANT(name, type) \ template \ struct name##_instance_t \ { \ @@ -29,6 +30,10 @@ namespace \ \ template \ const type name##_instance_t::instance +#else +# define BOOST_UNITS_STATIC_CONSTANT(name, type) \ +BOOST_STATIC_CONSTEXPR type name +#endif /// A convenience macro for static constants with auto /// type deduction. diff --git a/include/boost/units/static_rational.hpp b/include/boost/units/static_rational.hpp index 1296f06c..6d3d8187 100644 --- a/include/boost/units/static_rational.hpp +++ b/include/boost/units/static_rational.hpp @@ -114,11 +114,11 @@ class static_rational (::boost::mpl::divides::value) > type; - static integer_type numerator() { return Numerator; } - static integer_type denominator() { return Denominator; } + static BOOST_CONSTEXPR integer_type numerator() { return Numerator; } + static BOOST_CONSTEXPR integer_type denominator() { return Denominator; } // INTERNAL ONLY - static_rational() { } + BOOST_CONSTEXPR static_rational() { } //~static_rational() { } }; #else @@ -127,19 +127,19 @@ class static_rational { private: - static const integer_type nabs = static_abs::value, - dabs = static_abs::value; + BOOST_STATIC_CONSTEXPR integer_type nabs = static_abs::value, + dabs = static_abs::value; /// greatest common divisor of N and D // need cast to signed because static_gcd returns unsigned long - static const integer_type den = + BOOST_STATIC_CONSTEXPR integer_type den = static_cast(boost::integer::static_gcd::value) * ((D < 0) ? -1 : 1); public: // for mpl arithmetic support typedef detail::static_rational_tag tag; - static const integer_type Numerator = N/den, + BOOST_STATIC_CONSTEXPR integer_type Numerator = N/den, Denominator = D/den; /// INTERNAL ONLY @@ -148,11 +148,11 @@ class static_rational /// static_rational reduced by GCD typedef static_rational type; - static integer_type numerator() { return Numerator; } - static integer_type denominator() { return Denominator; } + static BOOST_CONSTEXPR integer_type numerator() { return Numerator; } + static BOOST_CONSTEXPR integer_type denominator() { return Denominator; } // INTERNAL ONLY - static_rational() { } + BOOST_CONSTEXPR static_rational() { } //~static_rational() { } }; #endif @@ -178,7 +178,7 @@ template class static_rational; /// get decimal value of @c static_rational template -inline typename divide_typeof_helper::type +inline BOOST_CONSTEXPR typename divide_typeof_helper::type value(const static_rational&) { return T(N)/T(D); diff --git a/include/boost/units/systems/detail/constants.hpp b/include/boost/units/systems/detail/constants.hpp index cf156f70..692efa4e 100644 --- a/include/boost/units/systems/detail/constants.hpp +++ b/include/boost/units/systems/detail/constants.hpp @@ -31,22 +31,22 @@ template 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 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, constant >\ }; \ \ template \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper >::type \ operator symbol(const constant& t, const template_name& u)\ { \ @@ -71,6 +72,7 @@ operator symbol(const constant& t, const template_name& u)\ } \ \ template \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper, typename T::value_type>::type \ operator symbol(const template_name& u, const constant& t)\ { \ @@ -97,6 +99,7 @@ struct name ## _typeof_helper, constant > \ }; \ \ template \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper::type \ operator symbol(const constant& t, const constant& u) \ { \ @@ -116,6 +119,7 @@ struct name ## _typeof_helper > \ }; \ \ template \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper::type \ operator symbol(const constant& t, const T2& u) \ { \ @@ -123,6 +127,7 @@ operator symbol(const constant& t, const T2& u) \ } \ \ template \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper::type \ operator symbol(const T1& t, const constant& u) \ { \ @@ -151,6 +156,7 @@ struct name ## _typeof_helper > \ }; \ \ template \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper::type \ operator symbol(const constant& t, const one& u) \ { \ @@ -158,6 +164,7 @@ operator symbol(const constant& t, const one& u) \ } \ \ template \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper::type \ operator symbol(const one& t, const constant& u) \ { \ @@ -174,7 +181,7 @@ struct power_typeof_helper, static_rational > { typedef power_typeof_helper > base; typedef typename base::type type; - static type value(const constant& arg) + static BOOST_CONSTEXPR type value(const constant& arg) { return base::value(arg.value()); } @@ -189,6 +196,7 @@ struct name ## _typeof_helper > \ }; \ \ template \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper::type \ operator symbol(const constant& t, const one& u) \ { \ @@ -196,21 +204,22 @@ operator symbol(const constant& t, const one& u) \ } \ \ template \ +BOOST_CONSTEXPR \ typename name ## _typeof_helper::type \ operator symbol(const one& t, const constant& 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 >) = { } // stream output diff --git a/include/boost/units/unit.hpp b/include/boost/units/unit.hpp index 7d3a8ad4..aa4611cf 100644 --- a/include/boost/units/unit.hpp +++ b/include/boost/units/unit.hpp @@ -42,11 +42,11 @@ class unit typedef Dim dimension_type; typedef System system_type; - unit() { } - unit(const this_type&) { } + BOOST_CONSTEXPR unit() { } + BOOST_CONSTEXPR unit(const this_type&) { } //~unit() { } - this_type& operator=(const this_type&) { return *this; } + BOOST_CXX14_CONSTEXPR this_type& operator=(const this_type&) { return *this; } // sun will ignore errors resulting from templates // instantiated in the return type of a function. @@ -305,7 +305,7 @@ struct power_typeof_helper,static_rational > { typedef unit >::type,typename static_power >::type> type; - static type value(const unit&) + static BOOST_CONSTEXPR type value(const unit&) { return type(); } @@ -317,7 +317,7 @@ struct root_typeof_helper,static_rational > { typedef unit >::type,typename static_root >::type> type; - static type value(const unit&) + static BOOST_CONSTEXPR type value(const unit&) { return type(); } @@ -325,6 +325,7 @@ struct root_typeof_helper,static_rational > /// unit runtime unary plus template +BOOST_CONSTEXPR typename unary_plus_typeof_helper< unit >::type operator+(const unit&) { @@ -335,6 +336,7 @@ operator+(const unit&) /// unit runtime unary minus template +BOOST_CONSTEXPR typename unary_minus_typeof_helper< unit >::type operator-(const unit&) { @@ -348,6 +350,7 @@ template +BOOST_CONSTEXPR typename add_typeof_helper< unit, unit >::type operator+(const unit&,const unit&) @@ -366,6 +369,7 @@ template +BOOST_CONSTEXPR typename subtract_typeof_helper< unit, unit >::type operator-(const unit&,const unit&) @@ -384,6 +388,7 @@ template +BOOST_CONSTEXPR typename multiply_typeof_helper< unit, unit >::type operator*(const unit&,const unit&) @@ -399,6 +404,7 @@ template +BOOST_CONSTEXPR typename divide_typeof_helper< unit, unit >::type operator/(const unit&,const unit&) @@ -415,6 +421,7 @@ template inline +BOOST_CONSTEXPR bool operator==(const unit&,const unit&) { @@ -427,6 +434,7 @@ template inline +BOOST_CONSTEXPR bool operator!=(const unit&,const unit&) { diff --git a/test/test_absolute.cpp b/test/test_absolute.cpp index 3b83173c..2908612f 100644 --- a/test/test_absolute.cpp +++ b/test/test_absolute.cpp @@ -49,18 +49,18 @@ typedef bu::unit int test_main(int,char *[]) { - bu::quantity > q1(212.0 * bu::absolute()); - bu::quantity > q2(0.0 * bu::absolute()); - bu::quantity > q3(q2); - bu::quantity q4(q1 - q3); + BOOST_CONSTEXPR_OR_CONST bu::quantity > q1(212.0 * bu::absolute()); + BOOST_CONSTEXPR_OR_CONST bu::quantity > q2(0.0 * bu::absolute()); + BOOST_CONSTEXPR_OR_CONST bu::quantity > q3(q2); + BOOST_CONSTEXPR_OR_CONST bu::quantity q4(q1 - q3); BOOST_UNITS_CHECK_CLOSE(q4.value(), 180.0); - bu::quantity > q5(static_cast >(q4) + static_cast > >(q2)); + BOOST_CONSTEXPR_OR_CONST bu::quantity > q5(static_cast >(q4) + static_cast > >(q2)); BOOST_UNITS_CHECK_CLOSE(q5.value(), 373.15); - bu::quantity > q6(q5); + BOOST_CONSTEXPR_OR_CONST bu::quantity > q6(q5); BOOST_UNITS_CHECK_CLOSE(q6.value(), 212.0); diff --git a/test/test_cmath.cpp b/test/test_cmath.cpp index ac2b715a..85a5119c 100644 --- a/test/test_cmath.cpp +++ b/test/test_cmath.cpp @@ -29,17 +29,15 @@ Test unit class. namespace bu = boost::units; -static volatile double zero = 0; - int test_main(int,char *[]) { - double inf = std::numeric_limits::infinity(), - nan = 0.0/zero; + BOOST_CONSTEXPR_OR_CONST double inf = std::numeric_limits::infinity(), + nan = std::numeric_limits::quiet_NaN(); // default constructor - const bu::quantity E1(0.0*bu::joules), - E2(inf*bu::joules), - E3(nan*bu::joules); + BOOST_CONSTEXPR_OR_CONST bu::quantity E1(0.0*bu::joules), + E2(inf*bu::joules), + E3(nan*bu::joules); BOOST_CHECK((bu::isfinite)(E1) == true); BOOST_CHECK((bu::isfinite)(E2) == false); @@ -57,8 +55,8 @@ int test_main(int,char *[]) BOOST_CHECK((bu::isnormal)(E2) == false); BOOST_CHECK((bu::isnormal)(E3) == false); - const bu::quantity E4(-2.5*bu::joules), - E5(2.5*bu::joules); + BOOST_CONSTEXPR_OR_CONST bu::quantity E4(-2.5*bu::joules), + E5(2.5*bu::joules); BOOST_CHECK((bu::isgreater)(E4,E5) == false); BOOST_CHECK((bu::isgreater)(E5,E4) == true); @@ -104,10 +102,10 @@ int test_main(int,char *[]) BOOST_CHECK((bu::fdim)(E4,E5) == 0.0*bu::joules); BOOST_CHECK((bu::fdim)(E5,E4) == E5-E4); - const bu::quantity L1(3.0*bu::meters), - L2(4.0*bu::meters); - const bu::quantity A1(4.0*bu::square_meters), - A2(L1*L2+A1); + BOOST_CONSTEXPR_OR_CONST bu::quantity L1(3.0*bu::meters), + L2(4.0*bu::meters); + BOOST_CONSTEXPR_OR_CONST bu::quantity A1(4.0*bu::square_meters), + A2(L1*L2+A1); #if 0 BOOST_CHECK((bu::fma)(L1,L2,A1) == A2); @@ -156,7 +154,7 @@ int test_main(int,char *[]) BOOST_CHECK(ex == 2); BOOST_CHECK((bu::ldexp)(E6,ex) == E4); - const bu::quantity E7(1.0); + BOOST_CONSTEXPR_OR_CONST bu::quantity E7(1.0); BOOST_CHECK(bu::pow(E7,E7) == 1.0*1.0); @@ -165,7 +163,7 @@ int test_main(int,char *[]) BOOST_CHECK(std::abs(E8 - std::exp(1.0)) < .000001); BOOST_CHECK(bu::log(E8) == E7); - const bu::quantity E9(100.0); + BOOST_CONSTEXPR_OR_CONST bu::quantity E9(100.0); BOOST_CHECK(bu::log10(E9) == 2.0); diff --git a/test/test_conversion.cpp b/test/test_conversion.cpp index 79a0f58b..17015245 100644 --- a/test/test_conversion.cpp +++ b/test/test_conversion.cpp @@ -54,32 +54,32 @@ typedef bu::divide_typeof_helper a1(2.0 * mixed_length()); - bu::quantity a2(a1); + BOOST_CONSTEXPR_OR_CONST bu::quantity a1(2.0 * mixed_length()); + BOOST_CONSTEXPR_OR_CONST bu::quantity a2(a1); BOOST_UNITS_CHECK_CLOSE(a2.value(), .02); - bu::quantity a3(a2); + BOOST_CONSTEXPR_OR_CONST bu::quantity a3(a2); BOOST_UNITS_CHECK_CLOSE(a3.value(), 2.0); - bu::quantity e1(2.0 * mixed_energy_1()); - bu::quantity e2(e1); + BOOST_CONSTEXPR_OR_CONST bu::quantity e1(2.0 * mixed_energy_1()); + BOOST_CONSTEXPR_OR_CONST bu::quantity e2(e1); BOOST_UNITS_CHECK_CLOSE(e2.value(), 20.0); - bu::quantity e3(e1); + BOOST_CONSTEXPR_OR_CONST bu::quantity e3(e1); BOOST_UNITS_CHECK_CLOSE(e3.value(), .0002); - bu::quantity e4(e3); + BOOST_CONSTEXPR_OR_CONST bu::quantity e4(e3); BOOST_UNITS_CHECK_CLOSE(e4.value(), 20.0); - bu::quantity F0 = 20 * bu::cgs::dyne; + BOOST_CONSTEXPR_OR_CONST bu::quantity F0 = 20 * bu::cgs::dyne; BOOST_UNITS_CHECK_CLOSE(F0.value(), 20.0); - bu::quantity F3(F0); + BOOST_CONSTEXPR_OR_CONST bu::quantity F3(F0); BOOST_UNITS_CHECK_CLOSE(F3.value(), 2.0e-4); - bu::quantity F5(20 * bu::cgs::dyne); + BOOST_CONSTEXPR_OR_CONST bu::quantity F5(20 * bu::cgs::dyne); BOOST_UNITS_CHECK_CLOSE(F5.value(), 2.0e-4); // same type @@ -89,14 +89,14 @@ BOOST_AUTO_TEST_CASE(test_conversion) { BOOST_AUTO_TEST_CASE(test_dimensionless_conversions) { typedef bu::divide_typeof_helper::type mixed_dimensionless; - bu::quantity dimensionless_test1(1.0*bu::cgs::dyne/bu::si::newton); + BOOST_CONSTEXPR_OR_CONST bu::quantity dimensionless_test1(1.0*bu::cgs::dyne/bu::si::newton); BOOST_CHECK(dimensionless_test1 == 1e-5); typedef bu::multiply_typeof_helper::type m_cm; typedef bu::divide_typeof_helper::type heterogeneous_dimensionless; - bu::quantity dimensionless_test2(1.0*bu::cgs::dyne/bu::si::newton); + BOOST_CONSTEXPR_OR_CONST bu::quantity dimensionless_test2(1.0*bu::cgs::dyne/bu::si::newton); BOOST_CHECK(dimensionless_test2.value() == 1e-5); - bu::quantity::type> dimensionless_test3(dimensionless_test2); + BOOST_CONSTEXPR_OR_CONST bu::quantity::type> dimensionless_test3(dimensionless_test2); BOOST_UNITS_CHECK_CLOSE(dimensionless_test3.value(), 1.0); BOOST_UNITS_CHECK_CLOSE(boost::units::conversion_factor(mixed_dimensionless(), heterogeneous_dimensionless()), 1e-5); @@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(test_dimensionless_conversions) { //m/cm -> g/kg - bu::quantity::type> dimensionless_test4(2.0 * bu::si::meters / bu::cgs::centimeters); - bu::quantity::type> dimensionless_test5(dimensionless_test4); + BOOST_CONSTEXPR_OR_CONST bu::quantity::type> dimensionless_test4(2.0 * bu::si::meters / bu::cgs::centimeters); + BOOST_CONSTEXPR_OR_CONST bu::quantity::type> dimensionless_test5(dimensionless_test4); BOOST_UNITS_CHECK_CLOSE(dimensionless_test5.value(), 2e5); } diff --git a/test/test_default_conversion.cpp b/test/test_default_conversion.cpp index 734a9431..f05aac69 100644 --- a/test/test_default_conversion.cpp +++ b/test/test_default_conversion.cpp @@ -54,24 +54,24 @@ BOOST_UNITS_DEFAULT_CONVERSION(unit6_tag, make_unit::type); BOOST_UNITS_DEFAULT_CONVERSION(unit7_tag, make_unit::type); int test_main(int, char*[]) { - double value1 = boost::units::conversion_factor(unit3_tag::unit_type(), unit1_tag::unit_type()); + BOOST_CONSTEXPR_OR_CONST double value1 = boost::units::conversion_factor(unit3_tag::unit_type(), unit1_tag::unit_type()); BOOST_CHECK(std::abs(value1 - 1.0/6.0) < .0000000001); - double value2 = boost::units::conversion_factor(unit5_tag::unit_type() / unit4_tag::unit_type(), unit1_tag::unit_type()); + BOOST_CONSTEXPR_OR_CONST double value2 = boost::units::conversion_factor(unit5_tag::unit_type() / unit4_tag::unit_type(), unit1_tag::unit_type()); BOOST_CHECK(std::abs(value2 - 5.0/6.0) < .0000000001); typedef boost::units::scaled_base_unit > > scaled_unit5_tag; - double value3 = boost::units::conversion_factor(scaled_unit5_tag::unit_type() / unit4_tag::unit_type(), unit1_tag::unit_type()); + BOOST_CONSTEXPR_OR_CONST double value3 = boost::units::conversion_factor(scaled_unit5_tag::unit_type() / unit4_tag::unit_type(), unit1_tag::unit_type()); BOOST_CHECK(std::abs(value3 - 10.0/6.0) < .0000000001); // check homogeneous unit conversions - double value4 = boost::units::conversion_factor(make_unit::type(), make_unit::type()); + BOOST_CONSTEXPR_OR_CONST double value4 = boost::units::conversion_factor(make_unit::type(), make_unit::type()); BOOST_CHECK(std::abs(value4 - 1.0/6.0) < .0000000001); - double value5 = boost::units::conversion_factor(unit3_tag::unit_type(), make_unit::type()); + BOOST_CONSTEXPR_OR_CONST double value5 = boost::units::conversion_factor(unit3_tag::unit_type(), make_unit::type()); BOOST_CHECK(std::abs(value5 - 1.0/6.0) < .0000000001); - double value6 = boost::units::conversion_factor(make_unit::type(), unit1_tag::unit_type()); + BOOST_CONSTEXPR_OR_CONST double value6 = boost::units::conversion_factor(make_unit::type(), unit1_tag::unit_type()); BOOST_CHECK(std::abs(value6 - 1.0/6.0) < .0000000001); // check chained homogeneous conversions - double value7 = boost::units::conversion_factor(unit6_tag::unit_type(), unit7_tag::unit_type()); + BOOST_CONSTEXPR_OR_CONST double value7 = boost::units::conversion_factor(unit6_tag::unit_type(), unit7_tag::unit_type()); BOOST_CHECK(std::abs(value7 - 5.0/42.0) < .0000000001); return(0); diff --git a/test/test_dimensionless_ice1.cpp b/test/test_dimensionless_ice1.cpp index 8fb98678..06ab61ee 100644 --- a/test/test_dimensionless_ice1.cpp +++ b/test/test_dimensionless_ice1.cpp @@ -14,7 +14,7 @@ void foo() { - boost::units::quantity d = boost::units::quantity< boost::units::si::dimensionless >(); + BOOST_CONSTEXPR_OR_CONST boost::units::quantity d = boost::units::quantity< boost::units::si::dimensionless >(); boost::ignore_unused(d); } diff --git a/test/test_dimensionless_ice2.cpp b/test/test_dimensionless_ice2.cpp index 90795761..b04e6544 100644 --- a/test/test_dimensionless_ice2.cpp +++ b/test/test_dimensionless_ice2.cpp @@ -14,7 +14,7 @@ void foo() { - boost::units::quantity d(1.0 * boost::units::si::meters / boost::units::cgs::centimeters); + BOOST_CONSTEXPR_OR_CONST boost::units::quantity d(1.0 * boost::units::si::meters / boost::units::cgs::centimeters); } #include diff --git a/test/test_dimensionless_quantity.cpp b/test/test_dimensionless_quantity.cpp index 6937d9e7..197d7c9d 100644 --- a/test/test_dimensionless_quantity.cpp +++ b/test/test_dimensionless_quantity.cpp @@ -27,40 +27,40 @@ Test unit class. namespace bu = boost::units; -static const double E_ = 2.718281828459045235360287471352662497757; +BOOST_STATIC_CONSTEXPR double E_ = 2.718281828459045235360287471352662497757; int test_main(int,char *[]) { // default constructor - const bu::quantity E1; + BOOST_CONSTEXPR_OR_CONST bu::quantity E1; BOOST_CHECK(E1.value() == double()); // value_type constructor - const bu::quantity E2(E_); + BOOST_CONSTEXPR_OR_CONST bu::quantity E2(E_); BOOST_CHECK(E2.value() == E_); // copy constructor - const bu::quantity E3(E2); + BOOST_CONSTEXPR_OR_CONST bu::quantity E3(E2); BOOST_CHECK(E3.value() == E_); // operator= - const bu::quantity E4 = E2; + BOOST_CONSTEXPR_OR_CONST bu::quantity E4 = E2; BOOST_CHECK(E4.value() == E_); // implicit copy constructor value_type conversion - const bu::quantity E5(E2); + BOOST_CONSTEXPR_OR_CONST bu::quantity E5(E2); BOOST_UNITS_CHECK_CLOSE(E5.value(), float(E_)); - const bu::quantity E6(E2); + BOOST_CONSTEXPR_OR_CONST bu::quantity E6(E2); BOOST_CHECK(E6.value() == long(E_)); // implicit operator= value_type conversion // narrowing conversion disallowed -// const bu::quantity E7 = E2; +// BOOST_CONSTEXPR_OR_CONST bu::quantity E7 = E2; // BOOST_UNITS_CHECK_CLOSE(E7.value(),float(E_)); // narrowing conversion disallowed -// const bu::quantity E8 = E2; +// BOOST_CONSTEXPR_OR_CONST bu::quantity E8 = E2; // BOOST_CHECK(E8.value() == long(E_)); // const construction @@ -104,7 +104,7 @@ int test_main(int,char *[]) BOOST_CHECK(E9.value() == 1.0); // static construct quantity from value_type - const bu::quantity E(bu::quantity::from_value(2.5)); + BOOST_CONSTEXPR_OR_CONST bu::quantity E(bu::quantity::from_value(2.5)); BOOST_CHECK(E.value() == 2.5); // implicit conversion to value_type @@ -138,8 +138,8 @@ int test_main(int,char *[]) // scalar / quantity BOOST_CHECK(2.0/E == bu::quantity::from_value(0.8)); - const bu::quantity D1(1.0), - D2(2.0); + BOOST_CONSTEXPR_OR_CONST bu::quantity D1(1.0), + D2(2.0); // unit * quantity BOOST_CHECK(bu::dimensionless()*D1 == D1); @@ -183,10 +183,10 @@ int test_main(int,char *[]) // rational root of quantity BOOST_CHECK((2.0*bu::root< bu::static_rational<3,2> >(D2) == 2.0*std::pow(2.0,2.0/3.0)*bu::dimensionless())); - const bu::quantity A1(0.0), - A2(0.0), - A3(1.0), - A4(-1.0); + BOOST_CONSTEXPR_OR_CONST bu::quantity A1(0.0), + A2(0.0), + A3(1.0), + A4(-1.0); // operator== BOOST_CHECK((A1 == A2) == true); diff --git a/test/test_implicit_conversion.cpp b/test/test_implicit_conversion.cpp index 350a7c4e..41dfca03 100644 --- a/test/test_implicit_conversion.cpp +++ b/test/test_implicit_conversion.cpp @@ -96,16 +96,16 @@ int test_main(int,char *[]) BOOST_CHECK((bu::is_implicitly_convertible::value == false)); BOOST_CHECK((bu::is_implicitly_convertible::value == false)); - const bu::quantity S1(2.0*bu::si::seconds); - const bu::quantity S2 = S1; + BOOST_CONSTEXPR_OR_CONST bu::quantity S1(2.0*bu::si::seconds); + BOOST_CONSTEXPR_OR_CONST bu::quantity S2 = S1; BOOST_CHECK((S1.value() == S2.value())); - const bu::quantity S3(2.0*bu::si::catalytic_activity()); + BOOST_CONSTEXPR_OR_CONST bu::quantity S3(2.0*bu::si::catalytic_activity()); - const bu::quantity C1(2.0*bu::cgs::seconds); - const bu::quantity C2 = C1; + BOOST_CONSTEXPR_OR_CONST bu::quantity C1(2.0*bu::cgs::seconds); + BOOST_CONSTEXPR_OR_CONST bu::quantity C2 = C1; BOOST_CHECK((C1.value() == C2.value())); diff --git a/test/test_information_units.cpp b/test/test_information_units.cpp index 6bb1ab59..80eb04f2 100644 --- a/test/test_information_units.cpp +++ b/test/test_information_units.cpp @@ -54,13 +54,13 @@ const double close_fraction = 0.0000001; // check transitive conversion factors // invariant: cf(u1,u3) = cf(u1,u2)*cf(u2,u3) #define CHECK_TRANSITIVE_CF(u1, u2, u3) { \ - double cf12 = bu::conversion_factor((u2), (u1)) ; \ - double cf23 = bu::conversion_factor((u3), (u2)) ; \ - double cf13 = bu::conversion_factor((u3), (u1)) ; \ + BOOST_CONSTEXPR_OR_CONST double cf12 = bu::conversion_factor((u2), (u1)) ; \ + BOOST_CONSTEXPR_OR_CONST double cf23 = bu::conversion_factor((u3), (u2)) ; \ + BOOST_CONSTEXPR_OR_CONST double cf13 = bu::conversion_factor((u3), (u1)) ; \ BOOST_CHECK_CLOSE_FRACTION(cf13, cf12*cf23, close_fraction); \ - double cf32 = bu::conversion_factor((u2), (u3)) ; \ - double cf21 = bu::conversion_factor((u1), (u2)) ; \ - double cf31 = bu::conversion_factor((u1), (u3)) ; \ + BOOST_CONSTEXPR_OR_CONST double cf32 = bu::conversion_factor((u2), (u3)) ; \ + BOOST_CONSTEXPR_OR_CONST double cf21 = bu::conversion_factor((u1), (u2)) ; \ + BOOST_CONSTEXPR_OR_CONST double cf31 = bu::conversion_factor((u1), (u3)) ; \ BOOST_CHECK_CLOSE_FRACTION(cf31, cf32*cf21, close_fraction); \ } @@ -105,55 +105,55 @@ BOOST_AUTO_TEST_CASE(test_transitive_byte_nat_hartley) { BOOST_AUTO_TEST_CASE(test_byte_quantity_is_default) { using namespace bu::information; - quantity qd(2 * byte); + BOOST_CONSTEXPR_OR_CONST quantity qd(2 * byte); BOOST_CHECK_EQUAL(qd.value(), double(2)); - quantity ql(2 * byte); + BOOST_CONSTEXPR_OR_CONST quantity ql(2 * byte); BOOST_CHECK_EQUAL(ql.value(), long(2)); } BOOST_AUTO_TEST_CASE(test_byte_quantity_explicit) { using namespace bu::information; - quantity qd(2 * byte); + BOOST_CONSTEXPR_OR_CONST quantity qd(2 * byte); BOOST_CHECK_EQUAL(qd.value(), double(2)); - quantity ql(2 * byte); + BOOST_CONSTEXPR_OR_CONST quantity ql(2 * byte); BOOST_CHECK_EQUAL(ql.value(), long(2)); } BOOST_AUTO_TEST_CASE(test_bit_quantity) { using namespace bu::information; - quantity qd(2 * bit); + BOOST_CONSTEXPR_OR_CONST quantity qd(2 * bit); BOOST_CHECK_EQUAL(qd.value(), double(2)); - quantity ql(2 * bit); + BOOST_CONSTEXPR_OR_CONST quantity ql(2 * bit); BOOST_CHECK_EQUAL(ql.value(), long(2)); } BOOST_AUTO_TEST_CASE(test_nat_quantity) { using namespace bu::information; - quantity qd(2 * nat); + BOOST_CONSTEXPR_OR_CONST quantity qd(2 * nat); BOOST_CHECK_EQUAL(qd.value(), double(2)); - quantity ql(2 * nat); + BOOST_CONSTEXPR_OR_CONST quantity ql(2 * nat); BOOST_CHECK_EQUAL(ql.value(), long(2)); } BOOST_AUTO_TEST_CASE(test_hartley_quantity) { using namespace bu::information; - quantity qd(2 * hartley); + BOOST_CONSTEXPR_OR_CONST quantity qd(2 * hartley); BOOST_CHECK_EQUAL(qd.value(), double(2)); - quantity ql(2 * hartley); + BOOST_CONSTEXPR_OR_CONST quantity ql(2 * hartley); BOOST_CHECK_EQUAL(ql.value(), long(2)); } BOOST_AUTO_TEST_CASE(test_shannon_quantity) { using namespace bu::information; - quantity qd(2 * shannon); + BOOST_CONSTEXPR_OR_CONST quantity qd(2 * shannon); BOOST_CHECK_EQUAL(qd.value(), double(2)); - quantity ql(2 * shannon); + BOOST_CONSTEXPR_OR_CONST quantity ql(2 * shannon); BOOST_CHECK_EQUAL(ql.value(), long(2)); } BOOST_AUTO_TEST_CASE(test_mixed_hu) { using namespace bu::information; - const double cf = 0.001; + BOOST_CONSTEXPR_OR_CONST double cf = 0.001; BOOST_CHECK_CLOSE_FRACTION((quantity(1.0 * bits)).value(), 1.0, cf); BOOST_CHECK_CLOSE_FRACTION((quantity(1.0 * bits)).value(), 1.0/8.0, cf); BOOST_CHECK_CLOSE_FRACTION((quantity(1.0 * bits)).value(), 0.69315, cf); @@ -163,37 +163,37 @@ BOOST_AUTO_TEST_CASE(test_mixed_hu) { BOOST_AUTO_TEST_CASE(test_info_prefixes) { using namespace bu::information; - quantity q10(1LL * kibi * byte); + BOOST_CONSTEXPR_OR_CONST quantity q10(1LL * kibi * byte); BOOST_CHECK_EQUAL(q10.value(), 1024LL); - quantity q20(1LL * mebi * byte); + BOOST_CONSTEXPR_OR_CONST quantity q20(1LL * mebi * byte); BOOST_CHECK_EQUAL(q20.value(), 1048576LL); - quantity q30(1LL * gibi * byte); + BOOST_CONSTEXPR_OR_CONST quantity q30(1LL * gibi * byte); BOOST_CHECK_EQUAL(q30.value(), 1073741824LL); - quantity q40(1LL * tebi * byte); + BOOST_CONSTEXPR_OR_CONST quantity q40(1LL * tebi * byte); BOOST_CHECK_EQUAL(q40.value(), 1099511627776LL); - quantity q50(1LL * pebi * byte); + BOOST_CONSTEXPR_OR_CONST quantity q50(1LL * pebi * byte); BOOST_CHECK_EQUAL(q50.value(), 1125899906842624LL); - quantity q60(1LL * exbi * byte); + BOOST_CONSTEXPR_OR_CONST quantity q60(1LL * exbi * byte); BOOST_CHECK_EQUAL(q60.value(), 1152921504606846976LL); using boost::multiprecision::int128_t; - quantity q70(1LL * zebi * byte); + const quantity q70(1LL * zebi * byte); BOOST_CHECK_EQUAL(q70.value(), int128_t("1180591620717411303424")); - quantity q80(1LL * yobi * byte); + const quantity q80(1LL * yobi * byte); BOOST_CHECK_EQUAL(q80.value(), int128_t("1208925819614629174706176")); // sanity check: si prefixes should also operate - quantity q1e3(1LL * si::kilo * byte); + BOOST_CONSTEXPR_OR_CONST quantity q1e3(1LL * si::kilo * byte); BOOST_CHECK_EQUAL(q1e3.value(), 1000LL); - quantity q1e6(1LL * si::mega * byte); + BOOST_CONSTEXPR_OR_CONST quantity q1e6(1LL * si::mega * byte); BOOST_CHECK_EQUAL(q1e6.value(), 1000000LL); } diff --git a/test/test_mixed_value_types.cpp b/test/test_mixed_value_types.cpp index dbc16967..7d86362c 100644 --- a/test/test_mixed_value_types.cpp +++ b/test/test_mixed_value_types.cpp @@ -16,7 +16,7 @@ namespace bu = boost::units; int main() { bu::quantity q1; - bu::quantity q2; + BOOST_CONSTEXPR_OR_CONST bu::quantity q2; q1 + q2; q1 -= q2; } diff --git a/test/test_quantity.cpp b/test/test_quantity.cpp index 28eee7cd..b6461bf2 100644 --- a/test/test_quantity.cpp +++ b/test/test_quantity.cpp @@ -27,35 +27,35 @@ Test unit class. namespace bu = boost::units; -static const double E_ = 2.718281828459045235360287471352662497757; +BOOST_STATIC_CONSTEXPR double E_ = 2.718281828459045235360287471352662497757; int test_main(int,char *[]) { // default constructor - const bu::quantity E1; + BOOST_CONSTEXPR_OR_CONST bu::quantity E1; BOOST_CHECK(E1.value() == double()); // value_type constructor - const bu::quantity E2(E_*bu::joules); + BOOST_CONSTEXPR_OR_CONST bu::quantity E2(E_*bu::joules); BOOST_CHECK(E2.value() == E_); // copy constructor - const bu::quantity E3(E2); + BOOST_CONSTEXPR_OR_CONST bu::quantity E3(E2); BOOST_CHECK(E3.value() == E_); // operator= - const bu::quantity E4 = E2; + BOOST_CONSTEXPR_OR_CONST bu::quantity E4 = E2; BOOST_CHECK(E4.value() == E_); // implicit copy constructor value_type conversion - const bu::quantity E5(E2); + BOOST_CONSTEXPR_OR_CONST bu::quantity E5(E2); BOOST_UNITS_CHECK_CLOSE(E5.value(),float(E_)); // implicit operator= value_type conversion - //const bu::quantity E7 = E2; + //BOOST_CONSTEXPR_OR_CONST bu::quantity E7 = E2; //BOOST_UNITS_CHECK_CLOSE(E7.value(),float(E_)); - //const bu::quantity E8 = E2; + //BOOST_CONSTEXPR_OR_CONST bu::quantity E8 = E2; //BOOST_CHECK(E8.value() == long(E_)); // const construction @@ -91,7 +91,7 @@ int test_main(int,char *[]) BOOST_CHECK(E9.value() == 1.0); // static construct quantity from value_type - const bu::quantity E(bu::quantity::from_value(2.5)); + BOOST_CONSTEXPR_OR_CONST bu::quantity E(bu::quantity::from_value(2.5)); BOOST_CHECK(E.value() == 2.5); // quantity_cast @@ -120,10 +120,10 @@ int test_main(int,char *[]) // scalar / quantity BOOST_CHECK(2.0/E == bu::quantity::from_value(0.8)); - const bu::quantity L(1.0*bu::meters); - const bu::quantity M(2.0*bu::kilograms); - const bu::quantity T(3.0*bu::seconds); - const bu::quantity V(bu::quantity::from_value(4.0)); + BOOST_CONSTEXPR_OR_CONST bu::quantity L(1.0*bu::meters); + BOOST_CONSTEXPR_OR_CONST bu::quantity M(2.0*bu::kilograms); + BOOST_CONSTEXPR_OR_CONST bu::quantity T(3.0*bu::seconds); + BOOST_CONSTEXPR_OR_CONST bu::quantity V(bu::quantity::from_value(4.0)); // unit * quantity BOOST_CHECK(bu::seconds*V == 4.0*bu::meters); @@ -155,8 +155,8 @@ int test_main(int,char *[]) // quantity / quantity BOOST_CHECK(L/V == 0.25*bu::seconds); - const bu::quantity A(2.0*bu::square_meters); - const bu::quantity VL(1.0*bu::cubic_meters); + BOOST_CONSTEXPR_OR_CONST bu::quantity A(2.0*bu::square_meters); + BOOST_CONSTEXPR_OR_CONST bu::quantity VL(1.0*bu::cubic_meters); // integer power of quantity BOOST_CHECK(2.0*bu::pow<2>(L) == A); @@ -170,10 +170,10 @@ int test_main(int,char *[]) // rational root of quantity BOOST_CHECK((bu::root< bu::static_rational<3,2> >(VL) == 0.5*A)); - const bu::quantity A1(0.0*bu::square_meters), - A2(0.0*bu::square_meters), - A3(1.0*bu::square_meters), - A4(-1.0*bu::square_meters); + BOOST_CONSTEXPR_OR_CONST bu::quantity A1(0.0*bu::square_meters), + A2(0.0*bu::square_meters), + A3(1.0*bu::square_meters), + A4(-1.0*bu::square_meters); // operator== BOOST_CHECK((A1 == A2) == true); diff --git a/test/test_scaled_unit.cpp b/test/test_scaled_unit.cpp index 89cd8185..2357a98d 100644 --- a/test/test_scaled_unit.cpp +++ b/test/test_scaled_unit.cpp @@ -37,23 +37,23 @@ namespace bu = boost::units; namespace si = boost::units::si; BOOST_AUTO_TEST_CASE(test_scaled_to_plain) { - bu::quantity s1 = 12.5 * si::seconds; - bu::quantity s2(si::nano * s1); + BOOST_CONSTEXPR_OR_CONST bu::quantity s1 = 12.5 * si::seconds; + BOOST_CONSTEXPR_OR_CONST bu::quantity s2(si::nano * s1); BOOST_CHECK_CLOSE_FRACTION(1e-9 * s1.value(), s2.value(), 0.000000001); } BOOST_AUTO_TEST_CASE(test_plain_to_scaled) { - bu::quantity s1 = 12.5 * si::seconds; + BOOST_CONSTEXPR_OR_CONST bu::quantity s1 = 12.5 * si::seconds; typedef bu::multiply_typeof_helper::type time_unit; - bu::quantity s2(s1); + BOOST_CONSTEXPR_OR_CONST bu::quantity s2(s1); BOOST_CHECK_CLOSE_FRACTION(1e9 * s1.value(), s2.value(), 0.000000001); } BOOST_AUTO_TEST_CASE(test_scaled_to_scaled) { typedef bu::multiply_typeof_helper::type mega_time_unit; typedef bu::multiply_typeof_helper::type micro_time_unit; - bu::quantity s1(12.5 * si::seconds); - bu::quantity s2(s1); + BOOST_CONSTEXPR_OR_CONST bu::quantity s1(12.5 * si::seconds); + BOOST_CONSTEXPR_OR_CONST bu::quantity s2(s1); BOOST_CHECK_CLOSE_FRACTION(1e12 * s1.value(), s2.value(), 0.000000001); } diff --git a/test/test_unit.cpp b/test/test_unit.cpp index 49748c50..ed80430f 100644 --- a/test/test_unit.cpp +++ b/test/test_unit.cpp @@ -29,11 +29,11 @@ namespace bu = boost::units; int test_main(int,char *[]) { - const bu::dimensionless D; + BOOST_CONSTEXPR_OR_CONST bu::dimensionless D; - const bu::length L; - const bu::mass M; - const bu::time T; + BOOST_CONSTEXPR_OR_CONST bu::length L; + BOOST_CONSTEXPR_OR_CONST bu::mass M; + BOOST_CONSTEXPR_OR_CONST bu::time T; BOOST_CHECK(+L == L); BOOST_CHECK(-L == L); @@ -45,9 +45,9 @@ int test_main(int,char *[]) BOOST_CHECK(M+M == M); BOOST_CHECK(M-M == M); - const bu::area A; - const bu::energy E; - const bu::velocity V; + BOOST_CONSTEXPR_OR_CONST bu::area A; + BOOST_CONSTEXPR_OR_CONST bu::energy E; + BOOST_CONSTEXPR_OR_CONST bu::velocity V; BOOST_CHECK(L*L == A); BOOST_CHECK(A == L*L); From 86dbd8c04b508344b45174071b08516ab0ec3490 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Sun, 14 Aug 2016 21:27:15 +0200 Subject: [PATCH 2/2] Use constexpr for name() and symbol() --- example/autoprefixes.cpp | 12 ++++++------ include/boost/units/base_units/angle/arcminute.hpp | 4 ++-- include/boost/units/base_units/angle/arcsecond.hpp | 4 ++-- include/boost/units/base_units/angle/revolution.hpp | 4 ++-- .../units/base_units/astronomical/light_day.hpp | 4 ++-- .../units/base_units/astronomical/light_hour.hpp | 4 ++-- .../units/base_units/astronomical/light_minute.hpp | 4 ++-- .../units/base_units/astronomical/light_year.hpp | 4 ++-- include/boost/units/base_units/imperial/drachm.hpp | 4 ++-- .../boost/units/base_units/imperial/fluid_ounce.hpp | 4 ++-- include/boost/units/base_units/imperial/foot.hpp | 4 ++-- include/boost/units/base_units/imperial/furlong.hpp | 4 ++-- include/boost/units/base_units/imperial/gallon.hpp | 4 ++-- include/boost/units/base_units/imperial/gill.hpp | 4 ++-- include/boost/units/base_units/imperial/grain.hpp | 4 ++-- .../units/base_units/imperial/hundredweight.hpp | 4 ++-- include/boost/units/base_units/imperial/inch.hpp | 4 ++-- include/boost/units/base_units/imperial/league.hpp | 4 ++-- include/boost/units/base_units/imperial/mile.hpp | 4 ++-- include/boost/units/base_units/imperial/ounce.hpp | 4 ++-- include/boost/units/base_units/imperial/quart.hpp | 4 ++-- include/boost/units/base_units/imperial/quarter.hpp | 4 ++-- include/boost/units/base_units/imperial/stone.hpp | 4 ++-- include/boost/units/base_units/imperial/thou.hpp | 4 ++-- include/boost/units/base_units/imperial/ton.hpp | 4 ++-- include/boost/units/base_units/information/byte.hpp | 4 ++-- .../boost/units/base_units/information/shannon.hpp | 4 ++-- include/boost/units/base_units/metric/angstrom.hpp | 4 ++-- include/boost/units/base_units/metric/day.hpp | 4 ++-- include/boost/units/base_units/metric/fermi.hpp | 4 ++-- include/boost/units/base_units/metric/hour.hpp | 4 ++-- include/boost/units/base_units/metric/micron.hpp | 4 ++-- include/boost/units/base_units/metric/minute.hpp | 4 ++-- .../boost/units/base_units/metric/nautical_mile.hpp | 4 ++-- include/boost/units/base_units/metric/ton.hpp | 4 ++-- include/boost/units/base_units/metric/year.hpp | 4 ++-- include/boost/units/base_units/us/cup.hpp | 4 ++-- include/boost/units/base_units/us/dram.hpp | 4 ++-- include/boost/units/base_units/us/fluid_dram.hpp | 4 ++-- include/boost/units/base_units/us/fluid_ounce.hpp | 4 ++-- include/boost/units/base_units/us/foot.hpp | 4 ++-- include/boost/units/base_units/us/gallon.hpp | 4 ++-- include/boost/units/base_units/us/gill.hpp | 4 ++-- include/boost/units/base_units/us/grain.hpp | 4 ++-- include/boost/units/base_units/us/hundredweight.hpp | 4 ++-- include/boost/units/base_units/us/inch.hpp | 4 ++-- include/boost/units/base_units/us/mil.hpp | 4 ++-- include/boost/units/base_units/us/mile.hpp | 4 ++-- include/boost/units/base_units/us/minim.hpp | 4 ++-- include/boost/units/base_units/us/ounce.hpp | 4 ++-- include/boost/units/base_units/us/quart.hpp | 4 ++-- include/boost/units/base_units/us/tablespoon.hpp | 4 ++-- include/boost/units/base_units/us/teaspoon.hpp | 4 ++-- include/boost/units/base_units/us/ton.hpp | 4 ++-- include/boost/units/conversion.hpp | 4 ++-- test/test_output.cpp | 20 ++++++++++---------- 56 files changed, 124 insertions(+), 124 deletions(-) diff --git a/example/autoprefixes.cpp b/example/autoprefixes.cpp index 478fbbd1..611e1af7 100644 --- a/example/autoprefixes.cpp +++ b/example/autoprefixes.cpp @@ -54,20 +54,20 @@ meter struct byte_base_unit : boost::units::base_unit { - static const char* name() { return("byte"); } - static const char* symbol() { return("b"); } + static BOOST_CONSTEXPR const char* name() { return("byte"); } + static BOOST_CONSTEXPR const char* symbol() { return("b"); } }; struct thing_base_unit : boost::units::base_unit { - static const char* name() { return("thing"); } - static const char* symbol() { return(""); } + static BOOST_CONSTEXPR const char* name() { return("thing"); } + static BOOST_CONSTEXPR const char* symbol() { return(""); } }; struct euro_base_unit : boost::units::base_unit { - static const char* name() { return("EUR"); } - static const char* symbol() { return("€"); } + static BOOST_CONSTEXPR const char* name() { return("EUR"); } + static BOOST_CONSTEXPR const char* symbol() { return("€"); } }; int main() diff --git a/include/boost/units/base_units/angle/arcminute.hpp b/include/boost/units/base_units/angle/arcminute.hpp index 86bf5e0f..27570fbb 100644 --- a/include/boost/units/base_units/angle/arcminute.hpp +++ b/include/boost/units/base_units/angle/arcminute.hpp @@ -26,8 +26,8 @@ typedef scaled_base_unit > > ar template<> struct base_unit_info { - static const char* name() { return("arcminute"); } - static const char* symbol() { return("'"); } + static BOOST_CONSTEXPR const char* name() { return("arcminute"); } + static BOOST_CONSTEXPR const char* symbol() { return("'"); } }; } diff --git a/include/boost/units/base_units/angle/arcsecond.hpp b/include/boost/units/base_units/angle/arcsecond.hpp index 8baabfa6..97851ffb 100644 --- a/include/boost/units/base_units/angle/arcsecond.hpp +++ b/include/boost/units/base_units/angle/arcsecond.hpp @@ -27,8 +27,8 @@ typedef scaled_base_unit > > template<> struct base_unit_info { - static const char* name() { return("arcsecond"); } - static const char* symbol() { return("\""); } + static BOOST_CONSTEXPR const char* name() { return("arcsecond"); } + static BOOST_CONSTEXPR const char* symbol() { return("\""); } }; } diff --git a/include/boost/units/base_units/angle/revolution.hpp b/include/boost/units/base_units/angle/revolution.hpp index 2dd0d5b9..3d576286 100644 --- a/include/boost/units/base_units/angle/revolution.hpp +++ b/include/boost/units/base_units/angle/revolution.hpp @@ -26,8 +26,8 @@ typedef scaled_base_unit > > re template<> struct base_unit_info { - static const char* name() { return("revolution"); } - static const char* symbol() { return("rev"); } + static BOOST_CONSTEXPR const char* name() { return("revolution"); } + static BOOST_CONSTEXPR const char* symbol() { return("rev"); } }; } diff --git a/include/boost/units/base_units/astronomical/light_day.hpp b/include/boost/units/base_units/astronomical/light_day.hpp index 2d045ff2..a0ad93be 100644 --- a/include/boost/units/base_units/astronomical/light_day.hpp +++ b/include/boost/units/base_units/astronomical/light_day.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit struct base_unit_info { - static const char* name() { return("light day"); } - static const char* symbol() { return("ldy"); } + static BOOST_CONSTEXPR const char* name() { return("light day"); } + static BOOST_CONSTEXPR const char* symbol() { return("ldy"); } }; } // namespace units diff --git a/include/boost/units/base_units/astronomical/light_hour.hpp b/include/boost/units/base_units/astronomical/light_hour.hpp index 207d951a..91bc09a2 100644 --- a/include/boost/units/base_units/astronomical/light_hour.hpp +++ b/include/boost/units/base_units/astronomical/light_hour.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit struct base_unit_info { - static const char* name() { return("light hour"); } - static const char* symbol() { return("lhr"); } + static BOOST_CONSTEXPR const char* name() { return("light hour"); } + static BOOST_CONSTEXPR const char* symbol() { return("lhr"); } }; } // namespace units diff --git a/include/boost/units/base_units/astronomical/light_minute.hpp b/include/boost/units/base_units/astronomical/light_minute.hpp index f0bd0956..6301745c 100644 --- a/include/boost/units/base_units/astronomical/light_minute.hpp +++ b/include/boost/units/base_units/astronomical/light_minute.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit struct base_unit_info { - static const char* name() { return("light minute"); } - static const char* symbol() { return("lmn"); } + static BOOST_CONSTEXPR const char* name() { return("light minute"); } + static BOOST_CONSTEXPR const char* symbol() { return("lmn"); } }; } // namespace units diff --git a/include/boost/units/base_units/astronomical/light_year.hpp b/include/boost/units/base_units/astronomical/light_year.hpp index e9e83a3a..f3434a79 100644 --- a/include/boost/units/base_units/astronomical/light_year.hpp +++ b/include/boost/units/base_units/astronomical/light_year.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit struct base_unit_info { - static const char* name() { return("light year"); } - static const char* symbol() { return("ly"); } + static BOOST_CONSTEXPR const char* name() { return("light year"); } + static BOOST_CONSTEXPR const char* symbol() { return("ly"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/drachm.hpp b/include/boost/units/base_units/imperial/drachm.hpp index 3dcc0240..b965040c 100644 --- a/include/boost/units/base_units/imperial/drachm.hpp +++ b/include/boost/units/base_units/imperial/drachm.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > drac template<> struct base_unit_info { - static const char* name() { return("drachm"); } - static const char* symbol() { return("drachm"); } + static BOOST_CONSTEXPR const char* name() { return("drachm"); } + static BOOST_CONSTEXPR const char* symbol() { return("drachm"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/fluid_ounce.hpp b/include/boost/units/base_units/imperial/fluid_ounce.hpp index 8bab33eb..b318fb2c 100644 --- a/include/boost/units/base_units/imperial/fluid_ounce.hpp +++ b/include/boost/units/base_units/imperial/fluid_ounce.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > fluid template<> struct base_unit_info { - static const char* name() { return("fluid ounce (imp.)"); } - static const char* symbol() { return("fl oz"); } + static BOOST_CONSTEXPR const char* name() { return("fluid ounce (imp.)"); } + static BOOST_CONSTEXPR const char* symbol() { return("fl oz"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/foot.hpp b/include/boost/units/base_units/imperial/foot.hpp index 149985e8..429c77c7 100644 --- a/include/boost/units/base_units/imperial/foot.hpp +++ b/include/boost/units/base_units/imperial/foot.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > foot_b template<> struct base_unit_info { - static const char* name() { return("foot"); } - static const char* symbol() { return("ft"); } + static BOOST_CONSTEXPR const char* name() { return("foot"); } + static BOOST_CONSTEXPR const char* symbol() { return("ft"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/furlong.hpp b/include/boost/units/base_units/imperial/furlong.hpp index 1d988214..8851f2c0 100644 --- a/include/boost/units/base_units/imperial/furlong.hpp +++ b/include/boost/units/base_units/imperial/furlong.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > furlo template<> struct base_unit_info { - static const char* name() { return("furlong"); } - static const char* symbol() { return("furlong"); } + static BOOST_CONSTEXPR const char* name() { return("furlong"); } + static BOOST_CONSTEXPR const char* symbol() { return("furlong"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/gallon.hpp b/include/boost/units/base_units/imperial/gallon.hpp index 6fd46538..c0e15136 100644 --- a/include/boost/units/base_units/imperial/gallon.hpp +++ b/include/boost/units/base_units/imperial/gallon.hpp @@ -29,8 +29,8 @@ typedef scaled_base_unit > > gallon_ template<> struct base_unit_info { - static const char* name() { return("gallon (imp.)"); } - static const char* symbol() { return("gal"); } + static BOOST_CONSTEXPR const char* name() { return("gallon (imp.)"); } + static BOOST_CONSTEXPR const char* symbol() { return("gal"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/gill.hpp b/include/boost/units/base_units/imperial/gill.hpp index 3e5b83af..353a46b4 100644 --- a/include/boost/units/base_units/imperial/gill.hpp +++ b/include/boost/units/base_units/imperial/gill.hpp @@ -29,8 +29,8 @@ typedef scaled_base_unit > > gill_b template<> struct base_unit_info { - static const char* name() { return("gill (imp.)"); } - static const char* symbol() { return("gill"); } + static BOOST_CONSTEXPR const char* name() { return("gill (imp.)"); } + static BOOST_CONSTEXPR const char* symbol() { return("gill"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/grain.hpp b/include/boost/units/base_units/imperial/grain.hpp index a36b4a4d..7567f991 100644 --- a/include/boost/units/base_units/imperial/grain.hpp +++ b/include/boost/units/base_units/imperial/grain.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > gr template<> struct base_unit_info { - static const char* name() { return("grain"); } - static const char* symbol() { return("grain"); } + static BOOST_CONSTEXPR const char* name() { return("grain"); } + static BOOST_CONSTEXPR const char* symbol() { return("grain"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/hundredweight.hpp b/include/boost/units/base_units/imperial/hundredweight.hpp index 6709a788..8f03763f 100644 --- a/include/boost/units/base_units/imperial/hundredweight.hpp +++ b/include/boost/units/base_units/imperial/hundredweight.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > hund template<> struct base_unit_info { - static const char* name() { return("hundredweight"); } - static const char* symbol() { return("cwt"); } + static BOOST_CONSTEXPR const char* name() { return("hundredweight"); } + static BOOST_CONSTEXPR const char* symbol() { return("cwt"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/inch.hpp b/include/boost/units/base_units/imperial/inch.hpp index 048d8c67..d39c3323 100644 --- a/include/boost/units/base_units/imperial/inch.hpp +++ b/include/boost/units/base_units/imperial/inch.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > inch_ template<> struct base_unit_info { - static const char* name() { return("inch"); } - static const char* symbol() { return("in"); } + static BOOST_CONSTEXPR const char* name() { return("inch"); } + static BOOST_CONSTEXPR const char* symbol() { return("in"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/league.hpp b/include/boost/units/base_units/imperial/league.hpp index 991e4b60..87c0cfb5 100644 --- a/include/boost/units/base_units/imperial/league.hpp +++ b/include/boost/units/base_units/imperial/league.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > leag template<> struct base_unit_info { - static const char* name() { return("league"); } - static const char* symbol() { return("league"); } + static BOOST_CONSTEXPR const char* name() { return("league"); } + static BOOST_CONSTEXPR const char* symbol() { return("league"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/mile.hpp b/include/boost/units/base_units/imperial/mile.hpp index d0d0fb5a..230537f5 100644 --- a/include/boost/units/base_units/imperial/mile.hpp +++ b/include/boost/units/base_units/imperial/mile.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > mile template<> struct base_unit_info { - static const char* name() { return("mile"); } - static const char* symbol() { return("mi"); } + static BOOST_CONSTEXPR const char* name() { return("mile"); } + static BOOST_CONSTEXPR const char* symbol() { return("mi"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/ounce.hpp b/include/boost/units/base_units/imperial/ounce.hpp index 8b9e33af..05bfcc15 100644 --- a/include/boost/units/base_units/imperial/ounce.hpp +++ b/include/boost/units/base_units/imperial/ounce.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > ounce template<> struct base_unit_info { - static const char* name() { return("ounce"); } - static const char* symbol() { return("oz"); } + static BOOST_CONSTEXPR const char* name() { return("ounce"); } + static BOOST_CONSTEXPR const char* symbol() { return("oz"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/quart.hpp b/include/boost/units/base_units/imperial/quart.hpp index 723ce0b4..f4c0a009 100644 --- a/include/boost/units/base_units/imperial/quart.hpp +++ b/include/boost/units/base_units/imperial/quart.hpp @@ -29,8 +29,8 @@ typedef scaled_base_unit > > quart_b template<> struct base_unit_info { - static const char* name() { return("quart (imp.)"); } - static const char* symbol() { return("qt"); } + static BOOST_CONSTEXPR const char* name() { return("quart (imp.)"); } + static BOOST_CONSTEXPR const char* symbol() { return("qt"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/quarter.hpp b/include/boost/units/base_units/imperial/quarter.hpp index 30f0594f..912d51d7 100644 --- a/include/boost/units/base_units/imperial/quarter.hpp +++ b/include/boost/units/base_units/imperial/quarter.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > quart template<> struct base_unit_info { - static const char* name() { return("quarter"); } - static const char* symbol() { return("quarter"); } + static BOOST_CONSTEXPR const char* name() { return("quarter"); } + static BOOST_CONSTEXPR const char* symbol() { return("quarter"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/stone.hpp b/include/boost/units/base_units/imperial/stone.hpp index b4ce4338..1b260a29 100644 --- a/include/boost/units/base_units/imperial/stone.hpp +++ b/include/boost/units/base_units/imperial/stone.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > stone template<> struct base_unit_info { - static const char* name() { return("stone"); } - static const char* symbol() { return("st"); } + static BOOST_CONSTEXPR const char* name() { return("stone"); } + static BOOST_CONSTEXPR const char* symbol() { return("st"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/thou.hpp b/include/boost/units/base_units/imperial/thou.hpp index eab2ac9e..af1f911e 100644 --- a/include/boost/units/base_units/imperial/thou.hpp +++ b/include/boost/units/base_units/imperial/thou.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > th template<> struct base_unit_info { - static const char* name() { return("thou"); } - static const char* symbol() { return("thou"); } + static BOOST_CONSTEXPR const char* name() { return("thou"); } + static BOOST_CONSTEXPR const char* symbol() { return("thou"); } }; } // namespace units diff --git a/include/boost/units/base_units/imperial/ton.hpp b/include/boost/units/base_units/imperial/ton.hpp index 867f1473..a1f709ec 100644 --- a/include/boost/units/base_units/imperial/ton.hpp +++ b/include/boost/units/base_units/imperial/ton.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > ton template<> struct base_unit_info { - static const char* name() { return("long ton"); } - static const char* symbol() { return("t"); } + static BOOST_CONSTEXPR const char* name() { return("long ton"); } + static BOOST_CONSTEXPR const char* symbol() { return("t"); } }; } // namespace units diff --git a/include/boost/units/base_units/information/byte.hpp b/include/boost/units/base_units/information/byte.hpp index 6cd9692d..6dcfde25 100644 --- a/include/boost/units/base_units/information/byte.hpp +++ b/include/boost/units/base_units/information/byte.hpp @@ -26,8 +26,8 @@ typedef scaled_base_unit struct base_unit_info { - static const char* name() { return("byte"); } - static const char* symbol() { return("B"); } + static BOOST_CONSTEXPR const char* name() { return("byte"); } + static BOOST_CONSTEXPR const char* symbol() { return("B"); } }; } // namespace units diff --git a/include/boost/units/base_units/information/shannon.hpp b/include/boost/units/base_units/information/shannon.hpp index b52bf7af..60e37b2c 100644 --- a/include/boost/units/base_units/information/shannon.hpp +++ b/include/boost/units/base_units/information/shannon.hpp @@ -26,8 +26,8 @@ typedef scaled_base_unit struct base_unit_info { - static const char* name() { return("shannon"); } - static const char* symbol() { return("Sh"); } + static BOOST_CONSTEXPR const char* name() { return("shannon"); } + static BOOST_CONSTEXPR const char* symbol() { return("Sh"); } }; } // namespace units diff --git a/include/boost/units/base_units/metric/angstrom.hpp b/include/boost/units/base_units/metric/angstrom.hpp index d2954e31..64cc3379 100644 --- a/include/boost/units/base_units/metric/angstrom.hpp +++ b/include/boost/units/base_units/metric/angstrom.hpp @@ -27,8 +27,8 @@ typedef scaled_base_unit struct base_unit_info { - static const char* name() { return("angstrom"); } - static const char* symbol() { return("A"); } + static BOOST_CONSTEXPR const char* name() { return("angstrom"); } + static BOOST_CONSTEXPR const char* symbol() { return("A"); } }; } diff --git a/include/boost/units/base_units/metric/day.hpp b/include/boost/units/base_units/metric/day.hpp index f8d83c8a..ac111c9e 100644 --- a/include/boost/units/base_units/metric/day.hpp +++ b/include/boost/units/base_units/metric/day.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit struct base_unit_info { - static const char* name() { return("day"); } - static const char* symbol() { return("d"); } + static BOOST_CONSTEXPR const char* name() { return("day"); } + static BOOST_CONSTEXPR const char* symbol() { return("d"); } }; } // namespace units diff --git a/include/boost/units/base_units/metric/fermi.hpp b/include/boost/units/base_units/metric/fermi.hpp index 8732c4ef..f12c903f 100644 --- a/include/boost/units/base_units/metric/fermi.hpp +++ b/include/boost/units/base_units/metric/fermi.hpp @@ -26,8 +26,8 @@ typedef scaled_base_unit struct base_unit_info { - static const char* name() { return("fermi"); } - static const char* symbol() { return("fm"); } + static BOOST_CONSTEXPR const char* name() { return("fermi"); } + static BOOST_CONSTEXPR const char* symbol() { return("fm"); } }; } diff --git a/include/boost/units/base_units/metric/hour.hpp b/include/boost/units/base_units/metric/hour.hpp index 443e2503..65657ce0 100644 --- a/include/boost/units/base_units/metric/hour.hpp +++ b/include/boost/units/base_units/metric/hour.hpp @@ -27,8 +27,8 @@ typedef scaled_base_unit struct base_unit_info { - static const char* name() { return("hour"); } - static const char* symbol() { return("h"); } + static BOOST_CONSTEXPR const char* name() { return("hour"); } + static BOOST_CONSTEXPR const char* symbol() { return("h"); } }; } diff --git a/include/boost/units/base_units/metric/micron.hpp b/include/boost/units/base_units/metric/micron.hpp index 09658360..c169cfdb 100644 --- a/include/boost/units/base_units/metric/micron.hpp +++ b/include/boost/units/base_units/metric/micron.hpp @@ -26,8 +26,8 @@ typedef scaled_base_unit struct base_unit_info { - static const char* name() { return("micron"); } - static const char* symbol() { return("u"); } + static BOOST_CONSTEXPR const char* name() { return("micron"); } + static BOOST_CONSTEXPR const char* symbol() { return("u"); } }; } diff --git a/include/boost/units/base_units/metric/minute.hpp b/include/boost/units/base_units/metric/minute.hpp index c2f9e6b3..3c0a68fc 100644 --- a/include/boost/units/base_units/metric/minute.hpp +++ b/include/boost/units/base_units/metric/minute.hpp @@ -27,8 +27,8 @@ typedef scaled_base_unit struct base_unit_info { - static const char* name() { return("minute"); } - static const char* symbol() { return("min"); } + static BOOST_CONSTEXPR const char* name() { return("minute"); } + static BOOST_CONSTEXPR const char* symbol() { return("min"); } }; } diff --git a/include/boost/units/base_units/metric/nautical_mile.hpp b/include/boost/units/base_units/metric/nautical_mile.hpp index d42dd77e..4f20951a 100644 --- a/include/boost/units/base_units/metric/nautical_mile.hpp +++ b/include/boost/units/base_units/metric/nautical_mile.hpp @@ -26,8 +26,8 @@ typedef scaled_base_unit struct base_unit_info { - static const char* name() { return("nautical mile"); } - static const char* symbol() { return("nmi"); } + static BOOST_CONSTEXPR const char* name() { return("nautical mile"); } + static BOOST_CONSTEXPR const char* symbol() { return("nmi"); } }; } diff --git a/include/boost/units/base_units/metric/ton.hpp b/include/boost/units/base_units/metric/ton.hpp index a842aaab..4f8e9643 100644 --- a/include/boost/units/base_units/metric/ton.hpp +++ b/include/boost/units/base_units/metric/ton.hpp @@ -29,8 +29,8 @@ typedef scaled_base_unit struct base_unit_info { - static const char* name() { return("metric ton"); } - static const char* symbol() { return("t"); } + static BOOST_CONSTEXPR const char* name() { return("metric ton"); } + static BOOST_CONSTEXPR const char* symbol() { return("t"); } }; } diff --git a/include/boost/units/base_units/metric/year.hpp b/include/boost/units/base_units/metric/year.hpp index e43acd6d..5d715e2d 100644 --- a/include/boost/units/base_units/metric/year.hpp +++ b/include/boost/units/base_units/metric/year.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit struct base_unit_info { - static const char* name() { return("Julian year"); } - static const char* symbol() { return("yr"); } + static BOOST_CONSTEXPR const char* name() { return("Julian year"); } + static BOOST_CONSTEXPR const char* symbol() { return("yr"); } }; } diff --git a/include/boost/units/base_units/us/cup.hpp b/include/boost/units/base_units/us/cup.hpp index f8113733..86b40832 100644 --- a/include/boost/units/base_units/us/cup.hpp +++ b/include/boost/units/base_units/us/cup.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > cup_ba template<> struct base_unit_info { - static const char* name() { return("cup"); } - static const char* symbol() { return("c"); } + static BOOST_CONSTEXPR const char* name() { return("cup"); } + static BOOST_CONSTEXPR const char* symbol() { return("c"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/dram.hpp b/include/boost/units/base_units/us/dram.hpp index 73fc44ff..29e08d9e 100644 --- a/include/boost/units/base_units/us/dram.hpp +++ b/include/boost/units/base_units/us/dram.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > dram template<> struct base_unit_info { - static const char* name() { return("dram (U.S.)"); } - static const char* symbol() { return("dr"); } + static BOOST_CONSTEXPR const char* name() { return("dram (U.S.)"); } + static BOOST_CONSTEXPR const char* symbol() { return("dr"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/fluid_dram.hpp b/include/boost/units/base_units/us/fluid_dram.hpp index cf0c85d3..0b9c60d7 100644 --- a/include/boost/units/base_units/us/fluid_dram.hpp +++ b/include/boost/units/base_units/us/fluid_dram.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > fluid_ template<> struct base_unit_info { - static const char* name() { return("fluid dram (U.S.)"); } - static const char* symbol() { return("fl dr"); } + static BOOST_CONSTEXPR const char* name() { return("fluid dram (U.S.)"); } + static BOOST_CONSTEXPR const char* symbol() { return("fl dr"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/fluid_ounce.hpp b/include/boost/units/base_units/us/fluid_ounce.hpp index 0c9d7e99..c7f0f07e 100644 --- a/include/boost/units/base_units/us/fluid_ounce.hpp +++ b/include/boost/units/base_units/us/fluid_ounce.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > fluid template<> struct base_unit_info { - static const char* name() { return("fluid ounce (U.S.)"); } - static const char* symbol() { return("fl oz"); } + static BOOST_CONSTEXPR const char* name() { return("fluid ounce (U.S.)"); } + static BOOST_CONSTEXPR const char* symbol() { return("fl oz"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/foot.hpp b/include/boost/units/base_units/us/foot.hpp index 4b529bb6..16cbf6d2 100644 --- a/include/boost/units/base_units/us/foot.hpp +++ b/include/boost/units/base_units/us/foot.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > foot_b template<> struct base_unit_info { - static const char* name() { return("foot"); } - static const char* symbol() { return("ft"); } + static BOOST_CONSTEXPR const char* name() { return("foot"); } + static BOOST_CONSTEXPR const char* symbol() { return("ft"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/gallon.hpp b/include/boost/units/base_units/us/gallon.hpp index a7314c58..1b54b28f 100644 --- a/include/boost/units/base_units/us/gallon.hpp +++ b/include/boost/units/base_units/us/gallon.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > gallon_ template<> struct base_unit_info { - static const char* name() { return("gallon (U.S.)"); } - static const char* symbol() { return("gal"); } + static BOOST_CONSTEXPR const char* name() { return("gallon (U.S.)"); } + static BOOST_CONSTEXPR const char* symbol() { return("gal"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/gill.hpp b/include/boost/units/base_units/us/gill.hpp index e9373439..c654386a 100644 --- a/include/boost/units/base_units/us/gill.hpp +++ b/include/boost/units/base_units/us/gill.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > gill_b template<> struct base_unit_info { - static const char* name() { return("gill (U.S.)"); } - static const char* symbol() { return("gi"); } + static BOOST_CONSTEXPR const char* name() { return("gill (U.S.)"); } + static BOOST_CONSTEXPR const char* symbol() { return("gi"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/grain.hpp b/include/boost/units/base_units/us/grain.hpp index e21baf69..485b6872 100644 --- a/include/boost/units/base_units/us/grain.hpp +++ b/include/boost/units/base_units/us/grain.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > gr template<> struct base_unit_info { - static const char* name() { return("grain"); } - static const char* symbol() { return("gr"); } + static BOOST_CONSTEXPR const char* name() { return("grain"); } + static BOOST_CONSTEXPR const char* symbol() { return("gr"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/hundredweight.hpp b/include/boost/units/base_units/us/hundredweight.hpp index 0bccd492..2ac991b9 100644 --- a/include/boost/units/base_units/us/hundredweight.hpp +++ b/include/boost/units/base_units/us/hundredweight.hpp @@ -29,8 +29,8 @@ typedef scaled_base_unit > > hund template<> struct base_unit_info { - static const char* name() { return("hundredweight (U.S.)"); } - static const char* symbol() { return("cwt"); } + static BOOST_CONSTEXPR const char* name() { return("hundredweight (U.S.)"); } + static BOOST_CONSTEXPR const char* symbol() { return("cwt"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/inch.hpp b/include/boost/units/base_units/us/inch.hpp index 05bd59a2..e7bd91da 100644 --- a/include/boost/units/base_units/us/inch.hpp +++ b/include/boost/units/base_units/us/inch.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > inch_ template<> struct base_unit_info { - static const char* name() { return("inch"); } - static const char* symbol() { return("in"); } + static BOOST_CONSTEXPR const char* name() { return("inch"); } + static BOOST_CONSTEXPR const char* symbol() { return("in"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/mil.hpp b/include/boost/units/base_units/us/mil.hpp index ee75b79a..e3276fe7 100644 --- a/include/boost/units/base_units/us/mil.hpp +++ b/include/boost/units/base_units/us/mil.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > mi template<> struct base_unit_info { - static const char* name() { return("mil"); } - static const char* symbol() { return("mil"); } + static BOOST_CONSTEXPR const char* name() { return("mil"); } + static BOOST_CONSTEXPR const char* symbol() { return("mil"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/mile.hpp b/include/boost/units/base_units/us/mile.hpp index d3513f13..c62c0d5f 100644 --- a/include/boost/units/base_units/us/mile.hpp +++ b/include/boost/units/base_units/us/mile.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > mile template<> struct base_unit_info { - static const char* name() { return("mile"); } - static const char* symbol() { return("mi"); } + static BOOST_CONSTEXPR const char* name() { return("mile"); } + static BOOST_CONSTEXPR const char* symbol() { return("mi"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/minim.hpp b/include/boost/units/base_units/us/minim.hpp index bf266cdb..d877e265 100644 --- a/include/boost/units/base_units/us/minim.hpp +++ b/include/boost/units/base_units/us/minim.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > min template<> struct base_unit_info { - static const char* name() { return("minim (U.S.)"); } - static const char* symbol() { return("minim"); } + static BOOST_CONSTEXPR const char* name() { return("minim (U.S.)"); } + static BOOST_CONSTEXPR const char* symbol() { return("minim"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/ounce.hpp b/include/boost/units/base_units/us/ounce.hpp index 5f88f838..9a4ec3e6 100644 --- a/include/boost/units/base_units/us/ounce.hpp +++ b/include/boost/units/base_units/us/ounce.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > ounce template<> struct base_unit_info { - static const char* name() { return("ounce"); } - static const char* symbol() { return("oz"); } + static BOOST_CONSTEXPR const char* name() { return("ounce"); } + static BOOST_CONSTEXPR const char* symbol() { return("oz"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/quart.hpp b/include/boost/units/base_units/us/quart.hpp index 45cf6a96..b39252a4 100644 --- a/include/boost/units/base_units/us/quart.hpp +++ b/include/boost/units/base_units/us/quart.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > quart_b template<> struct base_unit_info { - static const char* name() { return("quart (U.S.)"); } - static const char* symbol() { return("qt"); } + static BOOST_CONSTEXPR const char* name() { return("quart (U.S.)"); } + static BOOST_CONSTEXPR const char* symbol() { return("qt"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/tablespoon.hpp b/include/boost/units/base_units/us/tablespoon.hpp index f95f0a2b..43418ed3 100644 --- a/include/boost/units/base_units/us/tablespoon.hpp +++ b/include/boost/units/base_units/us/tablespoon.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > tables template<> struct base_unit_info { - static const char* name() { return("tablespoon"); } - static const char* symbol() { return("tbsp"); } + static BOOST_CONSTEXPR const char* name() { return("tablespoon"); } + static BOOST_CONSTEXPR const char* symbol() { return("tbsp"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/teaspoon.hpp b/include/boost/units/base_units/us/teaspoon.hpp index 8f8dd73d..94fe655b 100644 --- a/include/boost/units/base_units/us/teaspoon.hpp +++ b/include/boost/units/base_units/us/teaspoon.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > teasp template<> struct base_unit_info { - static const char* name() { return("teaspoon"); } - static const char* symbol() { return("tsp"); } + static BOOST_CONSTEXPR const char* name() { return("teaspoon"); } + static BOOST_CONSTEXPR const char* symbol() { return("tsp"); } }; } // namespace units diff --git a/include/boost/units/base_units/us/ton.hpp b/include/boost/units/base_units/us/ton.hpp index 84daa85a..d1f52e83 100644 --- a/include/boost/units/base_units/us/ton.hpp +++ b/include/boost/units/base_units/us/ton.hpp @@ -28,8 +28,8 @@ typedef scaled_base_unit > > ton template<> struct base_unit_info { - static const char* name() { return("short ton"); } - static const char* symbol() { return("t"); } + static BOOST_CONSTEXPR const char* name() { return("short ton"); } + static BOOST_CONSTEXPR const char* symbol() { return("t"); } }; } // namespace units diff --git a/include/boost/units/conversion.hpp b/include/boost/units/conversion.hpp index ab02e5bf..f5d4a1ef 100644 --- a/include/boost/units/conversion.hpp +++ b/include/boost/units/conversion.hpp @@ -158,8 +158,8 @@ namespace units { \ namespace namespace_ { \ struct name_ ## _base_unit \ : base_unit { \ - static const char* name() { return(name_string_); } \ - static const char* symbol() { return(symbol_string_); } \ + static BOOST_CONSTEXPR const char* name() { return(name_string_); } \ + static BOOST_CONSTEXPR const char* symbol() { return(symbol_string_); } \ }; \ } \ } \ diff --git a/test/test_output.cpp b/test/test_output.cpp index 011d78e2..fda15259 100644 --- a/test/test_output.cpp +++ b/test/test_output.cpp @@ -44,18 +44,18 @@ Tests for output from various units, name, symbol and raw formats, and automatic #include struct meter_base_unit : boost::units::base_unit { - static const char* name() { return("meter"); } - static const char* symbol() { return("m"); } + static BOOST_CONSTEXPR const char* name() { return("meter"); } + static BOOST_CONSTEXPR const char* symbol() { return("m"); } }; struct second_base_unit : boost::units::base_unit { - static const char* name() { return("second"); } - static const char* symbol() { return("s"); } + static BOOST_CONSTEXPR const char* name() { return("second"); } + static BOOST_CONSTEXPR const char* symbol() { return("s"); } }; struct byte_base_unit : boost::units::base_unit { - static const char* name() { return("byte"); } - static const char* symbol() { return("b"); } + static BOOST_CONSTEXPR const char* name() { return("byte"); } + static BOOST_CONSTEXPR const char* symbol() { return("b"); } }; typedef boost::units::make_system::type my_system; @@ -83,8 +83,8 @@ namespace boost { namespace units { template<> struct base_unit_info { - static const char* symbol() { return("scm"); } - static const char* name() { return("scaled_meter"); } + static BOOST_CONSTEXPR const char* symbol() { return("scm"); } + static BOOST_CONSTEXPR const char* name() { return("scaled_meter"); } }; } } @@ -98,8 +98,8 @@ std::string symbol_string(const custom1&) { return("c1"); } typedef boost::units::reduce_unit >::type custom2; -const char* name_string(const custom2&) { return("custom2"); } -const char* symbol_string(const custom2&) { return("c2"); } +BOOST_CONSTEXPR const char* name_string(const custom2&) { return("custom2"); } +BOOST_CONSTEXPR const char* symbol_string(const custom2&) { return("c2"); } typedef boost::units::make_scaled_unit > >::type scaled_custom1; typedef boost::units::make_scaled_unit > >::type scaled_custom2;