Ticket #2227: boost_units_lambda_dimensionless_quantity.patch
File boost_units_lambda_dimensionless_quantity.patch, 4.2 KB (added by , 14 years ago) |
---|
-
boost/units/lambda.hpp
34 34 35 35 #include <boost/lambda/lambda.hpp> 36 36 #include <boost/units/units_fwd.hpp> 37 #include <boost/units/detail/dimensionless_unit.hpp> 37 38 #include <boost/units/operators.hpp> 38 39 39 40 namespace boost { … … 318 319 }; 319 320 320 321 /// 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 321 344 /// quantity<Unit1, X> - quantity<Unit2, Y>. 322 345 template<typename Unit1, typename X, typename Unit2, typename Y> 323 346 struct plain_return_type_2<arithmetic_action<minus_action>, … … 329 352 }; 330 353 331 354 /// 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 332 377 /// quantity<Unit1, X> * quantity<Unit2, Y>. 333 378 template<typename Unit1, typename X, typename Unit2, typename Y> 334 379 struct plain_return_type_2<arithmetic_action<multiply_action>, -
libs/units/test/test_lambda.cpp
142 142 // quantity<Unit1, X> + quantity<Unit2, Y> 143 143 BOOST_CHECK(((bl::_1 + bl::_2)(2.0 * bu::meter, 4.0 * bu::meter) == 6.0 * bu::meter)); 144 144 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 145 151 // quantity<Unit1, X> - quantity<Unit2, Y> 146 152 BOOST_CHECK(((bl::_1 - bl::_2)(2.0 * bu::meter, 4.0 * bu::meter) == -2.0 * bu::meter)); 147 153 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 148 160 // quantity<Unit1, X> * quantity<Unit2, Y> 149 161 BOOST_CHECK(((bl::_1 * bl::_2)(2.0 * bu::kilogram, 4.0 * bu::meter_per_second) == 8.0 * bu::kilogram * bu::meter_per_second)); 150 162