
On Jun 4, 5:55 pm, alfC
wrote: So, I have to implement this kind of macro sorcery to bridge Boost.Units and Boost.Phoenix. Not sure if I will find another bump in the road: namespace boost{ namespace phoenix{ using namespace boost::units; #define RESULT_OF_GEN( PhoenixnamE, UnitsnamE, RefQ1, RefQ2 ) \ template
\ struct result_of_##PhoenixnamE RefQ1, quantity RefQ2>{ \ typedef typename UnitsnamE##_typeof_helper &,quantity & ::type type; \ }; RESULT_OF_GEN(multiplies, multiply, &, ) RESULT_OF_GEN(multiplies, multiply, &, &) RESULT_OF_GEN(multiplies, multiply, , ) RESULT_OF_GEN(multiplies, multiply, , &) RESULT_OF_GEN(divides , divide , &, ) RESULT_OF_GEN(divides , divide , &, &) RESULT_OF_GEN(divides , divide , , ) RESULT_OF_GEN(divides , divide , , &) #undef RESULT_OF_GEN }}
On top of what is above, I had to add the code below in order to be
able to use Phoenix in this context:
using namespace boost::units;
using namespace boost::phoenix;
using namespace boost::phoenix::arg_names;
...
boost::function
{ \ typedef \ typename boost::units::UnitsopnamE##_typeof_helper< \ boost::units::quantity
, boost::units::unit \ >::type type; \ }; RESULT_OF_QUANTITY_UNITS_GEN(multiplies, multiply) RESULT_OF_QUANTITY_UNITS_GEN(divides , divide ) #undef RESULT_OF_QUANTITY_UNITS_GEN
// this refines the operator* so the phoenix:;operator* is used instead of units::operator* #define REFINE_ARITHMETIC_OPERATORS(PhoenixopnamE, CsymboL) \ template< \ class PhoenixExpr, \ class System, \ class Dim \
\ actor< \ composite< \ PhoenixopnamE##_eval, \ boost::fusion::vector< \ PhoenixExpr, \ value< \ boost::units::unit
\ > \ > \ \ \ operator CsymboL (const actor<PhoenixExpr>& lhs, const unit
& rhs){ \ return compose (lhs, rhs); \ } REFINE_ARITHMETIC_OPERATORS(multiplies, *) REFINE_ARITHMETIC_OPERATORS(divides, /) #undef REFINE_ARITHMETIC_OPERATORS }}