Vladimir Grigoriev
2009-12-07 13:40:25 UTC
Let assume there is a class
struct Point
{
explicit Point( int i = 0, int j = 0 ) : x( i ), y( j ) {}
bool equal_to( Point rhs ) const
{
return ( ( x == rhs.x ) && ( y == rhs.y ) );
}
int x, y;
};
std::vector<Point> v;
for ( int i = 0; i < 10; ++i )
{
v.push_back( Point( i, i ) );
}
Then it may be write down
std::vector<Point>::iterator it;
it = std::find_if( v.begin(), v.end(), std::bind2nd(
std::const_mem_fun1_ref_t<bool, Point, Point>( &Point::equal_to ), Point( 5,
5 ) ) );
The code above works.
However if the member function equal_to will be changed as
bool equal_to( const Point &rhs ) const;
then how can it be called the find_if() for this member function?
Vladimir Grigoriev
struct Point
{
explicit Point( int i = 0, int j = 0 ) : x( i ), y( j ) {}
bool equal_to( Point rhs ) const
{
return ( ( x == rhs.x ) && ( y == rhs.y ) );
}
int x, y;
};
std::vector<Point> v;
for ( int i = 0; i < 10; ++i )
{
v.push_back( Point( i, i ) );
}
Then it may be write down
std::vector<Point>::iterator it;
it = std::find_if( v.begin(), v.end(), std::bind2nd(
std::const_mem_fun1_ref_t<bool, Point, Point>( &Point::equal_to ), Point( 5,
5 ) ) );
The code above works.
However if the member function equal_to will be changed as
bool equal_to( const Point &rhs ) const;
then how can it be called the find_if() for this member function?
Vladimir Grigoriev