c++ - std::remove_if using other class method -
i want use std::remove_if
predicate member function of differenct calss.
that is
class b; class { bool invalidb( const b& b ) const; // use members of class verify b invalid void somemethod() ; };
now, implementing a::somemethod
, have
void a::somemethod() { std::vector< b > vectorb; // filling elements // want remove_if vectorb based on predicate a::invalidb std::remove_if( vectorb.begin(), vectorb.end(), invalidb ) }
is there way this?
i have looked solution of idiomatic c++ remove_if, deals different case unary predicate of remove_if
member of b
and not a
.
moreover,
not have access boost or c++11
thanks!
once you're in remove_if
, you've lost this
pointer of a
. you'll have declare functional object holds it, like:
class isinvalidb { const* myowner; public: isinvalidb( const& owner ) : myowner( owner ) {} bool operator()( b const& obj ) { return myowner->invalidb( obj ); } }
just pass instance of remove_if
.
Comments
Post a Comment