Ticket #2227: boost_units_lambda_dimensionless_quantity.patch

File boost_units_lambda_dimensionless_quantity.patch, 4.2 KB (added by Torsten Maehne <Torsten.Maehne@…>, 14 years ago)

Patch for boost/units/lambda.hpp and libs/units/test/test_lambda.cpp

  • boost/units/lambda.hpp

     
    3434
    3535#include <boost/lambda/lambda.hpp>
    3636#include <boost/units/units_fwd.hpp>
     37#include <boost/units/detail/dimensionless_unit.hpp>
    3738#include <boost/units/operators.hpp>
    3839
    3940namespace boost {
     
    318319    };
    319320
    320321    /// Partial specialization of return type trait for action
     322    /// quantity<dimensionless, X> + Y.
     323    template<typename System, typename X, typename Y>
     324    struct plain_return_type_2<arithmetic_action<plus_action>,
     325                               boost::units::quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), X>,
     326                               Y> {
     327        typedef typename boost::units::add_typeof_helper<
     328            boost::units::quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), X>,
     329            Y>::type type;
     330    };
     331
     332    /// Partial specialization of return type trait for action
     333    /// X + quantity<dimensionless, Y>.
     334    template<typename System, typename X, typename Y>
     335    struct plain_return_type_2<arithmetic_action<plus_action>,
     336                               X,
     337                               boost::units::quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), Y> > {
     338        typedef typename boost::units::add_typeof_helper<
     339            X,
     340            boost::units::quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), Y> >::type type;
     341    };
     342
     343    /// Partial specialization of return type trait for action
    321344    /// quantity<Unit1, X> - quantity<Unit2, Y>.
    322345    template<typename Unit1, typename X, typename Unit2, typename Y>
    323346    struct plain_return_type_2<arithmetic_action<minus_action>,
     
    329352    };
    330353
    331354    /// Partial specialization of return type trait for action
     355    /// quantity<dimensionless, X> - Y.
     356    template<typename System, typename X, typename Y>
     357    struct plain_return_type_2<arithmetic_action<minus_action>,
     358                               boost::units::quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), X>,
     359                               Y> {
     360        typedef typename boost::units::subtract_typeof_helper<
     361            boost::units::quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), X>,
     362            Y>::type type;
     363    };
     364
     365    /// Partial specialization of return type trait for action
     366    /// X - quantity<dimensionless, Y>.
     367    template<typename System, typename X, typename Y>
     368    struct plain_return_type_2<arithmetic_action<minus_action>,
     369                               X,
     370                               boost::units::quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), Y> > {
     371        typedef typename boost::units::subtract_typeof_helper<
     372            X,
     373            boost::units::quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), Y> >::type type;
     374    };
     375
     376    /// Partial specialization of return type trait for action
    332377    /// quantity<Unit1, X> * quantity<Unit2, Y>.
    333378    template<typename Unit1, typename X, typename Unit2, typename Y>
    334379    struct plain_return_type_2<arithmetic_action<multiply_action>,
  • libs/units/test/test_lambda.cpp

     
    142142    // quantity<Unit1, X> + quantity<Unit2, Y>
    143143    BOOST_CHECK(((bl::_1 + bl::_2)(2.0 * bu::meter, 4.0 * bu::meter) == 6.0 * bu::meter));
    144144
     145    // quantity<dimensionless, X> + Y
     146    BOOST_CHECK(((bl::_1 + 1.0f)(bu::quantity<bu::dimensionless>(2.0)) == 3.0));
     147
     148    // X + quantity<dimensionless, Y>
     149    BOOST_CHECK(((1.0f + bl::_1)(bu::quantity<bu::dimensionless>(1.0)) == 2.0));
     150
    145151    // quantity<Unit1, X> - quantity<Unit2, Y>
    146152    BOOST_CHECK(((bl::_1 - bl::_2)(2.0 * bu::meter, 4.0 * bu::meter) == -2.0 * bu::meter));
    147153
     154    // quantity<dimensionless, X> - Y
     155    BOOST_CHECK(((bl::_1 - 2.0f)(bu::quantity<bu::dimensionless>(1.0)) == -1.0));
     156
     157    // X - quantity<dimensionless, Y>
     158    BOOST_CHECK(((2.0f - bl::_1)(bu::quantity<bu::dimensionless>(1.0)) == 1.0));
     159
    148160    // quantity<Unit1, X> * quantity<Unit2, Y>
    149161    BOOST_CHECK(((bl::_1 * bl::_2)(2.0 * bu::kilogram, 4.0 * bu::meter_per_second) == 8.0 * bu::kilogram * bu::meter_per_second));
    150162