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-04 20:55:53


> 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;
> };

can you believe it?, I tried with 'const &' but not '&'!!!
Thank you so much for your help. Boost.Units and Boost.Interval will
be good benchmark test for the type deduction of Phoenix3
(what will be the magic of P3? use of typeof?)

Below it is a bridge code between phoenix2 and units.

Notes:
1) Not sure about the reference '&' in the typedefs, put them there
for symmetry.
2) result_of_plus/minus don't seem to be necessary
3) todo: overload operator*(actor<T>, quantity<...>) and
operator*(actor<T>, unit<...>) and reversed to overcome ambiguity on
operator*.
4) todo: specialize *=, /=
5) I wish this be in boost/units/phoenix2.hpp.

// phoenix2 units bridge, result_of_plus/minus don't seem to be
necesary, todo: *=, /=
namespace boost{
namespace phoenix{
using namespace boost::units;
template<class XUnit, class YUnit, class TX, class TY>
struct result_of_multiplies<quantity<XUnit,TX>&, quantity<YUnit,TY>&>{
       typedef typename
multiply_typeof_helper<quantity<XUnit,TX>&,quantity<YUnit,TY>& >::type
type;
};
template<class X, class YUnit,class TY>
struct result_of_multiplies<X&, quantity<YUnit,TY>&>{
       typedef typename multiply_typeof_helper<X&,quantity<YUnit,TY>&
>::type type;
};
template<class XUnit, class Y, class TX>
struct result_of_multiplies<quantity<XUnit,TX>&, Y&>{
       typedef typename multiply_typeof_helper<quantity<XUnit,TX>&,Y&
>::type type;
};
template<class XUnit, class YUnit , class TX, class TY>
struct result_of_divides<quantity<XUnit>&, quantity<YUnit>&>{
       typedef typename
divide_typeof_helper<quantity<XUnit,TX>&,quantity<YUnit,TY>& >::type
type;
};
template<class X, class YUnit>
struct result_of_divides<X&, quantity<YUnit,TY>&>{
       typedef typename divide_typeof_helper<X&,quantity<YUnit,TY>&
>::type type;
};
template<class XUnit, class Y>
struct result_of_divides<quantity<XUnit,TX>&, Y&>{
       typedef typename divide_typeof_helper<quantity<XUnit,TX>&,
Y&>::type type;
};
}}


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