|
Boost Users : |
Subject: Re: [Boost-users] [phoenix] accumulate with data member binding
From: Christian Henning (chhenning_at_[hidden])
Date: 2008-11-02 14:40:40
Thanks Joel. What does it mean when you say that arg1 is the state and
arg2 is the point? Also, looking in the phoenix documentation I see
that there is an accumulate version. How would I use that one in my
context?
Thanks,
Christian
On Fri, Oct 31, 2008 at 7:52 PM, Joel de Guzman <joel_at_[hidden]> wrote:
> Christian Henning wrote:
>>
>> Hi there, the following snippet doesn't compile which surprises me a
>> little. Could somebody tell what's wrong?
>>
>> #include <algorithm>
>> #include <vector>
>> #include <numeric>
>>
>> #include <boost/spirit/include/phoenix_core.hpp>
>> #include <boost/spirit/include/phoenix_operator.hpp>
>> #include <boost/spirit/include/phoenix_bind.hpp>
>>
>> using namespace boost::phoenix;
>> using namespace boost::phoenix::arg_names;
>> using namespace std;
>>
>> struct point
>> {
>> double _prob;
>> double _x;
>> };
>>
>> int _tmain(int argc, _TCHAR* argv[])
>> {
>> std::vector< point > d;
>>
>> double sum_prob = std::accumulate( d.begin()
>> , d.end()
>> , 0.0
>> , bind( &point::_prob, arg1 )
>> );
>>
>>
>> return 0;
>> }
>>
>> I'm using Visual Studio 2005. This is the error I'm getting:
>>
>> error C2296: '.*' : illegal, left operand has type 'double'
>
> Rightly so. arg1 is the state. arg2 is the point. You might want to
> try:
>
> bind( &point::_prob, arg2 )
>
> For example,
>
> bind( &point::_prob, arg2 ) + arg1
>
> adds all _prob(s)
>
> HTH.
>
> Regards,
> --
> Joel de Guzman
> http://www.boostpro.com
> http://spirit.sf.net
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
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