Boost logo

Boost Users :

Subject: Re: [Boost-users] [Bind] Is this how to write it?
From: Michael Caisse (boost_at_[hidden])
Date: 2010-03-23 16:28:27


Robert Jones wrote:
>
>
> Thanks Ovanes - I'm sure you will understand that my real code is a
> bit more
> complicated then doubling ints! Since both bind and lambda are pretty
> much
> superceded by phoenix now, perhaps you could also supply the phoenix
> version?
>
> - Rob.

Rob -

I highly recommend moving to phoenix (despite comments made later in
this thread). The library is extremely powerful and stable and has been
conditionally accepted (
<http://lists.boost.org/boost-announce/2008/10/0205.php> ). The
documentation is excellent and the support is speedy. I find phoenix
constructs to be far more readable than boost.lambda resulting in
overall improved understanding of the code's intent.

Documentation can be found here:
<http://www.boost.org/doc/libs/1_42_0/libs/spirit/phoenix/doc/html/index.html>

Here is your example using phoenix -------------------

#include <iostream>
#include <vector>
#include <boost/spirit/include/phoenix.hpp>

int main()
{
   using namespace boost::phoenix::arg_names;
   std::vector< int > vec;

   // fill the vector with something
   for( int i=0; i < 10; ++i )
   {
      vec.push_back( i );
   }

   // double them all
   std::for_each( vec.begin(), vec.end(),
          ( arg1 *= 2 ) );

   // print them all out
   std::for_each( vec.begin(), vec.end(),
          ( std::cout << arg1 << " " ) );

   std::cout << std::endl;
  
   return 0;
}

--------------------------------------------------------------

Hope this helps some -
michael

-- 
----------------------------------
Michael Caisse
Object Modeling Designs
www.objectmodelingdesigns.com

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