Boost logo

Boost Users :

Subject: Re: [Boost-users] [phoenix][units] make boost.phoenix play well with boost.units
From: alfC (alfredo.correa_at_[hidden])
Date: 2010-06-06 04:53:51


On Jun 4, 5:55 pm, alfC <alfredo.cor..._at_[hidden]> wrote:
> > The type-deduction respects references. Phoenix2 passes in references.
> > The code should be:
>
> >    template<> //in general template<class XUnit, class YUnit>
> >    struct result_of_multiplies<quantity<si::length>&, quantity<si::length>&>
> >    {
> >        typedef quantity<si::area> type;
> >    };
>

Actually (unfortunately) it seems that all 4 combinations of reference/
no reference are needed.
This is the only way I managed to make these expression work with type
deduction:
arg1*arg1
(arg1*arg1)*arg1
arg1*(arg1*arg1)
(arg1*arg1)*(arg1*arg1)

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<class XUnit, class YUnit, class TX, class TY> \
        struct result_of_##PhoenixnamE <quantity<XUnit,TX> RefQ1,
quantity<YUnit,TY> RefQ2>{ \
                typedef typename
UnitsnamE##_typeof_helper<quantity<XUnit,TX>&,quantity<YUnit,TY>&
>::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
}}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net