Boost logo

Boost Users :

Subject: Re: [Boost-users] [phoenix] another problem with member_variable bind
From: Christian Henning (chhenning_at_[hidden])
Date: 2008-11-07 17:55:25


Ok, my bad. What would be your solution?

For instance, I changed over to std::for_each but still need a
separate function to do the actual multiplication plus assignment.

struct point
{
    double _prob;
    double _x;
};

void mul_assign( double& l, const double& f )
{
    l *= f;
}

int _tmain(int argc, _TCHAR* argv[])
{
    using namespace std;
    using namespace boost::phoenix;
    using namespace boost::phoenix::arg_names;

    vector< point > points( 1 );

    std::for_each( points.begin()
                 , points.end()
                 , bind( &mul_assign, bind( &point::_prob, arg1 ), 2.0 )
                 );

    return 0;
}

Is there a way I could get rid off "mul_assign"?

Thanks,
Christian

On Fri, Nov 7, 2008 at 4:19 PM, Steven Watanabe <watanabesj_at_[hidden]> wrote:
> AMDG
>
> Christian Henning wrote:
>>
>> vector< point > points;
>>
>> // doesn't work
>> std::transform( points.begin()
>> , points.end()
>> , points.begin()
>> , bind( &point::_prob, arg1 ) * val( 2.0 )
>> );
>>
>
> Certainly, it won't work. You're code does the equivalent of:
>
> points[i] = points[i]._prob * 2.0
>
> In Christ,
> Steven Watanabe
>
> _______________________________________________
> 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