|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r74159 - in trunk: boost/units boost/units/detail libs/units/test
From: steven_at_[hidden]
Date: 2011-08-30 11:07:49
Author: steven_watanabe
Date: 2011-08-30 11:07:48 EDT (Tue, 30 Aug 2011)
New Revision: 74159
URL: http://svn.boost.org/trac/boost/changeset/74159
Log:
Never return one from conversion_factor.
Text files modified:
trunk/boost/units/conversion.hpp | 6 ++++--
trunk/boost/units/detail/one.hpp | 11 +++++++++++
trunk/libs/units/test/test_conversion.cpp | 2 ++
3 files changed, 17 insertions(+), 2 deletions(-)
Modified: trunk/boost/units/conversion.hpp
==============================================================================
--- trunk/boost/units/conversion.hpp (original)
+++ trunk/boost/units/conversion.hpp 2011-08-30 11:07:48 EDT (Tue, 30 Aug 2011)
@@ -170,10 +170,12 @@
/// Find the conversion factor between two units.
template<class FromUnit,class ToUnit>
inline
-typename detail::conversion_factor_helper<FromUnit, ToUnit>::type
+typename one_to_double_type<
+ typename detail::conversion_factor_helper<FromUnit, ToUnit>::type
+>::type
conversion_factor(const FromUnit&,const ToUnit&)
{
- return(detail::conversion_factor_helper<FromUnit, ToUnit>::value());
+ return(one_to_double(detail::conversion_factor_helper<FromUnit, ToUnit>::value()));
}
} // namespace units
Modified: trunk/boost/units/detail/one.hpp
==============================================================================
--- trunk/boost/units/detail/one.hpp (original)
+++ trunk/boost/units/detail/one.hpp 2011-08-30 11:07:48 EDT (Tue, 30 Aug 2011)
@@ -102,6 +102,17 @@
return(1 > t);
}
+template<class T>
+T one_to_double(const T& t) { return t; }
+
+inline double one_to_double(const one&) { return 1.0; }
+
+template<class T>
+struct one_to_double_type { typedef T type; };
+
+template<>
+struct one_to_double_type<one> { typedef double type; };
+
} // namespace units
} // namespace boost
Modified: trunk/libs/units/test/test_conversion.cpp
==============================================================================
--- trunk/libs/units/test/test_conversion.cpp (original)
+++ trunk/libs/units/test/test_conversion.cpp 2011-08-30 11:07:48 EDT (Tue, 30 Aug 2011)
@@ -82,6 +82,8 @@
bu::quantity<bu::si::force> F5(20 * bu::cgs::dyne);
BOOST_UNITS_CHECK_CLOSE(F5.value(), 2.0e-4);
+ // same type
+ BOOST_CHECK_EQUAL(boost::units::conversion_factor(si_length(), si_length()), 1.0);
}
BOOST_AUTO_TEST_CASE(test_dimensionless_conversions) {
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk