Re: [Boost-users] [proto] need explanation in implementing distributive law

,
Hi all, It is probably already been discovered by everyone at this point, but the code proposed by Andrew does not to work properly to apply distributivity more than once in an expression [works for a*(b+c) but not for a*(b+c*(d+c)) ] Here a modified version that seems to work recursively. How does it look? struct distr : proto::or_< proto::when< proto::multiplies< proto::_, proto::plus< proto::_, proto::_ > >, proto::call<distr( // THIS IS TO RECURSE proto::_make_plus( proto::_make_multiplies( proto::_left, proto::_left( proto::_right ) ), proto::_make_multiplies( proto::_left, proto::_right( proto::_right ) ) ) ) > proto::otherwise<proto::nary_expr<proto::_, proto::vararg<distr> > > > {}; Regards, Mauro. On 22.03.2010 22:11, Andrew Durward wrote:
As a follow-up, the attached code seems to compile and yield the expected result.
andrew
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On 10/5/2010 5:43 AM, Mauro Bianco wrote:
Hi all, It is probably already been discovered by everyone at this point, but the code proposed by Andrew does not to work properly to apply distributivity more than once in an expression [works for a*(b+c) but not for a*(b+c*(d+c)) ]
Funny, I never saw the original message. Perhaps it's stuck in a moderation queue or lost in the ether(net).
Here a modified version that seems to work recursively. How does it look?
,
struct distr : proto::or_< proto::when< proto::multiplies< proto::_, proto::plus< proto::_, proto::_ > >, proto::call<distr( // THIS IS TO RECURSE proto::_make_plus( proto::_make_multiplies( proto::_left, proto::_left( proto::_right ) ), proto::_make_multiplies( proto::_left, proto::_right( proto::_right ) ) ) ) > proto::otherwise<proto::nary_expr<proto::_, proto::vararg<distr> > > > {};
Yes, this looks reasonable. -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (2)
-
Eric Niebler
-
Mauro Bianco