0

ALL,

It's continuation of this thread.

What I tried is to write following code:

struct Remover : public std::binary_function<CPlayer,void,bool>
{
public:
    bool operator()(const CPlayer &player) const
    {
        return player.IsNewPlayer();
    }
};

and call it this way:

players_pool->erase( std::remove_if( players_pool->begin(), players_pool->end(), std::bind2nd( Remover() ) ) );

but it gives me an error:

std::bind2nd(): expects 2 arguments - 1 provided.

How do I properly call this functor?

Thank you.

Community
  • 1
  • 1
Igor
  • 5,620
  • 11
  • 51
  • 103

2 Answers2

3

You don't need to wrap Remover() in std::bind2nd().

Also, you don't need to derive from std::binary_function<> (which is wrong, anyway; Remover is a unary functor). You don't need to derive from anything, in fact.

Finally, if your compiler supports C++11, you can reduce your code down to this:

players_pool->erase( std::remove_if( begin(*players_pool), end(*players_pool),
                                     [](const CPlayer &player) {
                                         return player.IsNewPlayer();
                                     } ),
                     end(*players_pool) );
Marcelo Cantos
  • 181,030
  • 38
  • 327
  • 365
0

Just change your binary_function to a unary_function.
You also need to add the end iterator to the erase call, in order to erase all removed values.

Photon
  • 3,182
  • 1
  • 15
  • 16