Boost logo

Boost Users :

Subject: Re: [Boost-users] [phoenix] accumulate with data member binding
From: Joel de Guzman (joel_at_[hidden])
Date: 2008-11-02 21:51:03


Christian Henning wrote:
> Thanks Joel. What does it mean when you say that arg1 is the state and
> arg2 is the point?

std::accumulate expects a binary function f, with the first arg being
the state. In your example, that is the double you passed initially
with value 0.0. This is your "accumulator". The second arg (arg2) is
the reference to the element in your stl container (a reference to a
point).

Also, looking in the phoenix documentation I see
> that there is an accumulate version. How would I use that one in my
> context?

See spirit/phoenix/test/algorithm for some examples. For example:

     void accumulate_test()
     {
         using namespace boost::phoenix;
         using namespace boost::phoenix::arg_names;
         int array[] = {1,2,3};
         BOOST_TEST(accumulate(arg1, 0)(array) == 6);
         BOOST_TEST(boost::phoenix::accumulate(
             arg1, 0, std::minus<int>())(array) == -6);
         return;
     }

HTH.

Regards,

-- 
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net

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