Boost logo

Boost Users :

Subject: [Boost-users] [phoenix] binding member_functions
From: Christian Henning (chhenning_at_[hidden])
Date: 2008-11-09 15:38:27

Hi there, I think there are some problems with binding functions if
the class has a const and a non-const version of the same member.
Please consider the following code:

#include <boost/spirit/include/phoenix_algorithm.hpp>
#include <boost/spirit/include/phoenix_bind.hpp>
#include <boost/spirit/include/phoenix_container.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_function.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_scope.hpp>
#include <boost/spirit/include/phoenix_statement.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>

#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;
using namespace boost::phoenix;
using namespace boost::phoenix::arg_names;

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

    double& prob() { return _prob; }
    double& x() { return _x; }

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

    void set_prob( const double& prob ) { _prob = prob; }
    void set_x ( const double& x ) { _x = x; }


    double _prob;
    double _x;

int _tmain(int argc, _TCHAR* argv[])
    typedef vector< point > distribution_t;

    distribution_t d( 1 );
    const distribution_t& dr = d;

    // works
    typedef const double& ( point::* pp_t )() const;
    double sum_prob = std::accumulate( dr.begin()
                                     , dr.end()
                                     , 0.0
                                     , arg1 + bind(
static_cast<pp_t>(&point::prob), arg2 )

    // doesn't work
    sum_prob = std::accumulate( dr.begin()
                              , dr.end()
                              , 0.0
                              , arg1 + bind( &point::prob, arg2 )

    return 0;

Only when I explicitly state which member phoenix is swallowing it. I
don't think that should be required.

Steven. When do you think you will apply the patches?


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at