|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r78342 - in branches/release: . boost boost/units boost/units/detail boost/units/systems/detail libs libs/units/test
From: steven_at_[hidden]
Date: 2012-05-05 17:45:24
Author: steven_watanabe
Date: 2012-05-05 17:45:23 EDT (Sat, 05 May 2012)
New Revision: 78342
URL: http://svn.boost.org/trac/boost/changeset/78342
Log:
Merge units from the trunk.
Properties modified:
branches/release/ (props changed)
branches/release/boost/ (props changed)
branches/release/libs/ (props changed)
Text files modified:
branches/release/boost/units/conversion.hpp | 6 ++-
branches/release/boost/units/detail/one.hpp | 11 ++++++
branches/release/boost/units/detail/static_rational_power.hpp | 4 +-
branches/release/boost/units/quantity.hpp | 36 +++++++++++++++++++++
branches/release/boost/units/systems/detail/constants.hpp | 68 ++++++++++++++++++++++++++++++++++++++++
branches/release/libs/units/test/test_constants.cpp | 13 +++++++
branches/release/libs/units/test/test_conversion.cpp | 2 +
7 files changed, 136 insertions(+), 4 deletions(-)
Modified: branches/release/boost/units/conversion.hpp
==============================================================================
--- branches/release/boost/units/conversion.hpp (original)
+++ branches/release/boost/units/conversion.hpp 2012-05-05 17:45:23 EDT (Sat, 05 May 2012)
@@ -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: branches/release/boost/units/detail/one.hpp
==============================================================================
--- branches/release/boost/units/detail/one.hpp (original)
+++ branches/release/boost/units/detail/one.hpp 2012-05-05 17:45:23 EDT (Sat, 05 May 2012)
@@ -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: branches/release/boost/units/detail/static_rational_power.hpp
==============================================================================
--- branches/release/boost/units/detail/static_rational_power.hpp (original)
+++ branches/release/boost/units/detail/static_rational_power.hpp 2012-05-05 17:45:23 EDT (Sat, 05 May 2012)
@@ -93,7 +93,7 @@
typedef typename next::type type;
static type call(const Y& y, const R& r)
{
- const Y square = y * y;
+ const square_type square = y * y;
return(next::call(square, r));
}
};
@@ -185,7 +185,7 @@
{
typedef typename static_int_power_sign_impl<N>::template apply<Y> impl;
typedef typename impl::type type;
- static Y call(const Y& y)
+ static type call(const Y& y)
{
return(impl::call(y));
}
Modified: branches/release/boost/units/quantity.hpp
==============================================================================
--- branches/release/boost/units/quantity.hpp (original)
+++ branches/release/boost/units/quantity.hpp 2012-05-05 17:45:23 EDT (Sat, 05 May 2012)
@@ -680,6 +680,15 @@
typedef quantity<unit_type,value_type> type;
};
+/// disambiguate
+/// INTERNAL ONLY
+template<class Unit,
+ class Y>
+struct multiply_typeof_helper< one,quantity<Unit,Y> >
+{
+ typedef quantity<Unit,Y> type;
+};
+
/// quantity times scalar typeof helper
/// INTERNAL ONLY
template<class Unit,
@@ -692,6 +701,15 @@
typedef quantity<unit_type,value_type> type;
};
+/// disambiguate
+/// INTERNAL ONLY
+template<class Unit,
+ class X>
+struct multiply_typeof_helper< quantity<Unit,X>,one >
+{
+ typedef quantity<Unit,X> type;
+};
+
/// unit times quantity typeof helper
/// INTERNAL ONLY
template<class Unit,
@@ -767,6 +785,15 @@
typedef quantity<unit_type,value_type> type;
};
+/// disambiguate
+/// INTERNAL ONLY
+template<class Unit,
+ class Y>
+struct divide_typeof_helper< one,quantity<Unit,Y> >
+{
+ typedef quantity<Unit,Y> type;
+};
+
/// quantity divided by scalar typeof helper
/// INTERNAL ONLY
template<class Unit,
@@ -779,6 +806,15 @@
typedef quantity<unit_type,value_type> type;
};
+/// disambiguate
+/// INTERNAL ONLY
+template<class Unit,
+ class X>
+struct divide_typeof_helper< quantity<Unit,X>,one >
+{
+ typedef quantity<Unit,X> type;
+};
+
/// unit divided by quantity typeof helper
/// INTERNAL ONLY
template<class Unit,
Modified: branches/release/boost/units/systems/detail/constants.hpp
==============================================================================
--- branches/release/boost/units/systems/detail/constants.hpp (original)
+++ branches/release/boost/units/systems/detail/constants.hpp 2012-05-05 17:45:23 EDT (Sat, 05 May 2012)
@@ -20,6 +20,8 @@
#include <boost/units/static_constant.hpp>
#include <boost/units/units_fwd.hpp>
#include <boost/units/operators.hpp>
+#include <boost/units/static_rational.hpp>
+#include <boost/units/detail/one.hpp>
namespace boost {
@@ -134,6 +136,72 @@
#undef BOOST_UNITS_DEFINE_HELPER
+#define BOOST_UNITS_DEFINE_HELPER(name, symbol) \
+ \
+template<class T1> \
+struct name ## _typeof_helper<constant<T1>, one> \
+{ \
+ typedef typename name ## _typeof_helper<typename T1::value_type, one>::type type;\
+}; \
+ \
+template<class T2> \
+struct name ## _typeof_helper<one, constant<T2> > \
+{ \
+ typedef typename name ## _typeof_helper<one, typename T2::value_type>::type type;\
+}; \
+ \
+template<class T1> \
+typename name ## _typeof_helper<typename T1::value_type, one>::type \
+operator symbol(const constant<T1>& t, const one& u) \
+{ \
+ return(t.value() symbol u); \
+} \
+ \
+template<class T2> \
+typename name ## _typeof_helper<one, typename T2::value_type>::type \
+operator symbol(const one& t, const constant<T2>& u) \
+{ \
+ return(t symbol u.value()); \
+}
+
+BOOST_UNITS_DEFINE_HELPER(multiply, *)
+BOOST_UNITS_DEFINE_HELPER(divide, /)
+
+#undef BOOST_UNITS_DEFINE_HELPER
+
+template<class T1, long N, long D>
+struct power_typeof_helper<constant<T1>, static_rational<N,D> >
+{
+ typedef power_typeof_helper<typename T1::value_type, static_rational<N,D> > base;
+ typedef typename base::type type;
+ static type value(const constant<T1>& arg)
+ {
+ return base::value(arg.value());
+ }
+};
+
+#define BOOST_UNITS_DEFINE_HELPER(name, symbol) \
+ \
+template<class T1, class E> \
+struct name ## _typeof_helper<constant<T1> > \
+{ \
+ typedef typename name ## _typeof_helper<typename T1::value_type, E>::type type;\
+}; \
+ \
+template<class T1> \
+typename name ## _typeof_helper<typename T1::value_type, one>::type \
+operator symbol(const constant<T1>& t, const one& u) \
+{ \
+ return(t.value() symbol u); \
+} \
+ \
+template<class T2> \
+typename name ## _typeof_helper<one, typename T2::value_type>::type \
+operator symbol(const one& t, const constant<T2>& u) \
+{ \
+ return(t symbol u.value()); \
+}
+
#define BOOST_UNITS_PHYSICAL_CONSTANT(name, type, value_, uncertainty_) \
struct name ## _t { \
typedef type value_type; \
Modified: branches/release/libs/units/test/test_constants.cpp
==============================================================================
--- branches/release/libs/units/test/test_constants.cpp (original)
+++ branches/release/libs/units/test/test_constants.cpp 2012-05-05 17:45:23 EDT (Sat, 05 May 2012)
@@ -20,6 +20,7 @@
#include <boost/units/systems/detail/constants.hpp>
#include <boost/units/quantity.hpp>
+#include <boost/units/pow.hpp>
#include <boost/units/systems/si/length.hpp>
#include <boost/units/systems/si/time.hpp>
@@ -27,6 +28,9 @@
using boost::units::si::length;
using boost::units::si::meters;
using boost::units::si::seconds;
+using boost::units::static_rational;
+using boost::units::pow;
+using boost::units::root;
BOOST_UNITS_PHYSICAL_CONSTANT(length_constant, quantity<length>, 2.0 * meters, 0.5 * meters);
@@ -72,3 +76,12 @@
BOOST_UNITS_CHECK_RESULT(length_constant, /, seconds);
BOOST_UNITS_CHECK_RESULT(seconds, /, length_constant);
}
+
+void test_pow() {
+ check_same(pow<2>(length_constant), pow<2>(unwrap(length_constant)));
+ check_same(root<2>(length_constant), root<2>(unwrap(length_constant)));
+ check_same(pow<5>(length_constant), pow<5>(unwrap(length_constant)));
+ check_same(root<5>(length_constant), root<5>(unwrap(length_constant)));
+ check_same(pow<static_rational<2, 3> >(length_constant), pow<static_rational<2, 3> >(unwrap(length_constant)));
+ check_same(root<static_rational<2, 3> >(length_constant), root<static_rational<2, 3> >(unwrap(length_constant)));
+}
Modified: branches/release/libs/units/test/test_conversion.cpp
==============================================================================
--- branches/release/libs/units/test/test_conversion.cpp (original)
+++ branches/release/libs/units/test/test_conversion.cpp 2012-05-05 17:45:23 EDT (Sat, 05 May 2012)
@@ -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