Can I replace boost::bind with bind1st/2nd?

565 Views Asked by At

Just for better understanding, can I replace the call to boost::bind in the following example with std::bind1st/2nd? Or is it not possible because of returning a reference?

Example(shortened):

class Pos
{
public:
bool operator==( const Pos& );
...
}

class X
{
public:
const Pos& getPos()  { return m_p; }
...
private:
Pos m_p;
}

...
Pos position;
std::vector<X> v;
std::vector<X>::iterator iter;
...

iter = std::find_if( v.begin(), v.end(), boost::bind( &X::getPos, _1 ) == position );
...
1

There are 1 best solutions below

1
Cat Plus Plus On

It's not possible, because neither bind1st nor bind2nd overloads operator== like bind does (to yield another functor). If you don't want to use bind, you need to write the functor yourself, or use a lambda.