# [SOLVED] boost::mem_fn, boost::bind, std::remove_if problem

This topic is 3772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm experimenting with some complicated concepts that neither I nor my faithful C++ book have dared to touch. ;) Sorry if this sounds noob-ish, but it's my first time attempting to understand it. Here's an example of what I'm trying to do (based off the example code on boost.org)...
class ent_base
{
public:
virtual bool step( const double &delta_time ) = 0;
virtual void draw( const double &interpolate_factor ) = 0;
};

class game
{
private:
boost::ptr_list<ent_base> m_objects;

public:
void draw( const double &interpolate_factor )
{
// This is simple enough :)  Call draw(interpolate_factor) for each object
std::for_each( m_objects.begin(), m_objects.end(), boost::bind( &ent_base::draw, _1, interpolate_factor ) );
}

bool step( const double &delta_time )
{
// This should work... :(  Call step(delta_time) for each object and remove it when the function returns true
// Why doesn't this work? (C2582: 'operator =' is unavailable in 'ent_base')
m_objects.erase( std::remove_if( m_objects.begin(), m_objects.end(), boost::bind( &ent_base::step, _1, dt ) ), m_objects.end() );
}
};


The problem is, I don't know why it's trying to ent_base::operator=, and I don't think I want it to! _fastcall

##### Share on other sites
This comes from the nature of boost::ptr_list iterator, whose value type is ent_base instead of ent_base*. Since remove_if moves elements around through assignment, it will thus use ent_base::operator=.

To avoid this issue, use boost::ptr_list::erase_if.

##### Share on other sites
m_objects.erase_if( boost::bind( &ent_base::step, _1, delta_time ) );

1. 1
2. 2
3. 3
Rutin
21
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631778
• Total Posts
3002308
×