|
Boost-Commit : |
From: boost_at_[hidden]
Date: 2008-08-19 14:45:18
Author: matthiasschabel
Date: 2008-08-19 14:45:17 EDT (Tue, 19 Aug 2008)
New Revision: 48226
URL: http://svn.boost.org/trac/boost/changeset/48226
Log:
patch from Torsten Maehne for using dimensionless quantities with boost/units/lambda.hpp
Text files modified:
trunk/boost/units/lambda.hpp | 45 ++++++++++++++++++++++++++++++++++++++++
trunk/libs/units/test/test_lambda.cpp | 12 ++++++++++
2 files changed, 57 insertions(+), 0 deletions(-)
Modified: trunk/boost/units/lambda.hpp
==============================================================================
--- trunk/boost/units/lambda.hpp (original)
+++ trunk/boost/units/lambda.hpp 2008-08-19 14:45:17 EDT (Tue, 19 Aug 2008)
@@ -34,6 +34,7 @@
#include <boost/lambda/lambda.hpp>
#include <boost/units/units_fwd.hpp>
+#include <boost/units/detail/dimensionless_unit.hpp>
#include <boost/units/operators.hpp>
namespace boost {
@@ -318,6 +319,28 @@
};
/// Partial specialization of return type trait for action
+ /// quantity<dimensionless, X> + Y.
+ template<typename System, typename X, typename Y>
+ struct plain_return_type_2<arithmetic_action<plus_action>,
+ boost::units::quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), X>,
+ Y> {
+ typedef typename boost::units::add_typeof_helper<
+ boost::units::quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), X>,
+ Y>::type type;
+ };
+
+ /// Partial specialization of return type trait for action
+ /// X + quantity<dimensionless, Y>.
+ template<typename System, typename X, typename Y>
+ struct plain_return_type_2<arithmetic_action<plus_action>,
+ X,
+ boost::units::quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), Y> > {
+ typedef typename boost::units::add_typeof_helper<
+ X,
+ boost::units::quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), Y> >::type type;
+ };
+
+ /// Partial specialization of return type trait for action
/// quantity<Unit1, X> - quantity<Unit2, Y>.
template<typename Unit1, typename X, typename Unit2, typename Y>
struct plain_return_type_2<arithmetic_action<minus_action>,
@@ -329,6 +352,28 @@
};
/// Partial specialization of return type trait for action
+ /// quantity<dimensionless, X> - Y.
+ template<typename System, typename X, typename Y>
+ struct plain_return_type_2<arithmetic_action<minus_action>,
+ boost::units::quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), X>,
+ Y> {
+ typedef typename boost::units::subtract_typeof_helper<
+ boost::units::quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), X>,
+ Y>::type type;
+ };
+
+ /// Partial specialization of return type trait for action
+ /// X - quantity<dimensionless, Y>.
+ template<typename System, typename X, typename Y>
+ struct plain_return_type_2<arithmetic_action<minus_action>,
+ X,
+ boost::units::quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), Y> > {
+ typedef typename boost::units::subtract_typeof_helper<
+ X,
+ boost::units::quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), Y> >::type type;
+ };
+
+ /// Partial specialization of return type trait for action
/// quantity<Unit1, X> * quantity<Unit2, Y>.
template<typename Unit1, typename X, typename Unit2, typename Y>
struct plain_return_type_2<arithmetic_action<multiply_action>,
Modified: trunk/libs/units/test/test_lambda.cpp
==============================================================================
--- trunk/libs/units/test/test_lambda.cpp (original)
+++ trunk/libs/units/test/test_lambda.cpp 2008-08-19 14:45:17 EDT (Tue, 19 Aug 2008)
@@ -142,9 +142,21 @@
// quantity<Unit1, X> + quantity<Unit2, Y>
BOOST_CHECK(((bl::_1 + bl::_2)(2.0 * bu::meter, 4.0 * bu::meter) == 6.0 * bu::meter));
+ // quantity<dimensionless, X> + Y
+ BOOST_CHECK(((bl::_1 + 1.0f)(bu::quantity<bu::dimensionless>(2.0)) == 3.0));
+
+ // X + quantity<dimensionless, Y>
+ BOOST_CHECK(((1.0f + bl::_1)(bu::quantity<bu::dimensionless>(1.0)) == 2.0));
+
// quantity<Unit1, X> - quantity<Unit2, Y>
BOOST_CHECK(((bl::_1 - bl::_2)(2.0 * bu::meter, 4.0 * bu::meter) == -2.0 * bu::meter));
+ // quantity<dimensionless, X> - Y
+ BOOST_CHECK(((bl::_1 - 2.0f)(bu::quantity<bu::dimensionless>(1.0)) == -1.0));
+
+ // X - quantity<dimensionless, Y>
+ BOOST_CHECK(((2.0f - bl::_1)(bu::quantity<bu::dimensionless>(1.0)) == 1.0));
+
// quantity<Unit1, X> * quantity<Unit2, Y>
BOOST_CHECK(((bl::_1 * bl::_2)(2.0 * bu::kilogram, 4.0 * bu::meter_per_second) == 8.0 * bu::kilogram * bu::meter_per_second));
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