Boost logo

Boost Users :

Subject: [Boost-users] [phoenix] adding const to member_variable bind
From: Christian Henning (chhenning_at_[hidden])
Date: 2008-11-04 14:28:44


Hi there, the following code doesn't compile since I'm iterating over
a constant vector of points.

struct point
{
    double _prob;
    double _x;
};

void test( const std::vector< point >& d )
{
    double sum_prob = std::accumulate( d.begin()
                                     , d.end()
                                     , 0.0
                                     , arg1 + bind( &point::_prob, arg2 )
                                     );
}

int _tmain(int argc, _TCHAR* argv[])
{
    std::vector< point > d;
    test( d );

    return 0;
}

My question is how can I convert or cast the "&point::_prob" into a
const reference? I tried several ways but they all don't work. The
only thing that worked was to add const getter function in my point
structure. Like this:

struct point
{
    point( double prob, double x ) : _prob( prob ), _x( x ) {}

    const double& prob() const { return _prob; }

    double _prob;
    double _x;
};

Thanks,
Christian


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