Boost logo

Boost Users :

Subject: Re: [Boost-users] [phoenix] Basic recursive function.
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2011-04-13 16:41:32


On Wed, Apr 13, 2011 at 8:04 PM, Thomas Heller
<thom.heller_at_[hidden]>wrote:

>
> Phoenix V3 (from trunk) has experimental support for recursing into itself:
> #include <boost/phoenix/core.hpp>
> #include <boost/phoenix/scope/this.hpp>
> #include <boost/phoenix/statement.hpp>
> #include <boost/phoenix/operator.hpp>
> #include <boost/phoenix/scope.hpp>
>
> #include <boost/function.hpp>
>
> #include <iostream>
>
> int main()
> {
> using boost::phoenix::_this;
> using boost::phoenix::arg_names::_1;
>
> boost::function<unsigned(unsigned)> factorial
> = if_else(
> _1 <= 1
> , 1
> , _1 * _this(_1 - 1)
> );
> std::cout << factorial( 3 ) << std::endl;
> }
>
> Have fun playing with it ;)
> I don't accept bugfixes for this feature cause i know it is not working in
> every
> case ... still needs a little work.
> If you encounter compile errors, add some dummy phoenix expression at the
> end of
> the recursing branch.
>
>
Thanks Thomas - It's sufficient to know that what I'm trying to
do is a basic limitation of the library. Cutting edge experimental
stuff is fun for me, but not really an option at work!

Cheers, Rob.



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